A breakout recognized at a completed bar's close is not necessarily tradable at that close. In thinkorswim, AddOrder creates hypothetical strategy orders, not unattended live brokerage execution. A useful test separates the signal from the modeled next-bar entry.

Worked example

Suppose a breakout is recognized at 100 and the next bar opens at 103. The modeled entry is 103, not 100. If a later hypothetical exit is 105, gross price profit is 2 rather than 5, before costs. This gap changes the economics without changing the signal.

Separating Signal Prices from Simulated Entry Prices in thinkScript Strategies
A signal at 100 and a modeled next-bar entry at 103.

Implementation

Use the highest high of preceding bars as resistance, excluding the current bar. The condition detects a transition from not above the previous resistance to above the current resistance. Because the resistance rolls, it is not a fixed horizontal level. AddOrder uses the next bar open as its modeled price; open[-1] is appropriate for this simulation price argument, not as a signal input.

input length = 20;
def resistance = Highest(high[1], length);
def breakout = close > resistance and close[1] <= resistance[1];
AddOrder(OrderType.BUY_TO_OPEN, breakout, open[-1], 1,
    Color.GREEN, Color.GREEN, "Breakout");

This is an entry-only example. Add independent exits and position controls before interpreting a complete strategy report. Repeated breakout events may generate additional hypothetical entries depending on strategy settings. Do not treat the example as a complete position controller.

Testing and limitations

Compare the signal close with the next open across identical events. Record the signed gap, median gap, adverse tail and net results after commissions and realistic slippage. Include overnight and session transitions separately. Check the final chart bar, where the next open is not yet available. Never use future price references in the signal itself. Historical strategy arrows are not evidence of executable live orders. Gaps, liquidity and costs can cause losses.

Official reference: platform documentation.

This example has not been compiled or backtested here. Trading involves risk of loss.

To adapt this strategy idea, contact us about Custom Thinkorswim 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.