TradingView strategy research

NR7 and NR4 trading strategies: narrow ranges and breakout rules

An NR7 trading strategy starts with a completed candle whose high-low range is the smallest of seven candles, including itself. NR4 uses four candles. The setup describes contraction, not direction. A breakout version then waits for a later move beyond the setup high or low. Equal ranges, order expiry and exits need explicit rules before the pattern becomes a testable strategy.

See the decision guide

What narrow range measures

StockCharts describes NR4 and NR7 as narrow-range patterns associated with Toby Crabel. Its high-low breakout adaptation is distinct from an opening-range entry. Here, R[t] = high[t] - low[t]. Compare the current completed range with the preceding N - 1 ranges. Use standard candles on one fixed symbol, timeframe and session; a seven-bar intraday window is not seven daily sessions.

  • Inclusive minimum: R[t] is less than or equal to every earlier range in the window. Strict minimum: R[t] is less than every earlier range. This page defaults to inclusive ties; the strict alternative is a separate setting.
  • Use the full high-low distance, not candle body size. True Range also considers the previous close, so a gapped candle can have a small high-low range and a large True Range.
  • Inside Bar checks price containment within the preceding candle. NR7 checks range size across seven candles. Neither definition substitutes for the other.

Check definitions with concrete range samples

All observations below are hypothetical. Ranges run from oldest to newest, in whole ticks. The final number is the candidate range. Zero-range candles are excluded from this page's research version even when they are mathematically the minimum.

  • For a containment counterexample, let the previous candle span 99 to 101 and today span 101.50 to 102.50. Today has range 1 versus yesterday's 2 but sits entirely above yesterday. If all six earlier ranges exceed 1, today is strict NR7 without being an Inside Bar.
  • In that example, a previous close of 100 produces True Range 2.50 today, despite high-low range 1. Replacing range with ATR(1) changes the test.
  • Compare ranges in integer ticks when prices lie on the instrument's tick grid. This avoids tiny floating-point differences classifying two equal tick ranges as unequal.
SampleInclusive NR4 / NR7Strict NR4 / NR7
12, 10, 9, 8, 7, 6, 5Yes / YesYes / Yes
12, 10, 9, 8, 7, 5, 5Yes / YesNo / No
3, 10, 9, 8, 7, 6, 5Yes / NoYes / No
12, 10, 9, 8, 7, 6, 0Excluded / ExcludedExcluded / Excluded
8, 7, 6, 5 (only four bars available)Yes / Not yet eligibleYes / Not yet eligible

A complete next-bar breakout research version

These execution rules are explicit research choices, not a claim to reproduce every Crabel rule. Start with standard daily bars, inclusive NR7, one unit, adequate capital, no pyramiding and one active setup or position. Record the exchange session and adjustment settings. Require seven completed bars and a positive setup range.

  • The initial planned distance is B - S. Targets use the frozen trigger prices, not a later favorable fill. If an entry gaps, actual reward and risk differ from the planned 2:1 ratio.
  • The opposite boundary is an invalidation level after entry. A mere close back inside the range does not exit this particular version; adding that exit would create a different test.
  • If both entry levels or both exit levels are touched on one historical candle, daily OHLC cannot establish which came first. Retain the case, record the simulator's sequence, and inspect available lower-timeframe prices. Do not delete it after observing a loss.
StageFrozen rule
Setup at bar t closeIf flat and idle, freeze H = setup high and L = setup low. Submit a buy stop at B = H + one tick and a sell stop at S = L - one tick.
ActivationOrders are eligible only on bar t + 1. An exact touch of B or S qualifies. The setup bar itself cannot trigger an entry.
One entryPut the two entry orders in one-cancels-another cancellation group. The first fill cancels the opposite entry; never reverse after a stop-out on that setup.
Protection and targetFor a long, stop at S and target B + 2 × (B - S). For a short, stop at B and target S - 2 × (B - S). Submit direction-specific protective brackets with the pending entries and cancel unused brackets.
Expiry without entryCancel both unfilled entries at the close of t + 1. Record one expired setup and zero trades. A move on t + 2 cannot revive it.
Time exit after entryIf still in a position at the close of t + 1, submit a market close for the next available fill, normally the t + 2 open. Keep protection until flat, then cancel residual orders.
New opportunitiesIgnore setup signals while an entry is pending or a position is open. Do not rearm on the bar an episode ends. Wait for a later eligible completed candle.

Worked trade, no-breakout and gap cases

Assume an eligible setup with H = 100, L = 99, tick size 0.01 and point value 1 per unit. Then B = 100.01, S = 98.99 and planned distance = 1.02. These independent scenarios illustrate rules; they are not measured returns.

  • The 0.04 cost is a single combined illustration for commission, spread and slippage across entry and exit. Replace it with instrument-specific assumptions and avoid counting spread twice.
  • A gap through a protective stop can lose more than 1.02. Stops specify an order condition, not a guaranteed loss ceiling.
  • For a 0.10-wide setup with the same 0.01 buffer, planned distance is 0.12. A 0.04 round-trip cost equals one-third of that distance. Narrower setups can make trading costs large relative to the intended risk.
