I have a problem to handle exit positions and I will really appreciate if you could assist me on this. At my strategy I have applied Trail Stop, Stop Loss and a condition in order to exit from the current position. However the strategy is not stop out if a condition is confirmed. I applied Print() statments and I understand that the If condition doesnt execute. Please have a look at the code below and let me know your thoughs or if you need the whole code. The strategy is compiled well but the stop loss orders are not working as expected
.................Initialize()
SetStopLoss("", CalculationMode.Percent, SL, true);
..............OnBarUpdate()
if ( EMA(5)[0]>EMA(40)[0]
&& Closes[1][0]>EMA(150)[0])
{
EnterLong(DefaultQuantity, "")
SetTrailStop("", CalculationMode.Ticks,30, true);
Print(Time[0] +" Enter Long");
}
else if (Position.MarketPosition== MarketPosition.Long && Close[0] < EMA (30)[0] )
{
ExitLong("EMA > Close");
Print(Time[0]+" Exit Long");
return;
}
Comment