EMA´s cross Bot
EMA´s cross Bot
28 Oct 2020, 02:11
A coding modification is required, i hope someone could assist in doing tow things:
- changing the simple SL to trailing SL.
- adding trading hours parameter ( trading can be like between two fixed hours )
I am using a cross of two EMA ( fast and medium) with a condition of being above or below the major EMA ( like 200 or so - here it is named as slow) this bot gave me great result while back testing it, looking into it.
an example of a good back test results is:
GBPUSD:
- timeframe: 15 minutes
- Slow period: 190
- Medium:50
- fast:14
- SL:70
- TP: 105
Note: This is a modified version by me on the bot done by https://ctrader.com/forum/cbot-support/10910 all credit goes to the original bot.
following is the code
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class EMACross_RSI : Robot
{
[Parameter("Source")]
public DataSeries SourceSeries { get; set; }
[Parameter("Label", DefaultValue = "EMA")]
public string label { get; set; }
[Parameter("Slow Periods", DefaultValue = 30)]
public int SlowPeriods { get; set; }
[Parameter("Medium Periods", DefaultValue = 12)]
public int MediumPeriods { get; set; }
[Parameter("Fast Periods", DefaultValue = 5)]
public int FastPeriods { get; set; }
[Parameter("Stop Loss", DefaultValue = 10)]
public int SL { get; set; }
[Parameter("Take Profit", DefaultValue = 10)]
public double TP { get; set; }
[Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
public double Quantity { get; set; }
private ExponentialMovingAverage slowMa;
private ExponentialMovingAverage mediumMa;
private ExponentialMovingAverage fastMa;
protected override void OnStart()
{
fastMa = Indicators.ExponentialMovingAverage(SourceSeries, FastPeriods);
mediumMa = Indicators.ExponentialMovingAverage(SourceSeries, MediumPeriods);
slowMa = Indicators.ExponentialMovingAverage(SourceSeries, SlowPeriods);
}
protected override void OnBar()
{
int index = MarketSeries.OpenTime.Count - 2;
var longPosition = Positions.Find(label, SymbolName, TradeType.Buy);
var shortPosition = Positions.Find(label, SymbolName, TradeType.Sell);
if ((fastMa.Result[index] > slowMa.Result[index]) && (mediumMa.Result[index] > slowMa.Result[index]) && (fastMa.Result[index - 1] < mediumMa.Result[index - 1]) && longPosition == null)
{
if (longPosition != null)
ClosePosition(longPosition);
ExecuteMarketOrder(TradeType.Sell, Symbol, VolumeInUnits, label, SL, TP);
}
else if ((fastMa.Result[index] < slowMa.Result[index]) && (mediumMa.Result[index] < slowMa.Result[index]) && (fastMa.Result[index - 1] > mediumMa.Result[index - 1]) && shortPosition == null)
{
if (shortPosition != null)
ClosePosition(shortPosition);
ExecuteMarketOrder(TradeType.Buy, Symbol, VolumeInUnits, label, SL, TP);
}
}
private long VolumeInUnits
{
get { return Symbol.QuantityToVolume(Quantity); }
}
}
}
... Deleted by UFO ...