Strategy · Pine Script v6 · On the chart

ES Opening Range Breakout [trugurpala]

by trugurpala

This strategy builds the opening range high and low during the first configurable minutes of the New York regular session, then enters on a close break of that range.

View on GitHub

GitHub stars4on the repository
Pine versionv6current
Lines of code86
Settings4inputs
LicenceMIT
Last update2 months ago3 Aug 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

86 lines of Pine Script v6 from global-markets/15_es_opening_range.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

15_es_opening_range.pine
//@version=6
// ES S&P500 — Opening Range Breakout (ORB) Strategy
// Author: Ugur Pala · github.com/trugurpala/pinescriptv6
// TradingView: https://tr.tradingview.com/u/trugurpala/
//
// TR: İlk 30 dakikanın yüksek/düşüğünü belirleyip kırılma yönünde giriş yapar.
//     RTH (09:30-16:00 ET) içinde çalışır. Seans sonunda tüm pozisyonlar kapatılır.
// EN: Identifies the first 30-minute high/low and enters on breakout.
//     Works within RTH (09:30-16:00 ET). All positions closed at session end.
//
// Sembol / Symbol: CME_MINI:ES1! veya CME_MICRO:MES1!
// Önerilen TF / Recommended TF: 5M, 15M
strategy("ES Opening Range Breakout [trugurpala]",
    overlay           = true,
    initial_capital   = 25000,
    default_qty_type  = strategy.fixed,
    default_qty_value = 1,
    commission_type   = strategy.commission.cash_per_contract,
    commission_value  = 4.0,
    slippage          = 1)

// ── Inputs ───────────────────────────────────────────────────────────────────
int   orbMins   = input.int(30, "ORB Minutes", minval=5, maxval=60,
                    tooltip="İlk N dakikanın high/low'u / First N-minute high/low")
float atrMult   = input.float(1.5, "SL ATR Mult", step=0.1)
float rr        = input.float(2.0,  "R:R Ratio",   step=0.1)
bool  longOnly  = input.bool(false,  "Long Only")

// ── Seans ve ORB Zamanı / Session and ORB Time ───────────────────────────────
bool  rthOpen   = not na(time(timeframe.period, "0930-0930", "America/New_York"))
bool  inRTH     = not na(time(timeframe.period, "0930-1600", "America/New_York"))
bool  inORB     = not na(time(timeframe.period, "0930-" + str.tostring(930 + orbMins), "America/New_York"))

// ORB yüksek/düşük hesapla
var float orbHigh = na
var float orbLow  = na
var bool  orbDone = false

if rthOpen
    orbHigh := high
    orbLow  := low
    orbDone := false

if inORB and not orbDone
    orbHigh := math.max(orbHigh, high)
    orbLow  := math.min(orbLow,  low)

if not inORB and not orbDone
    orbDone := true

// ── Calculations ─────────────────────────────────────────────────────────────
float atrVal    = ta.atr(14)
bool  longBreak  = orbDone and inRTH and ta.crossover(close, orbHigh)  and strategy.position_size == 0
bool  shortBreak = orbDone and inRTH and ta.crossunder(close, orbLow)  and strategy.position_size == 0

// RTH sonu kapat / Close at RTH end
bool  rthEnd    = inRTH[1] and not inRTH
if rthEnd
    strategy.close_all(comment="RTH Close")

// ── Entries ──────────────────────────────────────────────────────────────────
if longBreak
    float sl = close - atrMult * atrVal
    float tp = close + rr * (close - sl)
    strategy.entry("Long", strategy.long)
    strategy.exit("Long Exit", "Long", stop=sl, limit=tp)

if shortBreak and not longOnly
    float sl = close + atrMult * atrVal
    float tp = close - rr * (sl - close)
    strategy.entry("Short", strategy.short)
    strategy.exit("Short Exit", "Short", stop=sl, limit=tp)

// ── Visuals ──────────────────────────────────────────────────────────────────
plot(orbDone ? orbHigh : na, "ORB High", color.new(color.green, 30), linewidth=2, style=plot.style_linebr)
plot(orbDone ? orbLow  : na, "ORB Low",  color.new(color.red,   30), linewidth=2, style=plot.style_linebr)
bgcolor(inORB  ? color.new(color.orange, 93) : na, title="ORB Window")
bgcolor(not inRTH ? color.new(color.gray, 96) : na, title="Outside RTH")
plotshape(longBreak,  "Long",  shape.triangleup,   location.belowbar, color.green, size=size.small)
plotshape(shortBreak, "Short", shape.triangledown, location.abovebar, color.red,   size=size.small)

// ── Alerts (alert() — strategy içinde çalışır) ───────────────────────────────
if longBreak
    alert("ES ORB Breakout Long — " + str.tostring(close, "#.##"), alert.freq_once_per_bar)
if shortBreak
    alert("ES ORB Breakout Short — " + str.tostring(close, "#.##"), alert.freq_once_per_bar)

Overview

A long triggers when price crosses above the range high while flat; a short triggers on a cross below the range low unless long-only mode is on. The stop is an ATR multiple from the entry close, and the take profit uses the chosen reward-to-risk ratio. It draws the logic on the price chart and closes every position when the regular session ends.

Details

Published by

trugurpala on GitHub

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Breakout, Sessions & time, Volatility & bands

Markets

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.

Topics

aialgorithmic-tradingclaude-codecodexcoding-agentsgithub-copilotopen-sourcepine-scriptpine-script-v6technical-analysis

Settings

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

SettingTypeDefaultVariable
ORB Minutesint30orbMins
SL ATR Multfloat1.5atrMult
R:R Ratiofloat2.0rr
Long OnlyboolfalselongOnly
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 strategy places buy-stop and sell-stop orders around the opening-session high and low, offset by a user-defined pip gap, and only allows those orders during a separate trading session. It exits with a fixed or ATR-based stop loss and a matching take-profi

Strategy v5 Sessions & timeBreakout Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of 50 Pips A Day Strategy - Kaspricci

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

ORION: Hybrid Strategy

by eddiebelaval
7 stars

This strategy identifies volatility breakout opportunities by constructing dynamic ATR-based price boxes and detecting volatility squeezes. Trades are filtered using an exponential moving average trend condition and designated session hours. Entries trigger up

Strategy v5 Volatility & bandsBreakout
Updated 3 months ago · None stated GitHub repository of ORION: Hybrid Strategy
6 stars

This overlay strategy builds independent timed session ranges and marks range, trendline, mean, VWAP, and high-low levels when those displays are enabled. It enters on range breakouts and exits with strategy exits, choosing among range, ATR, fixed-point, and r

Strategy v5 Sessions & timeBreakout
Updated 7 months ago · None stated GitHub repository of MSG Enhanced LEGO System Strategy

ORB Hunter

by nxtaiapp
2 stars

ORB Hunter is an Opening Range Breakout strategy that identifies price breakouts beyond a defined opening session window (such as 09:30 to 09:45 EST). It places long or short trades when price crosses the opening range bounds with buffer, confirmed by optional

Strategy v5 BreakoutSessions & time
Updated 11 months ago · MIT GitHub repository of ORB Hunter
2 stars

This strategy captures momentum moves on gold by combining Bollinger Band breakouts with EMA trend confirmation. It restricts trade entry to active European and US trading sessions based on specified hours. Exits are managed dynamically through an ATR-based in

Strategy v6 BreakoutTrend
Updated 4 months ago · None stated GitHub repository of XAUUSD Momentum Breakout Strategy

More strategys

Trade Your Charts With a Regulated Broker

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

Compare brokers