OPEN-SOURCE SCRIPT
Atualizado

Opening Range Breakout + Midline

181
What this is

An opening range breakout tool that draws the range high, the range low and the
50% midline, then adds the context you need to judge whether today's range is
worth trading at all - and hit rates measured on the chart you are actually
looking at.

Most ORB indicators draw three lines and stop. The reason this one exists is
that the three lines on their own are misleading: a break of the range high is
not, by itself, evidence of a trend day. This script is built around that
problem.

Why the midline is on by default

Clean breakouts are the minority outcome. Measured on ES over a six-month
sample, price took out *both* sides of the opening range on roughly two thirds
of sessions, against roughly one sixth cleanly breaking up and one sixth cleanly
breaking down.

If both sides go more often than either side holds, then "price broke above the
range high, so it is going up" is wrong most of the time, and you need something
other than the break itself to tell you which side actually owns the session.
The 50% level is that something: it is the level a failed break falls back to,
and the level a genuine trend refuses to give back.

So the midline is drawn by default. You can turn it off under
**Midline -> Show midline (50%)**, and it has its own colour, style and width if
you would rather it stayed on but receded into the background.

What it draws

- **Range high and low**, held from the end of the opening range to the session
close, optionally extended to the right.
- **The 50% midline.**
- **A shaded range box**, either spanning just the range window or the whole
session.
- **Extension targets** projected from the broken edge at 0.5x, 1.0x, 1.5x and
2.0x the range width. Only the side that has actually broken is projected,
because targets on an untested side are clutter. 1.0x and 2.0x are on by
default.
- **Previous sessions' ranges**, five by default and up to forty, so you can see
how the instrument has been behaving lately.

The context table

**Range width** in points, as a percentage of price, and as a percentage of
ADR(14) - tagged NARROW, NORMAL or WIDE.

This matters in both directions. A range that is unusually narrow tends to break
in whichever direction noise happens to push it first. A range that is already
very wide has spent much of the day's expected movement before you are even in,
so the extension targets below it become unrealistic.

The comparison is scaled by the square root of time, so the tag stays meaningful
at any range length: a 5-minute range is expected to be about 17% of ADR, a
15-minute range about 30%, 30-minute about 42%, 60-minute about 60%. The
baseline is adjustable if your instrument opens habitually quiet or habitually
violent.

**Opening relative volume** - the volume traded inside the range window against
the average of the same window over the previous 14 sessions, tagged LIGHT,
NORMAL, ELEVATED or HIGH. Opening relative volume was the strongest single
filter in the published research on this setup, so it is shown rather than
buried.

**Session state** - FORMING while the range builds, then INSIDE, BROKE UP,
BROKE DOWN or DOUBLE BREAK, with BACK INSIDE appended when price has returned
into the range after breaking out.

The measured statistics

The bottom block is measured on the symbol and timeframe you have open, over the
last N sessions (60 by default). It is not borrowed from anywhere. Each row
carries its own sample size, because the denominators genuinely differ:

- **broke range** - of all sessions, how often price left the range at all.
- **double break** - of all sessions, how often price took out *both* sides.
This is the number that tells you how much to distrust a first break on this
instrument.
- **1x before far side** - of sessions that broke, how often the 1.0x extension
target printed before price reached the opposite extreme of the range. This is
the entry-at-the-break, stop-at-the-other-side pairing, scored honestly:
when a single bar spans both levels the bar is counted as reaching the stop,
and a session that reaches neither by the close counts as not reaching target.
- **failed to midline** - of sessions where a break failed, how often price then
reached the midline. A failed break is defined by a *close* back inside the
range; a wick back in that closes outside does not count.

Rows at or above 65% are tinted, which is a rough and widely used dividing line
between a tendency worth building a plan around and a coin flip. Treat these as
descriptive history for the symbol and timeframe in front of you. They describe
what has happened; they do not predict what will happen, and a small sample size
in the n= column means exactly what it says.

How to use it

Set **Trading session** to the instrument's real hours and **Session timezone**
to match - `0930-1600` New York for US equities and index futures RTH,
`0300-1130` London for European hours. The range is then measured forward in
wall-clock minutes from that session's first bar, so any range length works and
the two windows cannot drift out of step.

A workable reading, in order:

