A breakout strategy can use volume confirmation to reject low-participation signals. Including the breakout bar in its own average, however, makes the benchmark move with the observation being tested. This design instead compares completed-bar volume with the preceding 20 bars.
Rules and worked example
Require a fresh close above the preceding 20-bar high and volume at least 1.5 times the preceding 20-bar average. If the average is 1,000, the threshold is 1,500. A breakout on 1,200 fails; 1,500 and 2,100 pass. All examples assume the price condition is satisfied.

thinkScript strategy example
Create a strategy under Strategies. The [1] offset excludes the current bar from the reference calculations. The held variable tracks simulated signal state to prevent repeated entries. A close below the 10-bar moving average triggers an exit. AddOrder models execution at the next bar open.
input length = 20;
input multiplier = 1.5;
def baseline = Average(volume[1], length);
def level = Highest(high[1], length);
def ready = BarNumber() > length + 1;
def signal = ready and baseline > 0
and close > level and close[1] <= level[1]
and volume >= multiplier * baseline;
def exitSignal = close < Average(close, 10);
def held = CompoundValue(1,
if held[1] and exitSignal then 0
else if !held[1] and signal then 1
else held[1], 0);
AddOrder(OrderType.BUY_TO_OPEN,
held and !held[1], open[-1], 1);
AddOrder(OrderType.SELL_TO_CLOSE,
!held and held[1], open[-1], 1);
Implementation limitations
The held variable represents signal state, not a brokerage position. AddOrder is strategy simulation, not unattended live order execution. The open[-1] reference is used only for modeled execution pricing, never for deciding the signal. Volume and close can change during a forming real-time bar, so evaluate completed bars. The example has no hard protective stop and is not a complete live risk-management system.
Testing and risk
Test volumes of 1,499, 1,500 and 1,501, zero volume and missing data. Compare trade counts, net returns and drawdown with and without the filter. Opening volume often exceeds midday volume; a time-of-day benchmark is a possible extension, provided it uses only past observations. Test multiple aggregations, out-of-sample periods and gap fills. Simulated fills do not guarantee actual execution. Trading involves risk of loss. This example has not been compiled or backtested here.
Official reference: AddOrder.
To adapt this free strategy idea to your own rules, contact us about Custom Thinkorswim strategy Development Services.