Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- study("Pivot Prices", overlay=true)
- tf=input('120')
- leftbars = input(10, minval=1, title='Bars to the left')
- rightbars = input(2, minval=1, title='Bars to the right')
- // Figure out how many of current chart's bar fit in the higher TF, so we know how many bars backward to plot labels.
- f_tfResInMinutes(_resolution) =>
- // Returns resolution of _resolution period in minutes.
- // _resolution: resolution of other timeframe (in timeframe.period string format).
- _mult = security(syminfo.tickerid, _resolution, timeframe.multiplier)
- _res = security(syminfo.tickerid, _resolution, timeframe.isseconds ? 1 : timeframe.isminutes ? 2 : timeframe.isdaily ? 3 : timeframe.isweekly ? 4 : timeframe.ismonthly ? 5 : na)
- _return =
- _res == 1 ? _mult / 60 :
- _res == 2 ? _mult :
- _res == 3 ? _mult * 1440 :
- _res == 4 ? _mult * 10080 :
- _res == 5 ? _mult * 43800 : na
- var higherResInMinutes = f_tfResInMinutes(tf)
- var currentResInMinutes = f_tfResInMinutes(timeframe.period)
- var intraBars = higherResInMinutes / currentResInMinutes
- var idx = rightbars*intraBars
- plotchar(intraBars, "intraBars", "", location.top)
- phigh = security(syminfo.tickerid, tf, pivothigh(high, leftbars,rightbars))//, lookahead = barmerge.lookahead_on)
- plow = security(syminfo.tickerid, tf, pivotlow(low, leftbars,rightbars))//, lookahead = barmerge.lookahead_on)
- newpHigh = phigh and na(phigh[1])
- newpLow = plow and na(plow[1])
- if newpHigh
- label1 = label.new(bar_index[idx], phigh+tr, text=tostring(phigh), style=label.style_labeldown, color=color.orange)
- if newpLow
- label2 = label.new(bar_index[idx], plow-tr, text=tostring(plow), style=label.style_labelup, color=color.green)
- plotchar(phigh, "phigh", "▲", location.top)
- plotchar(plow, "plow", "▼", location.bottom)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement