The code (v3) looks like this:
Code: Select all
//@version=3
study(title='Opening Range Breakout Lines', shorttitle='Opening Range Breakout Lines', overlay=true)
// Based on "[STRATEGY][RS]Open Session Breakout Trader" by RicardoSantos Published Jul 10, 2017
// All credit for the base coding of this script goes to Ricardo
// His script can be viewed at https://www.tradingview.com/script/mIvVYU42-STRATEGY-RS-Open-Session-Breakout-Trader/
use_trade_session = true
trade_session = input(title='Trade Session(xxxx-xxxx to define a interval):', type=session, defval='1801-1600', confirm=false)
isinsession = use_trade_session ? not na(time('1', trade_session)) : true
percent_range_multiplier = input(0.15)
r = security(tickerid, 'D', atr(100)[1])
open_price = open
open_price := change(use_trade_session and isinsession ? 1 : 0) > 0 ? open : open_price[1]
buy_line = open_price + r * percent_range_multiplier
sel_line = open_price - r * percent_range_multiplier
plot(series=not isinsession ? na : open_price, title='Session Open Price', color=black, linewidth=4, style=linebr, transp=0)
plot(series=not isinsession ? na : buy_line, title='Buy Line', color=green, linewidth=4, style=linebr, transp=0)
plot(series=not isinsession ? na : sel_line, title='Sell Line', color=maroon, linewidth=4, style=linebr, transp=0)
// Conditions to buy/sell on the first bar, since cross's arent detected.
buy_on_1st_bar = change(open_price) != 0 and high > buy_line
sel_on_1st_bar = change(open_price) != 0 and low < sel_line
buy_trigger = crossover(close, buy_line) and isinsession
sel_trigger = crossunder(close, sel_line) and isinsession
plotshape(buy_trigger, style=shape.labelup, color=green, location=location.belowbar, textcolor=white, text="Buy", title="Buy")
plotshape(sel_trigger, style=shape.labeldown, color=red, location=location.abovebar, textcolor=white, text="Sell", title="Sell")
plotarrow(sel_trigger?-1:na, title="SELL Arrow", colordown=red, maxheight=100, minheight=50, transp=20)
plotarrow(buy_trigger?1:na, title="BUY Arrow", colordown=green, maxheight=100, minheight=50, transp=20)
alertcondition(buy_trigger, title="Buy Alert", message="Breakout Lines Possible Buy")
alertcondition(sel_trigger, title="Sell Alert", message="Breakout Lines Possible Sell")
// Christmas Update Dec 27, 2019