Advertisement
PineCoders

MTF Pivots

Oct 13th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. //@version=4
  2.  
  3. study("Pivot Prices", overlay=true)
  4. tf=input('120')
  5. leftbars = input(10, minval=1, title='Bars to the left')
  6. rightbars = input(2, minval=1, title='Bars to the right')
  7.  
  8. // Figure out how many of current chart's bar fit in the higher TF, so we know how many bars backward to plot labels.
  9. f_tfResInMinutes(_resolution) =>
  10. // Returns resolution of _resolution period in minutes.
  11. // _resolution: resolution of other timeframe (in timeframe.period string format).
  12. _mult = security(syminfo.tickerid, _resolution, timeframe.multiplier)
  13. _res = security(syminfo.tickerid, _resolution, timeframe.isseconds ? 1 : timeframe.isminutes ? 2 : timeframe.isdaily ? 3 : timeframe.isweekly ? 4 : timeframe.ismonthly ? 5 : na)
  14. _return =
  15. _res == 1 ? _mult / 60 :
  16. _res == 2 ? _mult :
  17. _res == 3 ? _mult * 1440 :
  18. _res == 4 ? _mult * 10080 :
  19. _res == 5 ? _mult * 43800 : na
  20. var higherResInMinutes = f_tfResInMinutes(tf)
  21. var currentResInMinutes = f_tfResInMinutes(timeframe.period)
  22. var intraBars = higherResInMinutes / currentResInMinutes
  23. var idx = rightbars*intraBars
  24. plotchar(intraBars, "intraBars", "", location.top)
  25.  
  26. phigh = security(syminfo.tickerid, tf, pivothigh(high, leftbars,rightbars))//, lookahead = barmerge.lookahead_on)
  27. plow = security(syminfo.tickerid, tf, pivotlow(low, leftbars,rightbars))//, lookahead = barmerge.lookahead_on)
  28. newpHigh = phigh and na(phigh[1])
  29. newpLow = plow and na(plow[1])
  30. if newpHigh
  31. label1 = label.new(bar_index[idx], phigh+tr, text=tostring(phigh), style=label.style_labeldown, color=color.orange)
  32. if newpLow
  33. label2 = label.new(bar_index[idx], plow-tr, text=tostring(plow), style=label.style_labelup, color=color.green)
  34.  
  35. plotchar(phigh, "phigh", "▲", location.top)
  36. plotchar(plow, "plow", "▼", location.bottom)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement