Advertisement
PineCoders

Pivot Points High Low + Other Value

Sep 11th, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. //@version=4
  2. study("Pivot Points High Low", shorttitle="Pivots HL", overlay=true)
  3.  
  4. lenH = input(title="Length High", type=input.integer, defval=10, minval=1)
  5. lenL = input(title="Length Low", type=input.integer, defval=10, minval=1)
  6. mult1 = input(0.5, "Line 1 multiple")
  7. mult2 = input(1.0, "Line 2 multiple")
  8.  
  9. var float zero_pt_five_Hi = na
  10. var float zero_pt_five_Lo = na
  11. var float one_pt_Hi = na
  12. var float one_pt_Lo = na
  13.  
  14. fun(src, len, isHigh) =>
  15. p = nz(src[len])
  16. isFound = true
  17. for i = 0 to len - 1
  18. if isHigh and src[i] > p
  19. isFound := false
  20.  
  21. if not isHigh and src[i] < p
  22. isFound := false
  23.  
  24. for i = len + 1 to 2 * len
  25. if isHigh and src[i] >= p
  26. isFound := false
  27.  
  28. if not isHigh and src[i] <= p
  29. isFound := false
  30. isFound ? p : na
  31.  
  32. newHi = fun(high, lenH, true)
  33. if not na(newHi)
  34. baseHi = high[lenH]-low[lenH]
  35. label.new(bar_index[lenH], high[lenH], tostring(high[lenH]) + "\n" + tostring(baseHi * mult1), style=label.style_labeldown, yloc=yloc.abovebar, color=color.lime)
  36. zero_pt_five_Hi := newHi + baseHi * mult1
  37. one_pt_Hi := newHi + baseHi * mult2
  38.  
  39. newLo = fun(low, lenL, false)
  40. if not na(newLo)
  41. baseLo = high[lenL]-low[lenL]
  42. label.new(bar_index[lenH], low[lenH], tostring(low[lenH]) + "\n" + tostring(baseLo * mult1), style=label.style_labelup, yloc=yloc.belowbar, color=color.red)
  43. zero_pt_five_Lo := newLo - baseLo * mult1
  44. one_pt_Lo := newLo - baseLo * mult2
  45.  
  46. plot(zero_pt_five_Hi, "Last High", color.green, 2, plot.style_circles, offset = -lenH)
  47. plot(zero_pt_five_Lo, "Last Low", color.red, 2, plot.style_circles, offset = -lenL)
  48. plot(one_pt_Hi, "1.0 Hi Ext", color.yellow, 2, plot.style_circles, offset = -lenH)
  49. plot(one_pt_Lo, "1.0 Low Ext", color.orange, 2, plot.style_circles, offset = -lenL)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement