Limit new entry attempts rather than trading all day

A breakout strategy may repeatedly enter after a stop-out in a choppy session. A session entry budget is one way to constrain repeated exposure. This NinjaTrader 8 example permits two long entry submissions per configured trading session, not two completed trades or two fills. This distinction matters when orders are rejected or partially filled.

Example and state transitions

Suppose the first and second breakout orders are submitted and each position is later closed. A third qualifying breakout must be ignored until the next session. A rejection still consumes a slot under this conservative definition. The session boundary follows the chart Trading Hours template, which may begin on the preceding calendar day for futures.

Session Entry Budgets for Breakout Strategies

Illustrative timeline: two entry submissions exhaust the budget; an exit does not replenish it.

NinjaScript entry logic

// Fields inside a Strategy class
private int submitted;
private int lastResetBar = -1;

// Configure Calculate.OnBarClose in State.SetDefaults.
// Example assumes one primary series, historical start
// at a session boundary, and no pyramiding.
protected override void OnBarUpdate()
{
    if (Bars.IsFirstBarOfSession &&
        lastResetBar != CurrentBar)
    {
        submitted = 0;
        lastResetBar = CurrentBar;
    }
    if (CurrentBar < 20) return;
    if (Position.MarketPosition == MarketPosition.Flat &&
        submitted < 2 &&
        Close[0] > MAX(High, 20)[1])
    {
        submitted++;
        EnterLong(1, "LimitedLong");
    }
}

Integrate this fragment into a Strategy with the standard NinjaTrader namespaces and Calculate.OnBarClose. MAX(High,20)[1] excludes the current bar. Configure a protective stop and exit policy before enabling orders; for example, SetStopLoss with CalculationMode.Ticks and a positive instrument-appropriate tick distance for the LimitedLong signal. The example deliberately counts attempts before EnterLong, not fills. Do not use this fragment as a complete live strategy.

Operational details

Production strategies need explicit pending-order tracking using OnOrderUpdate and execution reconciliation using OnExecutionUpdate. Do not allow a working entry to be duplicated on the following bar. Persist or reconstruct the budget if the strategy is restarted during a session; a local counter alone cannot enforce an account-wide daily limit. Session resets must not cancel protective orders or flatten positions inadvertently. Backtest identical entry and exit logic with limits of one, two and unlimited submissions. Compare exposure, trade frequency, drawdown and net results after costs; examine session boundaries and rejected orders in simulation. This fragment has not been compiled or tested here. Trading can cause substantial losses.

For persistent counters and order-state management, see Custom NinjaTrader strategy Development Services.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.