I have a problem with barssinceexitexecution when trading live. If the last trade was negative and the last exit was a stop loss, I want the strategy to do nothing for the next X bars.
When doing this in the strategy analyzer, it works perfectly fine in the backtest and it skips the next X bars. However, when trading live the strategy seems to ignore that rule. So the strategy enters a long position immediately after a Stop loss exit because the entry CONDITION is true even though it shouldn't do anything for the next X bars. Can anyone help me here?
Here is the simplified code:
{
/// STOPLOSS
SetStopLoss(CalculationMode.Percent, Stop);
if (IsFlat)
{
//// LONG TRADES
if (CONDITION)
{
if (SystemPerformance.AllTrades.Count <= 0)
EnterLong(size, "Buy");
else if (SystemPerformance.AllTrades.Count > 0)
{
Trade LastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];
if (LastTrade.ProfitCurrency < 0 && BarsSinceExitExecution("Stop loss") <= BarsSinceStopLoss)
return;
else
EnterLong(size, "Buy");
}
}
}
//// EXIT TRADES
if (CONDITION)
ExitLong();
}
Thanks in advance!
Comment