xmd79

Trend Lines

Nov 14th, 2021 (edited)
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 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('Trend Lines', overlay=true)
  6. lb = input.int(30, title='Left Bars', minval=1)
  7. rb = input.int(30, title='Right Bars', minval=1)
  8. showpivot = input(true, title='Show Pivot Points')
  9. chdashed = input(true, title='Show Old Line as Dashed')
  10. ucolor = input(defval=color.yellow, title='Uptrend line color')
  11. dcolor = input(defval=color.yellow, title='Downtrend line color')
  12.  
  13. mb = lb + rb + 1
  14.  
  15. float top = na
  16. float bot = na
  17. highestbars_1 = ta.highestbars(high, mb) // Pivot High
  18. iff_1 = highestbars_1 == -rb ? high[rb] : na
  19. top := not na(high[mb]) ? iff_1 : na
  20. lowestbars_1 = ta.lowestbars(low, mb) // Pivot Low
  21. iff_2 = lowestbars_1 == -rb ? low[rb] : na
  22. bot := not na(low[mb]) ? iff_2 : na
  23.  
  24. plotshape(top and showpivot, text='H', style=shape.labeldown, color=color.new(color.white, 100), textcolor=color.new(color.red, 0), location=location.abovebar, offset=-rb)
  25. plotshape(bot and showpivot, text='L', style=shape.labelup, color=color.new(color.white, 100), textcolor=color.new(color.lime, 0), location=location.belowbar, offset=-rb)
  26.  
  27. ltop = ta.valuewhen(top, top, 1)
  28. bst = 0
  29. bst := top ? 1 : nz(bst[1]) + 1
  30. float t_angle = 0.0
  31. t_angle := t_angle[1]
  32. if not na(ltop) and not na(top)
  33. line tline = na
  34. if ltop > top
  35. tline := line.new(bar_index - bst[1] - rb, high[bst[1] + rb], bar_index - rb, high[rb], color=dcolor, extend=extend.right)
  36. t_angle := (high[bst[1] + rb] - high[rb]) / bst[1]
  37. if t_angle < t_angle[1] and t_angle[1] != 0
  38. line.set_extend(tline[1], extend=extend.none)
  39. if t_angle > t_angle[1] and t_angle[1] != 0
  40. line.set_extend(tline, extend=extend.none)
  41. if ltop <= top
  42. t_angle := 0.0
  43. t_angle
  44. if chdashed
  45. line.set_style(tline[1], style=line.style_dashed)
  46.  
  47. lbot = ta.valuewhen(bot, bot, 1)
  48. bsb = 0
  49. bsb := bot ? 1 : nz(bsb[1]) + 1
  50. float b_angle = 0.0
  51. b_angle := b_angle[1]
  52. if not na(lbot) and not na(bot)
  53. line bline = na
  54. if lbot < bot
  55. bline := line.new(bar_index - bsb[1] - rb, low[bsb[1] + rb], bar_index - rb, low[rb], color=ucolor, extend=extend.right)
  56. b_angle := (low[bsb[1] + rb] - low[rb]) / bsb[1]
  57. if b_angle > b_angle[1] and b_angle[1] != 0
  58. line.set_extend(bline[1], extend=extend.none)
  59. if b_angle < b_angle[1] and b_angle[1] != 0
  60. line.set_extend(bline, extend=extend.none)
  61. if lbot >= bot
  62. b_angle := 0.0
  63. b_angle
  64. if chdashed
  65. line.set_style(bline[1], style=line.style_dashed)
  66.  
  67.  
  68.  
Add Comment
Please, Sign In to add comment