Code Library / Breakout
Pine Script Range Breakout
Opening range breakout from first hour high/low.
Language: Pine Script · Category: Breakout · Tags: range breakout, opening range, Pine Script, intraday, strategy
Source code
//@version=5
strategy("ORB",overlay=true)
var float rH=na, var float rL=na, var bool rSet=false
inS=time(timeframe.period,"0930-1030")
if inS
if na(rH) or not inS[1]
rH:=high; rL:=low
else
rH:=math.max(rH,high); rL:=math.min(rL,low)
if not inS and inS[1]
rSet:=true
if rSet and not inS
if ta.crossover(close,rH) then strategy.entry("Long",strategy.long)
if ta.crossunder(close,rL) then strategy.entry("Short",strategy.short)
plot(rSet?rH:na,"H",color.green,2,plot.style_stepline)
plot(rSet?rL:na,"L",color.red,2,plot.style_stepline)How to use this snippet
This is a building block, not a finished trading system. Paste it into your own Pine Script project, compile it, and test it on a demo account with your broker's real spreads before relying on it. You can convert it to MQL4 or MQL5 with the Pine Script converter.