ScenarioCalculation or next-bar pricesRecorded outcome
Long targetExact entry 100.01; target = 100.01 + 2 × 1.02 = 102.05.Gross gain 2.04 per unit. With assumed round-trip costs 0.04, net gain 2.00.
Long failureExact entry 100.01; protective stop fill 98.99.Gross loss 1.02. With the same costs, net loss 1.06; the opposite entry stays canceled.
No breakoutNext bar open 99.50, high 100.00, low 99.00, close 99.70.Neither buffered trigger is touched. Expire with zero trades, even if a later bar reaches 102.05.
Gap entryNext bar opens 100.50, beyond B. Assume the stop entry fills at that open.Distance to S becomes 1.51; distance to the frozen target becomes 1.55. It is no longer a 2:1 trade.
Both sides reachedNext bar open 99.50, high 100.20, low 98.80, close 99.60.Both triggers lie within the bar. The fill sequence needs a documented intrabar assumption or finer data.

Pine Script detector for the definition audit

This Pine Script v6 indicator marks confirmed NR7 candles and NR4-only candles. It defaults to inclusive ties, compares rounded tick ranges and excludes zero ranges. The two plotted NR7 levels appear only on the following bar. It places no orders and produces no strategy performance report; implement the execution specification separately.

  • The current candle can expand before it closes. Confirmed markers avoid declaring a final narrow range from an unfinished candle.
  • The marker audit is independent of position state. It can show a new narrow candle while the research strategy would ignore it because an episode is active.
Definition and next-bar level audit only. NR4 requires four bars; NR7 requires seven. Run on standard candles with valid OHLC data.pine
//@version=6
indicator("NR4 and NR7 confirmed ranges", overlay = true)
bool allowTies = input.bool(true, "Allow equal smallest ranges")
float rangeTicks = math.round((high - low) / syminfo.mintick)
float prior3Min = ta.lowest(rangeTicks[1], 3)
float prior6Min = ta.lowest(rangeTicks[1], 6)
bool enough4 = bar_index >= 3
bool enough7 = bar_index >= 6
bool nr4 = barstate.isconfirmed and enough4 and rangeTicks > 0 and (allowTies ? rangeTicks <= prior3Min : rangeTicks < prior3Min)
bool nr7 = barstate.isconfirmed and enough7 and rangeTicks > 0 and (allowTies ? rangeTicks <= prior6Min : rangeTicks < prior6Min)
plotshape(nr7, title = "NR7", style = shape.labeldown, location = location.abovebar, color = color.blue, text = "NR7", textcolor = color.white)
plotshape(nr4 and not nr7, title = "NR4 only", style = shape.labeldown, location = location.abovebar, color = color.orange, text = "NR4", textcolor = color.black)
plot(nr7[1] ? high[1] + syminfo.mintick : na, title = "Next-bar NR7 buy trigger", color = color.green, style = plot.style_circles)
plot(nr7[1] ? low[1] - syminfo.mintick : na, title = "Next-bar NR7 sell trigger", color = color.red, style = plot.style_circles)

Compare NR4 and NR7 without losing the denominator

First check signal timestamps against the range and execution examples. Keep separate counts for raw pattern bars, accepted setups, ignored overlapping signals, expired setups and filled trades. A trade CSV contains fills, so it cannot by itself recover the number of setups that never broke out.

  • A predeclared comparison can use N = 4 or 7 and inclusive or strict ties: four variants. Keep entry buffer, exits, session, dates, capital and cost assumptions unchanged. NR7 qualifies as NR4 under the same definition, so these samples overlap.
  • Choose settings on an earlier development period. Freeze the version before running later untouched dates and report that evaluation separately. Repeatedly choosing settings on those dates consumes the holdout.
  • Report net result, average net trade, trade count and drawdown beside expiry rate. Repeat the cost model at a predeclared higher cost. A high breakout rate alone says nothing about net profitability.
  • Record ambiguous intrabar fills, gaps and time-exit fills. TradingView uses a broker emulator; standard historical bars and lower-timeframe detail still describe simulated execution.

Implement the frozen rules with Pineify

Give Pine Script AI Coding Agent the detector, execution table and independent failure cases. Ask for a strategy draft with explicit order cancellation and an event log that includes expired setups. Review the generated source and check the event log before comparing performance.

  • Strategy Optimizer can compare exposed strategy inputs through its TradingView extension. Start with the four declared variants after the baseline passes the fixtures. Reserve and run the later evaluation period separately.
  • Backtest Deep Report accepts supported TradingView trade CSV data and calculates metrics including net profit, profit factor and closed-trade equity drawdown. Use it to inspect exported trades; retain a separate setup log for non-trades. These tools do not establish live execution quality or future profitability.
Where Pineify fits

Pine Script AI Coding Agent

Turn the written NR4/NR7 rules into a reviewable strategy draft, then check signals, cancellations and expiry against the examples.

Also useful: Strategy Optimizer. Compare the exposed window and tie-rule settings after validating the baseline. Keep the later evaluation sample separate.

Draft the narrow-range strategy

Frequently asked questions

Educational research, not investment advice. The rules and price examples are illustrative and have not been performance-tested. Syntax validation does not establish strategy correctness. Trading can lose money; 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.