xmd79

Pivot Points High Low Multi Time Frame

May 4th, 2022
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © LonesomeTheBlue
  3.  
  4. //@version=5
  5. indicator("Pivot Points High Low Multi Time Frame", overlay = true, max_lines_count = 500, max_labels_count = 500)
  6. timeframe = input.timeframe(defval = '240')
  7. leftBars = input.int(defval = 2, title = "Left Bars", minval = 1)
  8. rightBars = input.int(defval = 2, title = "Right Bars", minval = 1)
  9. phlinecol = input.color(defval = color.lime, title = "Pivot High/Low Line Colors", inline = "lc")
  10. pllinecol = input.color(defval = color.red, title = "", inline = "lc")
  11. phbgcol = input.color(defval = color.lime, title = "Pivot High BG/Text Colors", inline = "ph")
  12. phtextcol = input.color(defval = color.black, title = "", inline = "ph")
  13. plbgcol = input.color(defval = color.red, title = "Pivot Low BG/Text Colors", inline = "pl")
  14. pltextcol = input.color(defval = color.white, title = "", inline = "pl")
  15.  
  16. get_phpl()=>
  17. float ph = ta.pivothigh(leftBars, rightBars)
  18. float pl = ta.pivotlow(leftBars, rightBars)
  19. phtimestart = ph ? time[rightBars] : na
  20. phtimeend = ph ? time[rightBars - 1] : na
  21. pltimestart = pl ? time[rightBars] : na
  22. pltimeend = pl ? time[rightBars - 1] : na
  23.  
  24. [ph, phtimestart, phtimeend, pl, pltimestart, pltimeend]
  25.  
  26. // get if there if Pivot High/low and their start/end times
  27. [ph, phtimestart, phtimeend, pl, pltimestart, pltimeend] = request.security(syminfo.tickerid, timeframe, get_phpl(), lookahead = barmerge.lookahead_on)
  28.  
  29. // keep time of each bars, this is used for lines/labels
  30. var mytime = array.new_int(0)
  31. array.unshift(mytime, time)
  32.  
  33. // calculate end of the line/time for pivot high/low
  34. bhend = array.get(mytime, math.min(array.indexof(mytime, phtimeend) + 1, array.size(mytime) - 1))
  35. blend = array.get(mytime, math.min(array.indexof(mytime, pltimeend) + 1, array.size(mytime) - 1))
  36.  
  37. // to draw once
  38. float pivothigh = na(ph[1]) and ph ? ph : na
  39. float pivotlow = na(pl[1]) and pl ? pl : na
  40.  
  41. width = (ta.highest(300) - ta.lowest(300)) / 50
  42. if not na(pivothigh)
  43. line.new(x1 = phtimestart, y1 = pivothigh, x2 = bhend, y2 = pivothigh, color = phlinecol, xloc = xloc.bar_time, width = 2)
  44. line.new(x1 = phtimestart, y1 = pivothigh, x2 = phtimestart, y2 = pivothigh + width, color = phlinecol, xloc = xloc.bar_time, width = 2)
  45. line.new(x1 = bhend, y1 = pivothigh, x2 = bhend, y2 = pivothigh + width, color = phlinecol, xloc = xloc.bar_time, width = 2)
  46. label.new(x = (phtimestart + bhend) / 2, y = pivothigh + width,
  47. text = str.tostring(math.round_to_mintick(pivothigh)),
  48. color = phbgcol,
  49. textcolor = phtextcol,
  50. xloc = xloc.bar_time)
  51.  
  52. if not na(pivotlow)
  53. line.new(x1 = pltimestart, y1 = pivotlow, x2 = blend, y2 = pivotlow, color = pllinecol, xloc = xloc.bar_time, width = 2)
  54. line.new(x1 = pltimestart, y1 = pivotlow, x2 = pltimestart, y2 = pivotlow - width, color = pllinecol, xloc = xloc.bar_time, width = 2)
  55. line.new(x1 = blend, y1 = pivotlow, x2 = blend, y2 = pivotlow - width, color = pllinecol, xloc = xloc.bar_time, width = 2)
  56. label.new(x = (pltimestart + blend) / 2, y = pivotlow - width,
  57. text = str.tostring(math.round_to_mintick(pivotlow)),
  58. color = plbgcol,
  59. textcolor = pltextcol,
  60. style = label.style_label_up,
  61. xloc = xloc.bar_time)
  62.  
Advertisement
Add Comment
Please, Sign In to add comment