I have written a simple strategy with ema crossover and scaling out in 4 phases. Pasting the code below. When I backtest this, I see only first order gets executed for e.g. 'up1' and 'dn1' only. What am I doing wrong here? Thanks for your help!
/// <summary>
/// This method is used to configure the strategy and is called once before any strategy method is called.
/// </summary>
protected override void Initialize()
{
Add(EMA(Fema));
Add(EMA(Sema));
Add(EMA(Fema));
Add(EMA(Sema));
SetProfitTarget("up1", CalculationMode.Percent, Tgt1);
SetProfitTarget("up2", CalculationMode.Percent, Tgt2);
SetProfitTarget("up3", CalculationMode.Percent, Tgt3);
SetProfitTarget("up4", CalculationMode.Percent, Tgt4);
SetProfitTarget("dn1", CalculationMode.Percent, Tgt1);
SetProfitTarget("dn2", CalculationMode.Percent, Tgt2);
SetProfitTarget("dn3", CalculationMode.Percent, Tgt3);
SetProfitTarget("dn4", CalculationMode.Percent, Tgt4);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(EMA(Fema), EMA(Sema), 1))
{
EnterLong(Qty, "up1");
EnterLong(Qty, "up2");
EnterLong(Qty, "up3");
EnterLong(Qty, "up4");
ExitShort("dn1out", "dn1");
ExitShort("dn2out", "dn2");
ExitShort("dn3out", "dn3");
ExitShort("dn4out", "dn4");
}
// Condition set 2
if (CrossBelow(EMA(Fema), EMA(Sema), 1))
{
EnterShort(Qty, "dn1");
EnterShort(Qty, "dn2");
EnterShort(Qty, "dn3");
EnterShort(Qty, "dn4");
ExitLong("up1out", "up1");
ExitLong("up2out", "up2");
ExitLong("up3out", "up3");
ExitLong("up4out", "up4");
}
}
Comment