molepy

ORB

Thanks to ChrisMoody for the original script...
Added compatibility with After Hour Market
Added custom period selection
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
//Created by user ChrisMoody, with help from Alex in TechSupport and TheLark
//Currently works on Stocks
//Currently works on Forex but only based on the New York Session starting at 1700 East Coast Time
//Futurer Versions will have options to plot sessions bsed on Forex Europe Opening Range , Asia, etc.
// Modified by molepy from here ...
// v1.00 Added Auto Period detection. Excluding Day, Week and Month
// v1.00 Painting Top/Bottom area
// v1.01 Added compatibility with After Hour Market
// v1.02 Change fix period exclusion for parameter selection
// v1.03 Change predefined parameter selection for custom period selection
study(title="ORB", shorttitle="ORB 1.03", overlay=true)

period1 = input(title="Period 1", type=resolution, defval="3")
period2 = input(title="Period 2", type=resolution, defval="15")
period3 = input(title="Period 3", type=resolution, defval="30")
period4 = input(title="Period 4", type=resolution, defval="60")

is_period (ptest) =>
    ptest == period ? 1 : 0

period_flag =
    is_period (period1) +
    is_period (period2) +
    is_period (period3) +
    is_period (period4)

is_newbar(res) => change(time(res)) != 0 

adopt(s) =>
    t = tickerid(syminfo.prefix, ticker, session.regular)
    security(t, period, s, true) 

high_range = valuewhen(is_newbar('D'),high,0)
low_range = valuewhen(is_newbar('D'),low,0)

up = plot(period_flag ? adopt(high_range) : na, color = lime, style=circles, linewidth=4)
down = plot(period_flag ? adopt(low_range) : na, color = #DC143C, style=circles, linewidth=4) 

trans = 75
fill(up, down, color = gray, transp=trans)