Advertisement
PineCoders

DW pivots

Jan 26th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.27 KB | None | 0 0
  1. // LOVE JOY PEACE PATIENCE KINDNESS GOODNESS FAITHFULNESS GENTLENESS SELF-CONTROL
  2. // Original Script: https://www.tradingview.com/script/9dK1FvCB/
  3. // @author LonesomeTheBlue
  4. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  5. // Thank you Alex Grover for helping point me in the right direction regarding the capabilities of label.new which led me to line.new
  6. // Naturally pinecoders already had covered the questions I was asking:
  7. // http://www.pinecoders.com/faq_and_code/#how-can-i-keep-only-the-last-x-labels-or-lines
  8. // Updated By: JOSHUAMCGOWAN
  9. // Date: 1-26-2020
  10. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  11.  
  12. // Concept taken from Griss' and Brian Beamish's conversation here:
  13. // https://www.youtube.com/watch?v=pbSBW5otxo8
  14. // @version=4
  15.  
  16. study("The Griss Matrix - TRI LEVEL2 RITE Program", overlay =true)
  17.  
  18. //////////////////////////////////////////////////////////////////////////////////////////////
  19. // Original Inputs and Variables
  20. //////////////////////////////////////////////////////////////////////////////////////////////
  21.  
  22. // Increase these values to pickup less pivot points and reduce to identify more pivot highs/lows.
  23. lb = input(3, title="Left Bars")
  24. rb = input(3, title="Right Bars")
  25. repaint = input(false)
  26. repaintOffset = repaint ? 0 : 1
  27. showChartRes = input(false)
  28. showDailyRes = input(true)
  29. showWeeklyRes = input(true)
  30.  
  31. mb = lb + rb + 1
  32.  
  33. // These need to get offset to the left by left bars input above.
  34. pivot_top = iff(not na(high), iff(highestbars(mb) == -lb, true, false), false)
  35. pivot_bot = iff(not na(low), iff(lowestbars(mb) == -lb, true, false), false)
  36.  
  37. top_value = valuewhen(pivot_top,high[lb],0)
  38. bot_value = valuewhen(pivot_bot,low[lb],0)
  39.  
  40. // Daily
  41. top_value_d = repaint ? security(syminfo.tickerid, 'D', top_value) : security(syminfo.tickerid, 'D', top_value[1], lookahead = barmerge.lookahead_on)
  42. bot_value_d = repaint ? security(syminfo.tickerid, 'D', bot_value) : security(syminfo.tickerid, 'D', bot_value[1], lookahead = barmerge.lookahead_on)
  43. // Weekly
  44. top_value_w = repaint ? security(syminfo.tickerid, 'W', top_value) : security(syminfo.tickerid, 'W', top_value[1], lookahead = barmerge.lookahead_on)
  45. bot_value_w = repaint ? security(syminfo.tickerid, 'W', bot_value) : security(syminfo.tickerid, 'W', bot_value[1], lookahead = barmerge.lookahead_on)
  46.  
  47. plotchar(top_value, "top_value", "", location.top)
  48. plotchar(bot_value, "bot_value", "", location.top)
  49. plotchar(top_value_d, "top_value_d", "", location.top)
  50. plotchar(bot_value_d, "bot_value_d", "", location.top)
  51. plotchar(top_value_w, "top_value_w", "", location.top)
  52. plotchar(bot_value_w, "bot_value_w", "", location.top)
  53.  
  54. // ————— Create labels while keeping a trail of label ids in series "lbl".
  55. // See the following for details: http://www.pinecoders.com/faq_and_code/#how-can-i-keep-only-the-last-x-labels-or-lines
  56.  
  57. // // Monthly Levels //
  58. // line top_lbl_m = na
  59. // if change(pivot_top_m)
  60. // top_lbl_m := line.new(bar_index[lb], high[lb], bar_index, high[lb], extend=extend.right, color=color.maroon, width=3)
  61.  
  62. // line bot_lbl_m = na
  63. // if change(pivot_bot_m)
  64. // bot_lbl_m := line.new(bar_index[lb], low[lb], bar_index, low[lb], extend=extend.right, color=color.maroon, width=3)
  65.  
  66. // Current chart res
  67. if change(top_value) and showChartRes
  68. line.new(bar_index[lb], top_value[lb], bar_index, top_value[lb], extend=extend.right, color=color.lime, width=2)
  69. if change(bot_value) and showChartRes
  70. line.new(bar_index[lb], bot_value[lb], bar_index, bot_value[lb], extend=extend.right, color=color.maroon, width=2)
  71.  
  72. // Daily Levels
  73. if change(top_value_d) and showDailyRes
  74. line.new(bar_index[lb], top_value_d[lb], bar_index, top_value_d[lb], extend=extend.right, color=color.green, width=2)
  75. if change(bot_value_d) and showDailyRes
  76. line.new(bar_index[lb], bot_value_d[lb], bar_index, bot_value_d[lb], extend=extend.right, color=color.red, width=2)
  77.  
  78. // Weekly Levels
  79. if change(top_value_w) and showWeeklyRes
  80. line.new(bar_index[lb], top_value_w[lb], bar_index, top_value_w[lb], extend=extend.right, color=color.green, width=2)
  81. if change(bot_value_w) and showWeeklyRes
  82. line.new(bar_index[lb], bot_value_w[lb], bar_index, bot_value_w[lb], extend=extend.right, color=color.red, width=2)
  83.  
  84. // // Daily Levels //
  85. // line top_lbl_d = na
  86. // if change(pivot_top_d)
  87. // top_lbl_d := line.new(bar_index[lb], high[lb], bar_index, high[lb], extend=extend.right, color=color.orange, width=2)
  88.  
  89. // line bot_lbl_d = na
  90. // if change(pivot_bot_d)
  91. // bot_lbl_d := line.new(bar_index[lb], low[lb], bar_index, low[lb], extend=extend.right, color=color.orange, width=2)
  92.  
  93. // plot(iff(not na(high[mb]), iff(highestbars(mb) == -lb, high[lb], na), na), style = shape.cross, linewidth = 3, color = color.maroon, offset = -lb)
  94. // plot(iff(not na(low[mb]), iff(lowestbars(mb) == -lb, low[lb], na), na), style = shape.cross, linewidth = 3, color = color.green, offset = -lb)
  95.  
  96. //DRAWS PIVOT SHAPES// Helps to visually confirm pivots/levels.
  97. // plotshape(pivot_top, style=shape.cross, location=location.abovebar, color=color.maroon, offset = -lb)
  98. // plotshape(pivot_bot, style=shape.cross, location=location.belowbar, color=color.green, offset = -lb)
  99. // plotshape(iff(not na(high[mb]), iff(highestbars(mb) == -lb, high[lb], na), na), style=shape.cross, location=location.abovebar, color=color.maroon, offset = -lb)
  100. // plotshape(iff(not na(low[mb]), iff(lowestbars(mb) == -lb, low[lb], na), na), style=shape.cross, location=location.belowbar, color=color.green, offset = -lb)
  101.  
  102. // plot(top_value, title='top_value', transp=100)
  103. // plot(bot_value, title='bot_value', transp=100)
  104. // plot(pivot_top==true?1:0, title='pivot_top', transp=100)
  105. // plot(pivot_bot==true?1:0, title='pivot_bot', transp=100)
  106.  
  107.  
  108. //Additional Notes by Original Author//
  109. // sellcondition = iff(not na(high), iff(highestbars(mb) == -lb, true, false), false)
  110. // buycondition = iff(not na(low), iff(lowestbars(mb) == -lb, true, false), false)
  111. // alertcondition(buycondition, title='Pivot HL Signal', message='Pivot HL Buy Signal')
  112. // alertcondition(sellcondition, title='Pivot HL Sell Signal', message='Pivot HL Sell Signal')
  113.  
  114. // END //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement