StopWarden

Guides Updated

StopWarden is not open yet. This guide is general information about NinjaTrader 8 and does not depend on StopWarden. Get one email when it opens.

Why a NinjaTrader strategy position ends up without a stop loss

Short answer: a NinjaTrader 8 strategy position has a stop only while a stop order for it is actually working. That order can be rejected, cancelled, placed late, held on your PC instead of at the broker, or never sent. When any of those happens, the position is open with nothing behind it until your code, NinjaTrader's error handling or you close it.

This guide lists the common causes, how to check an account right now, and the settings that change the odds. It applies to NinjaScript strategies running from the Control Center's Strategies tab or a chart.

How the stop normally gets there

A NinjaScript strategy places its stop in one of two ways:

  • Set methods such as SetStopLoss(). NinjaTrader submits these "in real-time on incoming executions from entry orders", and its help guide says to call the method before submitting the entry so an initial level is set. [1]
  • Exit order methods such as ExitLongStopMarket(), which your own code submits at a moment you choose.

Either way, the stop only protects the position once the order is accepted and working. Everything below is a way that step fails.

Seven ways a position is left without a working stop

  1. The stop is rejected. A stop priced on the wrong side of the market (common in a fast move) comes back Rejected. With the default error handling, StopCancelClose, the strategy stops, cancels its orders and closes its position. With StopCancelCloseIgnoreRejects NinjaTrader applies that default "on all errors except order rejections", and with IgnoreAllErrors it keeps running; the help guide warns this can have "serious adverse affects" unless you wrote your own rejection handling. [2] In both of those modes a rejected stop can leave the position open with no stop.
  2. The stop waits for a bar to close. If your code submits the stop in OnBarUpdate() after it sees the new position, and the strategy's Calculate setting is On bar close, the stop is not sent until the next bar closes. On a 5-minute chart that can be minutes of open risk.
  3. The strategy was disabled with a position open. Disabling a strategy does not close the account's position. If Cancel exit orders when a strategy is disabled is checked (Control Center > Tools > Settings > Strategies) when the strategy row was added, the strategy's stop is cancelled at the same moment. [3] NinjaTrader copies the value into the row when the row is added, so the row keeps the value it was added with. See the cancel-on-disable guide.
  4. The strategy restarted while the account was in a position. With the default Start behavior, Wait until flat, NinjaTrader's help guide says the strategy "assumes your Account Position is in a flat state" and "will check for any active orders previously generated by the strategy on your account and cancel those first". [4] It then trades virtually until its own position reaches flat. The real position stays open; the old stop is cancelled.
  5. The stop is simulated on your PC. SetStopLoss() has an isSimulatedStop option that simulates the stop and submits a market order once triggered. [1] Simulated stop orders are "held and simulated locally on your PC and are therefore subject to issues such as loss of internet connection and computer crashes." [5]
  6. The connection dropped or NinjaTrader crashed before the stop was accepted, or while a stop was being moved. An order change needs a live connection to reach the broker. See what happens when the internet disconnects.
  7. Someone cancelled it. "Cancel All Orders" in the Orders tab cancels every working order, protective stops included. [6]

How to check an account right now

  1. Open the Control Center Positions tab and note each open position: account, instrument, side and quantity.
  2. Open the Orders tab. For each position, look for a stop order on the opposite side for the full quantity.
  3. Read its State. NinjaTrader's help guide says orders in the "Accepted" or "Working" state reside at the brokerage, exchange or provider, while "TriggerPending" or "Initialized" orders are typically held locally on your PC. [7] A TriggerPending stop depends on your PC, your connection and your data feed staying up.
  4. Check the Control Center Log tab for "Rejected" and for lines about the strategy being disabled.

If a position has no working stop, you decide what to do: place a stop by hand, or close it with Close Position (right-click in the Positions tab), which "flattens the currently selected position in the grid and cancels any working orders associated to the position's instrument". [8]

Settings that change the odds

SettingWhereWhat to consider
Error handlingStrategy code: RealtimeErrorHandlingKeep the default StopCancelClose unless your code handles rejected stops itself. [2]
Set methods before entryStrategy codeCall SetStopLoss() before the entry is submitted, as the help guide advises. [1]
When the stop is sentStrategy code: Calculate, or OnExecutionUpdate()Sending the stop from the fill, not from the next bar, closes the gap in cause 2.
Simulated stopsStrategy code / ATM templateFor unattended trading, a stop working at the broker does not depend on your PC. [5][7]
Start behaviorStrategy propertiesChoose it deliberately; know that Wait until flat cancels prior strategy orders. [4]
Cancel exit orders on disableTools > Settings > StrategiesClose the position yourself when you disable with a position open. [3]

None of these removes the risk. A stop can still fill far from its price in a fast market, and a platform or connection fault can still happen at the wrong moment.

Sources

  1. NinjaTrader 8 help guide, SetStopLoss()
  2. NinjaTrader 8 help guide, RealtimeErrorHandling
  3. NinjaTrader 8 help guide, Settings > Strategies
  4. NinjaTrader 8 help guide, Syncing Account Positions (Start behavior)
  5. NinjaTrader 8 help guide, Simulated Stop Orders
  6. NinjaTrader 8 help guide, Control Center > Orders Tab
  7. NinjaTrader 8 help guide, Where do your orders reside?
  8. NinjaTrader 8 help guide, Control Center > Positions Tab

General information about NinjaTrader 8 settings, checked against NinjaTrader’s help guide on the date above. Not financial advice. NinjaTrader changes between versions; confirm each setting on your own install.