Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. //
  2. // @author LonesomeTheBlue
  3. //
  4. //@version=3
  5. study("Higher High Lower Low Strategy", overlay =true)
  6. lb = input(2, title="Left Bars", minval = 1)
  7. rb = input(2, title="Right Bars", minval = 1)
  8.  
  9. showsupres = input(true, title="Show Support/Resistance")
  10. changebarcol = input(true, title="Change Bar Color")
  11. mb = lb + rb + 1
  12.  
  13. ph = iff(not na(high[mb]), iff(highestbars(high, mb) == -lb, high[lb], na), na) // Pivot High
  14. pl = iff(not na(low[mb]), iff(lowestbars(low, mb) == -lb, low[lb], na), na) // Pivot Low
  15.  
  16. hl = na
  17. hl := iff(ph, 1, iff(pl, -1, na)) // Trend direction
  18. zz = na
  19. zz := iff(ph, ph, iff(pl, pl, na)) // similar to zigzag but may have multiple highs/lows
  20. zz :=iff(pl and hl == -1 and valuewhen(hl, hl, 1) == -1 and pl > valuewhen(zz, zz, 1), na, zz)
  21. zz :=iff(ph and hl == 1 and valuewhen(hl, hl, 1) == 1 and ph < valuewhen(zz, zz, 1), na, zz)
  22.  
  23. hl := iff(hl==-1 and valuewhen(hl, hl, 1)==1 and zz > valuewhen(zz, zz, 1), na, hl)
  24. hl := iff(hl==1 and valuewhen(hl, hl, 1)==-1 and zz < valuewhen(zz, zz, 1), na, hl)
  25. zz := iff(na(hl), na, zz)
  26.  
  27. findprevious()=> // finds previous three points (b, c, d, e)
  28. ehl = iff(hl==1, -1, 1)
  29. loc1 = 0.0, loc2 = 0.0, loc3 = 0.0, loc4 = 0.0
  30. xx = 0
  31. for x=1 to 1000
  32. if hl[x]==ehl and not na(zz[x])
  33. loc1 := zz[x]
  34. xx := x + 1
  35. break
  36. ehl := hl
  37. for x=xx to 1000
  38. if hl[x]==ehl and not na(zz[x])
  39. loc2 := zz[x]
  40. xx := x + 1
  41. break
  42. ehl := iff(hl==1, -1, 1)
  43. for x=xx to 1000
  44. if hl[x]==ehl and not na(zz[x])
  45. loc3 := zz[x]
  46. xx := x + 1
  47. break
  48. ehl := hl
  49. for x=xx to 1000
  50. if hl[x]==ehl and not na(zz[x])
  51. loc4 := zz[x]
  52. break
  53. [loc1, loc2, loc3, loc4]
  54.  
  55. a = na, b = na, c = na, d = na, e = na
  56. if not na(hl)
  57. [loc1, loc2, loc3, loc4] = findprevious()
  58. a := zz
  59. b := loc1
  60. c := loc2
  61. d := loc3
  62. e := loc4
  63.  
  64. _hh = zz and (a > b and a > c and c > b and c > d)
  65. _ll = zz and (a < b and a < c and c < b and c < d)
  66. _hl = zz and ((a >= c and (b > c and b > d and d > c and d > e)) or (a < b and a > c and b < d))
  67. _lh = zz and ((a <= c and (b < c and b < d and d < c and d < e)) or (a > b and a < c and b > d))
  68.  
  69. plotshape(_hl, text="HL", title="Higher Low", style=shape.labelup, color=lime, textcolor=black, location=location.belowbar, transp=0, offset = -lb)
  70. plotshape(_hh, text="HH", title="Higher High", style=shape.labeldown, color=lime, textcolor=black, location=location.abovebar, transp=0, offset = -lb)
  71. plotshape(_ll, text="LL", title="Lower Low", style=shape.labelup, color=red, textcolor=white, location=location.belowbar, transp=0, offset = -lb)
  72. plotshape(_lh, text="LH", title="Lower High", style=shape.labeldown, color=red, textcolor=white, location=location.abovebar, transp=0, offset = -lb)
  73.  
  74. res = na, sup = na
  75. res := iff(_lh, zz, res[1])
  76. sup := iff(_hl, zz, sup[1])
  77.  
  78. trend = na
  79. trend := iff(close > res, 1, iff(close < sup, -1, nz(trend[1])))
  80.  
  81. res := iff((trend == 1 and _hh) or (trend == -1 and _lh), zz, res)
  82. sup := iff((trend == 1 and _hl) or (trend == -1 and _ll), zz, sup)
  83.  
  84. plot(showsupres ? res : na, title="Resistance", color= na(res) ? na : red, linewidth=2, style=circles, offset = -lb)
  85. plot(showsupres ? sup : na, title="Support", color= na(sup) ? na : blue, linewidth=2, style=circles, offset = -lb)
  86.  
  87. barcolor(color = iff(changebarcol, iff(trend == 1, blue, black), na))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement