A dynamic stop is also persistent strategy state
A common implementation mistake is to move a protective stop to an absolute price during one trade and then forget to restore the initial offset before entering the next trade. In NinjaTrader's managed approach, the previous SetStopLoss setting can affect the next entry. This design illustrates the lifecycle of a bar-close long-only strategy that moves its stop to gross breakeven once and resets the stop configuration before each new entry.
Two trades expose the problem
Assume tick size 0.25, initial risk eight ticks (two price points), and activation after twelve ticks (three points) of favorable closing-price movement. Trade A fills at 100, initially has stop 98, and moves the stop to 100 when close reaches at least 103. After exit, trade B fills at 95. Its intended initial stop is 93, not the previous absolute price of 100. A sell stop at 100 could be invalid while the market is below it. Gross breakeven does not include fees or slippage.

Hypothetical successive trades: the second entry must receive a fresh tick-based stop, not the absolute price retained from trade A.
NinjaScript managed-order example
// Add to a single-series Strategy class.
// In State.SetDefaults: Calculate = Calculate.OnBarClose;
// EntriesPerDirection = 1;
private bool moved;
private const string EntryName = "TrendLong";
protected override void OnBarUpdate()
{
if (CurrentBar < 30) return;
if (Position.MarketPosition == MarketPosition.Flat)
{
moved = false;
SetStopLoss(EntryName, CalculationMode.Ticks, 8, false);
if (CrossAbove(SMA(10), SMA(30), 1))
EnterLong(1, EntryName);
return;
}
if (Position.MarketPosition != MarketPosition.Long || moved)
return;
double entry = Position.AveragePrice;
if (Close[0] >= entry + 12 * TickSize)
{
double stop = Instrument.MasterInstrument
.RoundToTickSize(entry);
// In realtime require a valid current bid
// and a sell-stop price below it.
double bid = State == State.Realtime
? GetCurrentBid() : Close[0];
if (bid > stop)
{
SetStopLoss(EntryName, CalculationMode.Price,
stop, false);
moved = true;
}
}
}
Use the standard Strategy template and NinjaTrader.Cbi namespace. The signal is a 10-period SMA crossing above a 30-period SMA. The initial stop is configured before EnterLong; the later adjustment uses the actual average entry price, not the signal close. The SetStopLoss documentation specifically describes resetting dynamic stop settings while flat. The example has no profit target; the protective stop is its exit, subject to the platform's session-close behavior. The moved flag tracks a modification request, not acceptance by the broker.
Production safeguards
In a production implementation maintain a working-entry gate, avoid repeated submissions while an order is pending, and reconcile accepted stop prices in OnOrderUpdate. If a modification is rejected, follow an explicit policy for preserving or restoring protection rather than assuming moved is true. A current bid check cannot guarantee validity at the time of submission; broker minimum distances and fast price movement matter. Partial fills can alter average entry and protective quantities. Configure the stop handling policy and use execution notifications to reconcile actual fills where necessary. Restarting mid-position requires recovering the stop state rather than relying on a fresh boolean.
Validation and risk
Test successive entries at very different prices, gaps, partial fills, rejected modifications and session boundaries. Verify the initial stop for every entry and compare a static eight-tick stop against the breakeven variant under identical costs. Bar-close logic can miss favorable intrabar excursions; backtest and live order timing differ. The fragment has not been compiled or backtested here. Stops cannot guarantee a specified loss, and leveraged trading may cause substantial losses.
For custom execution and strategy rules, see Custom NinjaTrader strategy Development Services.