Multi-timeframe exit problem

My script’s running on the 5 min timeframe. I am trying to exit the trade when certain condition is met on 1min timeframe, but I am running into problem. Ninjatrader keep display Stop Loss being hit, even though the trade should exit before that. For example, this show stop loss was hit at 26705.75 even though it shouldve exit at around 26712.25.


I know I am using 1min timeframe, so i create this condition under: if BarsInProgress == 1

I want the trade to exit when supertrend flip from green to red on 1min timeframe

The condition are follow:
bool OneMinuteTurnRed =
!double.IsNaN(LongSupertrend1m.Values[1][0]) && double.IsNaN(LongSupertrend1m.Values[0][0])&&
!double.IsNaN(LongSupertrend1m.Values[0][1]) && double.IsNaN(LongSupertrend1m.Values[1][1]);
//LongSupertrend1min is using 1 min data. I used Bararray[1]

if (IsInLongTrade && !ExitedEarlyLong &&
&& OneMinuteTurnRed)
{
ExitLong(Quantity);

isInLongTrade = false;
ExitedEarlyLong = true;
exitPrice = Close[0];
}

Theoretically it should work, but for some reason it doesn’t, and I can’t figure out why stop loss condition is triggered.

You need tick data in your back-testing. Your entry logic should be on the one minute, but your actual entries should be on the tick dataseries.

1 Like