A pullback strategy may submit a limit entry that is attractive only while its original signal is fresh. Leaving it working indefinitely can turn yesterday's setup into an unintended trade. A bar-based expiration rule makes signal validity explicit without confusing the order's lifetime with the lifetime of an open position.
Worked example: a three-bar entry window
Assume a single-series strategy running with Calculate.OnBarClose. At the close of bar 120, it submits a two-contract buy limit at 100.00. The order may work during bars 121, 122 and 123. If it is still working at the close of bar 123, the strategy requests cancellation. The age is measured from the submission bar, not from an entry execution. If one contract fills before the cancel request or while cancellation is pending, the remaining quantity may be cancelled, but the filled contract still requires protection.

Choose the correct managed order lifetime
Ordinary managed entry orders generally expire at a bar boundary unless resubmitted. The advanced EnterLongLimit overload allows an order to remain active without resubmitting each bar, until the strategy cancels it or its time-in-force expires. Use this overload deliberately and retain a valid Order reference. The following fragments demonstrate placement and expiry, not a complete strategy.
// Illustrative excerpts: primary series, OnBarClose.
// Fields are maintained by the strategy's order lifecycle.
private Order entryOrder;
private int submittedBar;
private bool cancelRequested;
// In the eligible entry branch of OnBarUpdate():
// Set the pending-entry lock BEFORE submitting.
submittedBar = CurrentBar;
cancelRequested = false;
EnterLongLimit(0, true, 2, limitPrice, "TimedEntry");
// In the ongoing order-management branch of OnBarUpdate():
if (entryOrder != null && !cancelRequested &&
CurrentBar - submittedBar >= 3 &&
(entryOrder.OrderState == OrderState.Working ||
entryOrder.OrderState == OrderState.PartFilled))
{
cancelRequested = true;
CancelOrder(entryOrder);
}
// In OnOrderUpdate(), capture the order reference
// by its unique entry signal, and track terminal states.
// In OnExecutionUpdate(), protect actual executions.
Separate signal, order and execution state
| Event | Required action |
|---|---|
| Entry requested | Lock further entries before submitting; capture matching order in OnOrderUpdate. |
| Age reaches three bars | Request cancellation once; continue monitoring order state. |
| Cancelled, zero filled | Release the pending-entry lock under the strategy's re-entry policy. |
| Partially or fully filled | Manage actual filled quantity in OnExecutionUpdate; never assume the entire original quantity filled. |
| Rejected or cancellation error | Log error and reconcile; retry only when state and policy permit. |
In OnOrderUpdate, match the signal name and maintain the current order reference, including terminal Filled, Cancelled and Rejected states. A production implementation must account for Submitted, Accepted and pending-cancel states, rather than assuming every order immediately reaches Working. If expiration occurs while acceptance is pending, retain the expiration decision and cancel once eligible. Reset the cancellation flag only after a confirmed state transition or an explicitly handled rejection. Do not release the entry lock simply because CancelOrder returned.
Live and historical validation
Historical fills are determined by the selected fill model and bar data. A limit price touched during a bar does not guarantee a real fill, and a bar-close cancellation cannot undo an earlier execution. Test an unfilled order, a fill before expiration, a partial fill followed by cancellation, and a late execution during cancellation. Also test the session boundary, disconnect and historical-to-realtime transition; map historical references to real-time orders as required using GetRealtimeOrder. For a wall-clock expiry, design a separate time-based event mechanism instead of assuming three bars always equal three minutes.
Official references: EnterLongLimit, Advanced Order Handling and CancelOrder sample.
This hypothetical teaching excerpt has not been compiled or backtested here. Trading involves risk of loss; simulated results do not guarantee future performance.
To adapt this free strategy idea to your own order-management rules, contact us about Custom NinjaTrader strategy Development Services.