Exit on session close: Order Reject by RS but reason is unknown

I am running a Ninjascript strategy where it will auto-close all open positions, orders and disable the strategy at a certain time. However, it fails to execute the “Exit on session close” which prevents the closing of open positions. However, it successfully disabled the Ninjascript strategy and cancelled all existing orders. This then cause the open positions to be auto-liquidated.

This is the message from the logs:

“Name=‘Exit on session close’ New State=Rejected”

“Order Rejected by RS but reason is unknown affected Order: Sell 1 Market.”

1 Like

The Risk Server (RS) rejected the market order because your code disabled the NinjaScript strategy too early in the execution thread

When you force a strategy to turn off or change its state while an automated exit order like Exit on session close is triggered, NT8 tears down the internal strategy object wrapper and revokes the execution token, the platform cancels your working limit orders fine, but when the final market order hits the broker gateway (Tradovate/Rithmic), the risk engine sees an orphaned order with an inactive strategy GUID and drops it instantly. That’s why you get the “reason is unknown” log and suffer auto-liquidation by the broker house

Stop relying on the native IsExitOnSessionClose toggle if you are running custom time-based shutdown routines. You need to handle the exit manually inside OnBarUpdate. Fire a hard ExitLong() or ExitShort() at least 2 minutes before your final shutdown sequence, wait for the OnOrderUpdate event to confirm the state is OrderState.Filled, and only then trigger the strategy disable command, give the gateway time to clear the pipeline before you kill the script object