TradingView strategy research

Three-bar reversal rules: sequence and confirmation

A three bar reversal uses three consecutive candles: an initial directional bar, a second bar extending the move, and a third reversing it. Definitions differ. This page tests an explicit stronger variant: a bullish third bar must close above both earlier highs, or a bearish third bar below both earlier lows. The signal is known only at that close; the example strategy submits a market order for the next available tick, normally the next bar open.

See the decision guide

Choose a definition before comparing signals

LuxAlgo distinguishes a normal pattern from an enhanced pattern that requires the third bar to clear the first bar extreme. The independent research version here uses that stronger confirmation idea and fixes the remaining choices below. It is not a reproduction of the LuxAlgo indicator. Body size, middle-bar geometry, tolerance and exits are part of this specification; another script with the same name may disagree.

  • No moving-average or prior-swing trend filter is applied. Bar 1 and bar 2 supply local direction only. A signal can therefore occur inside a range or against a much larger trend.
  • The middle candle may be bullish, bearish or a doji. Its high and low determine eligibility. Bar 3 may make a fresh low in the bullish case or a fresh high in the bearish case; its final close supplies confirmation.

Exact bullish and bearish OHLC rules

Let O, H, L and C mean open, high, low and close, with subscripts 1, 2 and 3 for the sequence. Let q be the minimum tick and d = buffer ticks × q. The default buffer is one tick. Require three available, positive-range candles. Compare prices on the tick grid; the code rounds OHLC to integer ticks before comparing them.

  • The buffer is a minimum separation, not permission to accept a near miss. With q = 0.01 and one buffer tick, a close at H1 fails; a close at H1 + 0.01 passes. Equal middle-bar lows or highs fail the relevant extension test.
  • Using two buffer ticks requires two ticks of separation in every body, extension and confirmation comparison. The protective stop still uses one tick outside the whole pattern.
  • A zero-range candle fails. A middle-bar doji can pass if its range is positive and its extremes qualify. A doji on bar 1 or 3 cannot pass the directional-body rule.
StageBullish reversalBearish reversal
Bar 1 bodyC1 <= O1 - dC1 >= O1 + d
Bar 2 extensionH2 <= H1 - d and L2 <= L1 - dH2 >= H1 + d and L2 >= L1 + d
Bar 3 bodyC3 >= O3 + dC3 <= O3 - d
Bar 3 closing confirmationC3 >= max(H1, H2) + dC3 <= min(L1, L2) - d
Protective stop after entrymin(L1, L2, L3) - qmax(H1, H2, H3) + q

A three-candle example with a losing next-bar trade

These are hypothetical USD share prices with q = $0.01 and one buffer tick. They illustrate arithmetic and order timing, not measured performance. The long confirmation threshold is max(100.40, 100.10) + 0.01 = $100.41; bar 3 closes at $100.50, so the pattern qualifies.

  • At bar 3 close, submit the buy and its linked stop at min(99.30, 99.00, 99.10) - 0.01 = $98.99. There is no fill at the $100.50 signal close in this model.
  • Assume one share, $0.01 commission per side and one adverse tick of slippage per market/stop fill. The bar 4 open produces a $100.56 entry. A subsequent $98.99 stop trigger fills at $98.98 in the model. Gross loss is $1.58; adding $0.02 commission gives a $1.60 net loss.
  • The signal-close distance to the stop was $1.51. Actual entry-to-stop-level distance is $1.57, before stop slippage and fees. Using the signal close as the entry would understate this loss.
CandleOpenHighLowClose
1100.00100.4099.3099.50
299.60100.1099.0099.20
399.20100.6099.10100.50
4, independent failure branch100.55100.7098.8099.10

Rejected patterns and failures belong in different counts

Use each row as a separate change to the three-candle example. A rejected candidate creates no trade. A confirmed candidate that later loses remains a valid signal and a losing trade. Removing that loss would change the sample after seeing the outcome.

CaseObservationExpected result
Wick without confirmationKeep H3 = 100.60 but set C3 = 100.39.Reject. Crossing the level intrabar does not satisfy the closing rule.
Exact touchSet C3 = 100.40.Reject. One buffer tick requires 100.41 or higher.
Boundary passSet C3 = 100.41.Accept with a one-tick buffer; reject with two ticks.
Middle low tiesSet L2 = 99.30, equal to L1.Reject. The second bar did not extend the low by one tick.
Outside middle barSet H2 = 100.45 while keeping L2 = 99.00.Reject this version: a lower low alone is insufficient.
Confirmed but stoppedUse the original first three bars and the bar 4 failure branch.Accept the signal and record the $1.60 illustrative loss.
Gap below protectionAfter a long entry, a later bar opens at 98.50 below the 98.99 stop.The stop price is not a guaranteed fill. Model the gap and slippage; retain the larger loss.

Pine Script v6 strategy with next-bar orders

Paste this complete strategy into Pine Editor and add it to a standard candlestick chart. It trades one unit while flat, ignores signals while a position is open and never reverses directly. It places the fixed stop with the entry order. If the stop has not closed the trade, a time exit is submitted after five held bars by default, counting the entry bar as the first. There is no profit target.

  • For entry on bar 4 and holdBars = 5, the time-exit decision occurs at bar 8 close and normally fills at bar 9 open. The stop remains active until the position closes. Signals on a bar where a trade closes are skipped.
  • Keep the calculation settings shown above. Enabling fills on the closing tick or recalculation after fills changes the experiment. The next available bar can follow a session break; it need not be the next clock interval.
  • A gap through the stop immediately after the signal does not cancel this market-entry version. Inspect the resulting entry and protective fill. A rule that skips adverse opening gaps needs a different execution design; do not silently delete those trades.
  • The USD account, one-unit size, one-cent fee and one-tick slippage are illustrative inputs, not a broker quote. Use sufficient capital and instrument-appropriate quantity, point value and costs. This script does not model short borrow charges.
  • Use actual candle OHLC rather than synthetic chart prices. Historical bars do not reveal every trade inside them; inspect lower-timeframe data when execution order matters. No performance backtest is claimed here.
