Strategy · Pine Script v5 · On the chart

ORB - Opening Range Breakout

by Basant1Saini· code credited to TradingTools

ORB - Opening Range Breakout calculates the highest high and lowest low during a configurable opening session and trades breakouts during the subsequent trading session.

View on GitHub

GitHub stars1on the repository
Pine versionv5runs as is
Lines of code68
Settings8inputs
LicenceNone statedfile: MPL-2.0
Last update8 months ago4 Mar 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

68 lines of Pine Script v5 from 1_ORB/1_ORB.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

1_ORB.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0
// © TradingTools

//@version=5
strategy("ORB - Opening Range Breakout", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

// ─── Inputs ───
orbMinutes      = input.int(15, "Opening Range (minutes)", minval=5, step=5, group="ORB Settings")
sessionStart    = input.session("0930-0945", "Opening Range Session", group="ORB Settings")
tradeSession    = input.session("0930-1600", "Trading Session", group="ORB Settings")
useAtrSL        = input.bool(true, "Use ATR-based Stop Loss", group="Risk Management")
atrLength       = input.int(14, "ATR Length", group="Risk Management")
atrMult         = input.float(1.5, "ATR Multiplier for SL", step=0.1, group="Risk Management")
rrRatio         = input.float(2.0, "Risk:Reward Ratio", step=0.1, group="Risk Management")
showORB         = input.bool(true, "Show ORB Zone", group="Display")

// ─── Session Detection ───
isORBSession    = not na(time(timeframe.period, sessionStart))
isTradeSession  = not na(time(timeframe.period, tradeSession))

// ─── Opening Range Calculation ───
var float orbHigh = na
var float orbLow  = na
var bool  orbSet  = false

if isORBSession
    if not isORBSession[1]
        orbHigh := high
        orbLow  := low
        orbSet  := false
    else
        orbHigh := math.max(orbHigh, high)
        orbLow  := math.min(orbLow, low)
else if not isORBSession and isORBSession[1]
    orbSet := true

// ─── ATR for Stop Loss ───
atrVal = ta.atr(atrLength)

// ─── Entry Conditions ───
longCondition  = orbSet and isTradeSession and ta.crossover(close, orbHigh)
shortCondition = orbSet and isTradeSession and ta.crossunder(close, orbLow)

// ─── Execute Trades ───
if longCondition and strategy.position_size == 0
    stopLoss   = useAtrSL ? close - (atrVal * atrMult) : orbLow
    takeProfit = close + (close - stopLoss) * rrRatio
    strategy.entry("ORB Long", strategy.long)
    strategy.exit("ORB Long Exit", "ORB Long", stop=stopLoss, limit=takeProfit)

if shortCondition and strategy.position_size == 0
    stopLoss   = useAtrSL ? close + (atrVal * atrMult) : orbHigh
    takeProfit = close - (stopLoss - close) * rrRatio
    strategy.entry("ORB Short", strategy.short)
    strategy.exit("ORB Short Exit", "ORB Short", stop=stopLoss, limit=takeProfit)

// ─── Close at End of Session ───
if not isTradeSession and strategy.position_size != 0
    strategy.close_all("Session End")

// ─── Plotting ───
orbHighLine = plot(showORB and orbSet ? orbHigh : na, "ORB High", color=color.new(color.green, 0), linewidth=2, style=plot.style_linebr)
orbLowLine  = plot(showORB and orbSet ? orbLow : na, "ORB Low", color=color.new(color.red, 0), linewidth=2, style=plot.style_linebr)
fill(orbHighLine, orbLowLine, color=color.new(color.blue, 85), title="ORB Zone")

// ─── Alerts ───
alertcondition(longCondition, title="ORB Long Breakout", message="ORB: Price broke above Opening Range High")
alertcondition(shortCondition, title="ORB Short Breakdown", message="ORB: Price broke below Opening Range Low")

Overview

When the closing price crosses above the opening range high, it enters a long position; crossing below the low triggers a short position. Exits are managed via an ATR-based or range-boundary stop loss alongside a risk-to-reward take profit target, with all open trades closed at session end. Range boundaries and fill zones are plotted directly on the price chart.

Details

Published by

Basant1Saini on GitHub

Code credit

TradingTools, as written in the script's header

Draws

On the price chart

Markets

Stocks, Indices

Timeframes

M1-M5, M15-H1

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Opening Range (minutes)int15orbMinutes
Opening Range Sessionsession0930-0945sessionStart
Trading Sessionsession0930-1600tradeSession
Use ATR-based Stop LossbooltrueuseAtrSL
ATR Lengthint14atrLength
ATR Multiplier for SLfloat1.5atrMult
Risk:Reward Ratiofloat2.0rrRatio
Show ORB ZonebooltrueshowORB
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

106 stars

This script monitors opening gap conditions and breakout behavior relative to the first candle's range across up to twenty configurable stock tickers. It detects whether following bars remain inside the opening range before breaking out, displaying the status

Strategy v4 Screeners & dashboardsBreakout Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of 1St Bar GAP+BkOut Screener v2 by RM
53 stars

This strategy enters long or short on the price chart when price is on the correct side of a 200-period EMA, MACD agrees, RSI is not at the opposing extreme, ADX exceeds a threshold, volume beats a 20-bar average, and close breaks the recent high or low. A tim

Strategy v6 TrendOscillators & momentum
Updated 2 months ago · MPL-2.0 GitHub repository of BTCUSD 5M Optimized Strategy

Turtle MACD Time-Zone Filter

by skywalker0803r
42 stars

This strategy enters long when price closes above the prior Donchian high and short when it closes below the prior Donchian low, only while flat and inside a Taipei-hour window. It exits on a MACD histogram reversal or through an ATR stop and a percentage take

Strategy v5 BreakoutOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Turtle MACD Time-Zone Filter
39 stars

This intraday strategy implements Mark Fisher's Opening Range Breakout (ORB) methodology tailored for index futures like ES and NQ. It calculates session opening ranges, volume z-scores, and VWAP bands to plot support, resistance, and confirmation levels on th

Strategy v6 BreakoutSessions & time Repaints
Updated 6 days ago · MIT GitHub repository of Futures Intraday Pro (ES/NQ) Strategy

Morning Scalp

by benso87
24 stars

This strategy tracks an opening session time range to establish directional bias and triggers pullback trades using Stochastic RSI. Once price breaks out of the initial range, it establishes a directional bias and enters when the Stochastic RSI crosses over in

Strategy v5 Sessions & timeBreakout
Updated 4 years ago · MPL-2.0 GitHub repository of Morning Scalp
23 stars

This strategy evaluates breakout and trend opportunities on the price chart using a weighted composite score of volume, trend, and candlestick structure. It tracks volume spikes, fast and slow EMAs, higher-timeframe EMA trend alignment, opening ranges, and ses

Strategy v6 TrendVolume Repaints
Updated 4 weeks ago · Custom licence GitHub repository of TradingAlpha Point-Clip Strategy

More Breakout scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers