I have included stop to breakeven script as per https://ninjatrader.com/support/helpGuides/nt8/modifying_the_price_of_stop_lo.htm. But I can't have it fire as desired. It never moves it to breakeven after meeting my criteria of 40 ticks above position average. What am I missing from code? Here's code and a snapshot of an example where it should have stopped me at breakeven but continued to my full stop.
1st half of code (non bold) is the long entry execution. Second part of the code in bold is supposed to the stop to break even component:
isFirstPullbackSeriesLong[0] = isFirstPullbackLong ? 1 : 0;
if (isFirstPullbackLong)
{
Draw.ArrowUp(this, "FirstPullbackLong" + CurrentBar, false, 0, Low[0] + 2 * TickSize, Brushes.Orange);
// Place order at the high of the pullback candle
StoplimitOrder = EnterLongStopLimit(NumberOfContracts, High[0], High[0], "Long Entry");
SetStopLoss("Long Entry", CalculationMode.Ticks, FixedStopLossTicksLong, false);
SetProfitTarget("Long Entry", CalculationMode.Ticks, FixedTargetProfitTicksLong);
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Ticks, FixedStopLossTicksLong);
}
// If a long position is open, allow for stop loss modification to breakeven
else if (Position.MarketPosition == MarketPosition.Long)
{
// Once the price is greater than entry price+50 ticks, set stop loss to breakeven
if (Close[0] > Position.AveragePrice + 40 * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AveragePrice);
}
}
}
Example:

Comment