A breakout can look excellent at the closing bell and become a poor trade at the next open. How much of a channel breakout survives that execution delay? This Thinkorswim strategy isolates that question rather than assuming the signal close is a tradable fill.

What you'll learn

  • Build a channel from completed reference bars.
  • Separate entry and exit signals from simulated fills.
  • Control repeated orders with a position-state variable.
  • Measure gap sensitivity and failure conditions.

Trading hypothesis

Use a long-only 20-bar breakout and a faster five-bar exit channel. The hypothesis is that a close above the prior range may precede continuation, while a close below the shorter channel may indicate deterioration. Neither threshold predicts returns by itself.

Next-Open Channel Breakout Strategy

Figure: schematic hypothetical breakout above 100, signal close 101, next open 102. The exit signal is distinct from its subsequent fill.

Rules and execution

At each completed bar, calculate the highest high of the previous 20 bars and the lowest low of the previous five bars. Exclude the current bar from both. When flat, enter if the close exceeds the upper channel; when holding, exit if the close falls below the lower channel. Equality does not trigger an order. Use one unit initially and no pyramiding. For example, an upper channel of 100 and close of 101 trigger a simulated entry at the next open of 102. If a later lower channel is 99 and the close is 98, an opening fill of 97 produces a loss of 5 per share before costs. The channel exit is not a protective stop.

thinkScript implementation

Create a Strategy, not a Study, in the chart editor. The recursive variable tracks intended position state at signal time, not actual broker fills. Load sufficient warm-up bars. AddOrder uses the next bar open as its simulated price; the negative index is used only for reporting that fill, never for deciding the signal.

input length = 20;
input exitLength = 5;
input quantity = 1;
def ceiling = Highest(high[1], length);
def floor = Lowest(low[1], exitLength);
def enter = close > ceiling;
def leave = close < floor;
def held = CompoundValue(1,
    if held[1] and leave then 0
    else if !held[1] and enter then 1
    else held[1], 0);
AddOrder(OrderType.BUY_TO_OPEN,
    held == 1 and held[1] == 0,
    open[-1], quantity, Color.GREEN, Color.GREEN, "Entry");
AddOrder(OrderType.SELL_TO_CLOSE,
    held == 0 and held[1] == 1,
    open[-1], quantity, Color.RED, Color.RED, "Exit");

Review the AddOrder reference. AddOrder generates hypothetical strategy orders, not unattended live execution. The example has not been compiled or backtested here.

Risk and testing

Compare the baseline with 15/20/30-bar entries and 3/5/8-bar exits using chronological training and untouched test periods. Keep session settings consistent. Record trade count, drawdown, net expectancy after commissions and assumed slippage, and entry gap distribution. Stress next-open fills by adding adverse slippage on both sides. Inspect the first valid signal, consecutive breakout bars, exit transitions and missing next bars. Reject the hypothesis if results depend on a few outliers or disappear under plausible costs. A fixed quantity does not cap dollar loss; overnight gaps can exceed intended risk. A live implementation needs independent order acknowledgement, protective risk controls and reconciliation.

For platform-specific adaptations, see Custom Thinkorswim strategy Development Services.

Educational example only; trading can result in substantial losses.

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.