RicardoSantos

[RS]Temporal Open Diferential V0

EXPERIMENTAL: Diferencial from Opening "Timeframe" Price
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?
study("[RS]Temporal Open Diferential V0")
otracker = input(title='Open Timeframe:', defval='M', type=string)
src = input(title='Source:', type=source, defval=hl2)
SHOW_MA = input(title='Show Slow Moving Average:', type=bool, defval=true)
smooth = input(2)
MA_length = input(8)
SHOW_HHL = input(title='Show Historic Extremes:', type=bool, defval=true)

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

track = sma(src - security(tickerid, otracker, open), smooth)
ma = sma(track, MA_length)
track_color = track > 0 and rising(track, 1) ? green: track>0?olive : track < 0 and falling(track, 1) ? maroon : track < 0 ? orange : gray

hline(0, color=black)
plot(track, style=columns, color=track_color)
plot(not SHOW_MA ? na : ma, color=black)
plot(newbar(otracker)?0:na, style=cross, color=black, linewidth=3)

hh=not SHOW_HHL ? na : na(track)? 0 : track >= hh[1] ? track : hh[1]
ll=not SHOW_HHL ? na : na(track)? 0 : track <= ll[1] ? track : ll[1]

plot(not SHOW_HHL ? na : hh, color=hh == hh[1]?black:na)
plot(not SHOW_HHL ? na : ll, color=ll == ll[1]?black:na)