xmd79

Trend Lines

Jan 15th, 2023
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1.  
  2.  
  3. //@version=4
  4. study("Trend Lines", overlay=true)
  5. lb = input(13, title="Left Bars", minval=1)
  6. rb = input(21, title="Right Bars", minval=1)
  7. showpivot = input(true, title="Show Pivot Points")
  8. chdashed = input(true, title="Show Old Line as Dashed")
  9.  
  10. mb = lb + rb + 1
  11.  
  12. float top = na
  13. float bot = na
  14. top := iff(not na(high[mb]), iff(highestbars(high, mb) == -rb, high[rb], na), na) // Pivot High
  15. bot := iff(not na(low[mb]), iff(lowestbars(low, mb) == -rb, low[rb], na), na) // Pivot Low
  16.  
  17. plotshape(top and showpivot, text="[PH]", style=shape.labeldown, color=color.white, textcolor=color.black, location=location.abovebar, transp=0, offset = -rb)
  18. plotshape(bot and showpivot, text="[PL]", style=shape.labeldown, color=color.white, textcolor=color.black, location=location.belowbar, transp=0, offset = -rb)
  19.  
  20. ltop = valuewhen(top, top, 1)
  21. bst = 0
  22. bst := top ? 1 : nz(bst[1]) + 1
  23. float t_angle = 0.0
  24. t_angle := t_angle[1]
  25. if not na(ltop) and not na(top)
  26. line tline = na
  27. if ltop > top
  28. tline := line.new(bar_index - bst[1] - rb, high[bst[1] + rb], bar_index - rb, high[rb], color = color.red, extend = extend.right)
  29. t_angle := (high[bst[1] + rb] - high[rb]) / bst[1]
  30. if t_angle < t_angle[1] and t_angle[1] != 0
  31. line.set_extend(tline[1], extend = extend.none)
  32. if t_angle > t_angle[1] and t_angle[1] != 0
  33. line.set_extend(tline, extend = extend.none)
  34. if ltop <= top
  35. t_angle := 0.0
  36. if chdashed
  37. line.set_style(tline[1], style = line.style_dashed)
  38.  
  39. lbot = valuewhen(bot, bot, 1)
  40. bsb = 0
  41. bsb := bot ? 1 : nz(bsb[1]) + 1
  42. float b_angle = 0.0
  43. b_angle := b_angle[1]
  44. if not na(lbot) and not na(bot)
  45. line bline = na
  46. if lbot < bot
  47. bline := line.new(bar_index - bsb[1] - rb, low[bsb[1] + rb], bar_index - rb, low[rb], color = color.blue, extend = extend.right)
  48. b_angle := (low[bsb[1] + rb] - low[rb]) / bsb[1]
  49. if b_angle > b_angle[1] and b_angle[1] != 0
  50. line.set_extend(bline[1], extend = extend.none)
  51. if b_angle < b_angle[1] and b_angle[1] != 0
  52. line.set_extend(bline, extend = extend.none)
  53. if lbot >= bot
  54. b_angle := 0.0
  55. if chdashed
  56. line.set_style(bline[1], style = line.style_dashed)
  57.  
  58.  
  59.  
Advertisement
Add Comment
Please, Sign In to add comment