Original educational strategy for the rules on this page. Pattern labels show every qualifying sequence, including signals ignored while a trade is open. They are not entry-fill markers.pine
//@version=6
strategy("Three-bar reversal: confirmed close, next open", overlay = true,
     initial_capital = 100000, currency = currency.USD, pyramiding = 0,
     default_qty_type = strategy.fixed, default_qty_value = 1,
     commission_type = strategy.commission.cash_per_contract, commission_value = 0.01,
     slippage = 1, process_orders_on_close = false,
     calc_on_every_tick = false, calc_on_order_fills = false)

int bufferTicks = input.int(1, "Minimum separation in ticks", minval = 1)
int holdBars = input.int(5, "Bars held before time exit", minval = 1)
float q = syminfo.mintick
float o = math.round(open / q)
float h = math.round(high / q)
float l = math.round(low / q)
float c = math.round(close / q)
bool ready = barstate.isconfirmed and bar_index >= 2 and
     h > l and h[1] > l[1] and h[2] > l[2]
bool bull = ready and c[2] <= o[2] - bufferTicks and
     h[1] <= h[2] - bufferTicks and l[1] <= l[2] - bufferTicks and
     c >= o + bufferTicks and c >= math.max(h[2], h[1]) + bufferTicks
bool bear = ready and c[2] >= o[2] + bufferTicks and
     h[1] >= h[2] + bufferTicks and l[1] >= l[2] + bufferTicks and
     c <= o - bufferTicks and c <= math.min(l[2], l[1]) - bufferTicks
bool closedThisBar = strategy.closedtrades > nz(strategy.closedtrades[1])
var float stopPrice = na

if strategy.position_size == 0
    stopPrice := na
    if not closedThisBar
        if bull
            stopPrice := (math.min(l, math.min(l[1], l[2])) - 1) * q
            strategy.entry("Long", strategy.long)
            strategy.exit("Long stop", "Long", stop = stopPrice)
        else if bear
            stopPrice := (math.max(h, math.max(h[1], h[2])) + 1) * q
            strategy.entry("Short", strategy.short)
            strategy.exit("Short stop", "Short", stop = stopPrice)
else
    int held = bar_index - strategy.opentrades.entry_bar_index(0) + 1
    if held >= holdBars
        strategy.close_all(comment = "Time exit")

plotshape(bull, title = "Confirmed bullish pattern", text = "3BR+",
     style = shape.labelup, location = location.belowbar, color = color.green,
     textcolor = color.white, size = size.tiny)
plotshape(bear, title = "Confirmed bearish pattern", text = "3BR-",
     style = shape.labeldown, location = location.abovebar, color = color.red,
     textcolor = color.white, size = size.tiny)
plot(stopPrice, "Fixed stop", color = color.orange, style = plot.style_linebr)

Three bars, four candles and three swing points

The names count different objects. Three-bar reversal here needs exactly three adjacent candles. Three Line Strike uses four candles. A 1-2-3 reversal uses numbered swing points and can span many bars, with confirmation delays determined by its pivot rules.

PatternObject being countedDistinct confirmation question
Three-bar reversalThree adjacent OHLC candlesDid candle 3 close beyond the earlier extremes?
Three Line StrikeThree directional candles plus a fourth opposing strikeWhat did candle 4 engulf, and which later direction is tested?
1-2-3 reversalThree ordered swing pointsWhen was each point confirmed, and when did price break point 2?

Validate timing before changing parameters

First compare the OHLC table and failure cases with the strategy source. Then inspect real chart signals and the trade list: signal time, entry time, entry price, frozen stop, exit reason and costs. The middle candle and third-bar close must be known before an order is created. Save the symbol, interval, session, chart type and test dates with the results.

  • Pine Script AI Coding Agent can help revise this strategy and check its syntax. Supply the exact rule table and request the expected event sequence. Review the generated source and actual fills; a successful syntax check does not establish a profitable strategy.
  • Strategy Optimizer can compare exposed strategy inputs through its TradingView extension. One bounded experiment uses buffer ticks 1 or 2 and hold periods 3, 5 or 8: six combinations. These are sensitivity-test choices, not recommended trading settings.
  • Choose settings on an earlier development period and evaluate the frozen choice on later untouched dates. Run that date split separately. Report trade count, average net trade and drawdown, including losses and gap cases; do not select only the best-looking symbol.
Where Pineify fits

Pine Script AI Coding Agent

Revise the explicit three-bar rules in a reviewable Pine strategy, then inspect syntax and signal-to-fill timing.

Also useful: Strategy Optimizer. Compare declared tolerance and holding-period inputs after checking the baseline execution. Evaluate later dates separately.

Review the three-bar strategy rules

Frequently asked questions

Educational strategy research, not investment advice. Prices, costs and rules are illustrative; no measured performance is reported. Trading can lose money, and gaps can exceed planned stop distances. Syntax validation and historical results do not guarantee future returns.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.