Why a cooldown can help

A breakout strategy can repeatedly re-enter during a choppy market after being stopped out. A bar-based cooldown separates the exit from the next eligible entry without requiring a prediction of market direction. It may also miss profitable recoveries, so treat it as a testable hypothesis rather than a guaranteed improvement.

Define the timing precisely

Use a single primary series and Calculate.OnBarClose. When a transition from a non-flat position to flat is first observed at bar 3, block entries on bars 3, 4, 5 and 6. Bar 7 is the first eligible signal bar. A new breakout is still required: the close must exceed the highest high of the preceding 20 bars, excluding the current bar.

A Bar-Based Reentry Cooldown for Breakout Strategies

Hypothetical price path: exit observed at bar 3, three subsequent bars blocked, entry eligibility resumes at bar 7. Eligibility does not imply a fill.

NinjaScript entry gate

The following fragment belongs inside a Strategy class. Configure Calculate.OnBarClose in State.SetDefaults. It demonstrates the entry gate, not a complete trading system.

// Fields inside a NinjaScript Strategy
private int lastFlatBar = -1;
private bool wasInPosition = false;

protected override void OnBarUpdate()
{
    if (BarsInProgress != 0) return;
    bool inPosition = Position.MarketPosition != MarketPosition.Flat;
    if (wasInPosition && !inPosition)
        lastFlatBar = CurrentBar;
    wasInPosition = inPosition;
    if (CurrentBar < 20 || inPosition) return;
    if (lastFlatBar >= 0 && CurrentBar - lastFlatBar <= 3)
        return;
    if (Close[0] > MAX(High, 20)[1])
        EnterLong(1, "Breakout");
}

For a complete strategy, configure a protective stop and exit rules before enabling orders. For example, use SetStopLoss with a fixed tick distance chosen for the instrument and associate it with the Breakout entry signal. Add pending-entry tracking using OnOrderUpdate to prevent repeated submissions while an order remains working. The sample observes positions only at bar close, so a round trip within one bar may be missed. For execution-accurate cooldowns, track fills and flat transitions in OnExecutionUpdate and map the event to the primary bar; account for partial fills, historical versus realtime processing and restarts.

Testing checklist

Compare cooldowns of zero, three and six bars on the same data and costs. Measure trade count, net profit after commissions, drawdown and missed recovery trades. Use out-of-sample periods and playback to inspect order timing. A bar count represents different elapsed time on different chart types. The fragment has not been compiled or backtested here. Futures and leveraged products can cause substantial losses; stops may slip.

For execution-aware cooldowns or custom order handling, 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.