1. Check the range-quality tag before anything else. NARROW warns that breaks
are more likely to be noise; WIDE warns that the extension targets may be
asking for more than the day has left to give.
2. Check opening relative volume. A range formed on LIGHT volume is a weaker
reference level than one formed on HIGH volume.
3. Check the double-break rate for this symbol. If it is high, treat a first
break as provisional rather than as confirmation.
4. Watch the midline once a break fails. That is what the failed-to-midline row
is measuring.

Use 5-minute or 15-minute charts. The table warns you if your chart timeframe is
larger than the range length, or if it does not divide the range evenly - a
15-minute range on a 2-minute chart actually measures 16 minutes, which is
inherent to any bar-based range rather than a fault of this script.

Alerts

Seven alert conditions: break above the range, break below the range, failed
break (a close back inside), midline reached after a failed break, midline
crossed, and the 1x target reached above or below.

The range high, midline, low, width and opening relative volume are also
published to the Data Window, so other scripts can read them.

## What is different about this one

There is no shortage of ORB indicators. This one adds three things that are
uncommon:

1. **Measured hit rates on your own chart**, with visible sample sizes and
explicit definitions, rather than a static claim in a description. The
double-break number in particular changes how you should read a first break,
and it varies a lot between instruments.
2. **A range-quality score** that is comparable across range lengths because it
is scaled by the square root of time, instead of a fixed points or percentage
threshold that only works on one instrument at one setting.
3. **Opening relative volume**, surfaced as a first-class number because it was
the strongest filter in the research, not because it is easy to compute.

The range is also measured in wall-clock minutes from the session open rather
than from a second hardcoded session string, which is what usually breaks other
ORB scripts on futures, on non-US instruments, and on any timeframe the author
did not test.

Credits and sources

No code from other authors is used; this is written from scratch. The defaults,
however, are taken from published work rather than convention, and that work
deserves credit:

- Carlo Zarattini, Andrea Barbon and Andrew Aziz, *A Profitable Day Trading
Strategy For The U.S. Equity Market* (2024), which compared 5, 15, 30 and
60-minute opening ranges across more than 7,000 US stocks from 2016 to 2023,
and whose relative-volume stock selection is the reason opening relative volume
is displayed here.
- Carlo Zarattini and Andrew Aziz, *Can Day Trading Really Be Profitable?*,
on the 5-minute opening range applied to index ETFs.
- The published ES double-break statistics that motivate the midline being on by
default.
- A published study of 100,569 fifteen-minute opening range entries comparing
profit-target rules, in which the full 1x range projection produced the best
expectancy against the opposite range extreme as stop. This is why 1x is
enabled by default and labelled as such.

These are cited as the origin of the default settings. They are not claims about
what this indicator will do for you, and I have not independently reproduced
their results.

Limitations

- Intraday charts only.
- The statistics are limited by how much history your chart has loaded. On a
1-minute chart that can be considerably fewer sessions than the lookback you
set; the n= column tells you what you actually got.
- Intrabar sequence is unknowable from bar data. Where a single bar reaches both
a target and a stop, the statistics count the stop.
- This is a levels-and-context tool. It does not generate buy or sell signals,
it does not size positions, and nothing in it should be read as a prediction.
Notas de Lançamento
Fixes a runtime error that could stop the indicator from drawing.

On charts with many bars between sessions - most commonly 1-minute charts of
24-hour instruments such as index futures - the indicator would draw correctly
for a moment and then fail with "The requested historical offset is beyond the
historical buffer's limit."

The cause was in how previous sessions' ranges were positioned. Drawings
anchored to a bar index require Pine to walk back through chart history to reach
that bar, and on a 1-minute futures chart even the default five-session lookback
reaches several thousand bars back, past the buffer limit. The range boxes,
levels and labels are now anchored by timestamp instead, which removes that
lookup entirely.

Practical effect: the session lookback now works on any intraday timeframe,
including the maximum of forty sessions on 1-minute charts, where it previously
could not.

No settings, defaults or calculations have changed. The levels, the midline, the
targets and the measured statistics all behave exactly as before.
Notas de Lançamento
Fixed: nothing was drawn when the chart session was set to Regular hours.
Session start no longer depends on seeing an out-of-session bar, which a
regular-hours chart never has.

Session ranges now follow the visible chart - scroll back and those days are
drawn. "Sessions to draw" is renamed "Sessions drawn at once" (default 20, up to
150) and now caps only how many appear together, not how far back you can look.

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.