PineCoders

Ord Vol Marker 5

Mar 14th, 2021 (edited)
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.71 KB | None | 0 0
  1. //@version=4
  2. //@author=LucF
  3.  
  4. // Ord Volume [LucF]
  5. // v1.2, 2019.07.17 15:25 — Luc
  6.  
  7. // Shows average volume for each price wave (a Tim Ord concept).
  8. // It's basically Weis Wave with average volume instead of cumulative volume, plus a few goodies.
  9. // Credits to LazyBear for original Weis Wave code (a David Weis concept).
  10. // Docs: https://www.tradingview.com/script/lhda3xOg-Ord-Volume-LucF/
  11.  
  12. study("Ord Volume [LucF]", shorttitle="Ord Volume4")
  13.  
  14. // —————————— Colors
  15. MyGreenRaw = color.new(#00FF00,0), MyGreenMedium = color.new(#00FF00,40), MyGreenSemiDark = color.new(#00FF00,62), MyGreenDark = color.new(#00FF00,75), MyGreenDarkDark = color.new(#00FF00,82), MyGreenDarkDarkDark = color.new(#00FF00,93)
  16. MyRedRaw = color.new(#FF0000,0), MyRedMedium = color.new(#FF0000,30), MyRedSemiDark = color.new(#FF0000,50), MyRedDark = color.new(#FF0000,75), MyRedDarkDark = color.new(#FF0000,85), MyRedDarkDarkDark = color.new(#FF0000,92)
  17. MyOrangeRaw = color.new(#FF9800,0), MyOrangeMedium = color.new(#FF9800,30), MyOrangeSemiDark = color.new(#FF9800,50), MyOrangeDark = color.new(#FF9800,60)
  18. Invisible = color.new(color.white,100), MyBlack = color.new(color.black,0)
  19.  
  20. // —————————— Inputs
  21. TD1 = "Both"
  22. TD2 = "Longs Only"
  23. TD3 = "Shorts Only"
  24. ColorAvg = input(true, "Distinguish rising/falling states")
  25. ColorBars = input(false, "Color chart bars with rising/falling states & bars")
  26. ShowAvgEma = input(false, "EMA of averages")
  27. ShowLastAvg = input(false, "Last Wave's Ending Average")
  28. ShowLastHighestAvg = input(false, "Last Wave's Highest Average")
  29. TrendReversalLength = input(2, "Trend reversal length", minval=2)
  30. PriceSource = input(close, "Price Source for trend detection")
  31. TradeDirection = input(TD1, "Trade Direction", options=[TD1, TD2, TD3])
  32. ShowMarker1 = input(false, "Marker 1: Breach of previous wave's highest Average")
  33. ShowMarker2 = input(false, "Marker 2: n Consecutive increasing bars in same wave")
  34. Marker2Bars = input(3, "... n", minval=2)
  35. ShowMarker3 = input(false, "Marker 3: Last wave's volume was <% than the previous one.")
  36. Marker3Pct = input(50.0, "... % Trheshold", minval=1.0)
  37. ShowMarker4 = input(false, "Marker 4: Average volume crosses its EMA.")
  38. ShowMarker5 = input(true, "Marker 5: Breach of previous wave's highest Average on smaller avg")
  39. ShortsOnly = TradeDirection==TD3
  40. LongsOnly = TradeDirection==TD2
  41.  
  42. // —————————— Detect Price Waves
  43. var Trend = 0
  44. var Wave = 0
  45. var WaveBars = 0
  46. var CumVolume = volume
  47.  
  48. UpOrDn = PriceSource>PriceSource[1] ? 1 : PriceSource<PriceSource[1] ? -1 : 0 // Price movement Up->1, Dn->-1, No change->0
  49. Trend := (UpOrDn != 0) and (UpOrDn != UpOrDn[1]) ? UpOrDn : Trend // Trend changes when price reverses direction.
  50. ReversalTrend = rising(PriceSource, TrendReversalLength) or falling(PriceSource, TrendReversalLength) // Detect reversal condition.
  51. Wave := (Trend != Wave and ReversalTrend) ? Trend : Wave // Stay in wave until a counter trend of trendDetectionLength occurs.
  52.  
  53. // —————————— States
  54. BullWave = Wave==1
  55. BearWave = Wave==-1
  56. SameWave = Wave==nz(Wave[1])
  57.  
  58. // —————————— Build average volume for current wave.
  59. CumVolume := SameWave ? CumVolume+volume : volume
  60. WaveBars := SameWave ? WaveBars+1 : 1
  61. AverageWaveVolume = CumVolume/WaveBars
  62. AverageWaveVolumeMA = ema( AverageWaveVolume,20)
  63.  
  64. // ————— Keep track of last wave's hi/lo price.
  65.  
  66. // ————— Consecutive increasing average volume bars in same wave.
  67. var IncreasingBars = 0
  68. IncreasingBars := SameWave ? AverageWaveVolume>nz(AverageWaveVolume[1])? IncreasingBars+1 : 0 : 0
  69. // ————— Keep track of last wave's maximum average.
  70. var CurrentMaxAvg = 0.0
  71. CurrentMaxAvg := SameWave ? max(AverageWaveVolume, CurrentMaxAvg) : AverageWaveVolume
  72. // ————— Keep track of last wave ending averages.
  73. var LastMaxAvg = CurrentMaxAvg
  74. var LastAvg1 = 0.0
  75. var LastAvg2 = 0.0
  76. var LastAvg3 = 0.0
  77. // ————— Keep track of last wave his/los.
  78. var LastHi = 0.0
  79. var LastLo = 0.0
  80. LastHi := SameWave ? max(PriceSource, LastHi) : PriceSource
  81. LastLo := SameWave ? min(PriceSource, LastLo) : PriceSource
  82. var LastHi1 = 0.0
  83. var LastLo1 = 0.0
  84. var LastHi2 = 0.0
  85. var LastLo2 = 0.0
  86. var LastHi3 = 0.0
  87. var LastLo3 = 0.0
  88. // ————— Wave Strength
  89. var PriceMove = 0.0
  90. var WaveStrength = 0.0
  91. // Update numbers when changing waves.
  92. if not SameWave
  93. // Last 3 Averages.
  94. LastAvg3 := LastAvg2
  95. LastAvg2 := LastAvg1
  96. LastAvg1 := nz(AverageWaveVolume[1])
  97. LastMaxAvg := CurrentMaxAvg[2]
  98. // Last 3 His/Los.
  99. LastHi3 := LastHi2
  100. LastHi2 := LastHi1
  101. LastHi1 := nz(LastHi[1])
  102. LastLo3 := LastLo2
  103. LastLo2 := LastLo1
  104. LastLo1 := nz(LastLo[1])
  105. // Wave strength
  106. PriceMove := abs(LastHi1-LastLo1)/(BullWave[1]?LastLo1:LastHi1)
  107. WaveStrength := PriceMove*CumVolume[1]
  108.  
  109. // plot(WaveStrength)
  110. // plotchar(PriceMove,"PriceMove","")
  111. // plotchar(CumVolume[1],"CumVolume[1]","")
  112. // plotchar(WaveStrength, "WaveStrength","")
  113.  
  114. // plotchar(LastHi3,"LastHi3","")
  115. // plotchar(LastHi2,"LastHi2","")
  116. // plotchar(LastHi1,"LastHi1","")
  117. // plotchar(LastHi,"LastHi","")
  118. // plotchar(LastLo3,"LastLo3","")
  119. // plotchar(LastLo2,"LastLo2","")
  120. // plotchar(LastLo1,"LastLo1","")
  121. // plotchar(LastLo,"LastLo","")
  122.  
  123. // —————————— Markers
  124. // ————— Marker 1: Last wave's maximum average surpassed
  125. M1U = ShowMarker1 and not ShortsOnly and BullWave and close>open and (crossover(AverageWaveVolume, LastMaxAvg) or (not SameWave and AverageWaveVolume>CurrentMaxAvg[1]))
  126. M1D = ShowMarker1 and not LongsOnly and BearWave and close<open and (crossover(AverageWaveVolume, LastMaxAvg) or (not SameWave and AverageWaveVolume>CurrentMaxAvg[1]))
  127. // ————— Marker 2: consecutive increasing bars in same wave
  128. M2U = ShowMarker2 and not ShortsOnly and BullWave and IncreasingBars==Marker2Bars
  129. M2D = ShowMarker2 and not LongsOnly and BearWave and IncreasingBars==Marker2Bars
  130. // ————— Marker 3: Last wave's volume was <% than the previous one.
  131. M3U = ShowMarker3 and not ShortsOnly and BullWave and not SameWave and (LastAvg1<LastAvg2*Marker3Pct/100 or LastAvg1<LastAvg3*Marker3Pct/100) and LastLo1<LastLo3
  132. M3D = ShowMarker3 and not LongsOnly and BearWave and not SameWave and (LastAvg1<LastAvg2*Marker3Pct/100 or LastAvg1<LastAvg3*Marker3Pct/100) and LastHi1>LastHi3
  133. // ————— Marker 4: Avg volume crosses its MA.
  134. M4U = ShowMarker4 and not ShortsOnly and BullWave and crossover(AverageWaveVolume, AverageWaveVolumeMA)
  135. M4D = ShowMarker4 and not LongsOnly and BearWave and crossover(AverageWaveVolume, AverageWaveVolumeMA)
  136. // ————— Marker 5: Avg volume crosses its MA.
  137. M5U = ShowMarker5 and not ShortsOnly and BullWave and (crossover(AverageWaveVolume, LastMaxAvg) or (not SameWave and AverageWaveVolume>CurrentMaxAvg[1])) and LastMaxAvg < LastAvg3
  138. M5D = ShowMarker5 and not LongsOnly and BearWave and (crossover(AverageWaveVolume, LastMaxAvg) or (not SameWave and AverageWaveVolume>CurrentMaxAvg[1])) and LastMaxAvg < LastAvg3
  139. // plot(LastAvg3)
  140. // plotchar(LastAvg1,"LastAvg","")
  141. // plotchar(LastAvg2,"LastAvg2","")
  142. // plotchar(LastAvg2*Marker3Pct/100,"LastAvg2*Marker3Pct/100","")
  143. // plotchar(LastAvg3,"LastAvg3","")
  144. // plotchar(LastAvg3*Marker3Pct/100,"LastAvg3*Marker3Pct/100","")
  145.  
  146. AvgUp = rising(AverageWaveVolume,1)
  147. // plotchar(AvgUp and close>open and BullWave and ColorBars, "Rising", "+")
  148. // —————————— Plots
  149. ColorOfAvg = BullWave? AvgUp and ColorAvg? MyGreenDark:MyGreenDarkDark: AvgUp and ColorAvg? MyRedDark:MyRedDarkDark
  150. ColorOfBars = ColorBars? BullWave? AvgUp and close>open? MyGreenRaw:na : AvgUp and close<open ? MyRedRaw:na : na
  151. // ColorOfBars = ColorBars? BullWave? rising(AverageWaveVolume,1) and close>open? MyGreenRaw:na : rising(AverageWaveVolume,1) and close<open ? MyRedRaw:na : na
  152. // ColorOfAvg = BullWave? rising(AverageWaveVolume,1) and ColorAvg? MyGreenDark:MyGreenDarkDark: rising(AverageWaveVolume,1) and ColorAvg? MyRedDark:MyRedDarkDark
  153. // ColorOfBars = ColorBars? BullWave? rising(AverageWaveVolume,1) and close>open? MyGreenRaw:na : rising(AverageWaveVolume,1) and close<open ? MyRedRaw:na : na
  154.  
  155. // ColorOfBars = ColorBars? BullWave? rising(AverageWaveVolume,1) and close>open ? MyGreenRaw:MyOrangeRaw: rising(AverageWaveVolume,1) and close<open ? MyRedRaw:MyOrangeRaw : na
  156. // ColorOfBars = ColorBars? BullWave? rising(AverageWaveVolume,1) ? MyGreenRaw:MyGreenMedium: rising(AverageWaveVolume,1) ? MyRedRaw:MyRedMedium : na
  157. plot(AverageWaveVolume, "Average Volume", color=ColorOfAvg, linewidth=1, style=plot.style_area)
  158. plot(ShowAvgEma? AverageWaveVolumeMA:na, "EMA of Average Volume", color=MyOrangeMedium, linewidth=1)
  159. plot(ShowLastAvg ? LastAvg1:na, "Last Wave Average", color=BullWave? MyRedMedium:MyGreenMedium, linewidth=2, style=plot.style_circles)
  160. plot(ShowLastHighestAvg ? LastMaxAvg:na, "Last wave Maximum Average", color=not SameWave? Invisible: BullWave? MyRedMedium:MyGreenMedium, linewidth=2, style=plot.style_line)
  161. barcolor(color=ColorOfBars)
  162.  
  163. plotshape(M1U, "Marker 1 Up", color=MyGreenMedium, style=shape.triangleup, location=location.top, size=size.tiny, text="1")
  164. plotshape(M1D, "Marker 1 Dn", color=MyRedMedium, style=shape.triangledown, location=location.top, size=size.tiny, text="1")
  165. plotshape(M2U, "Marker 2 Up", color=MyGreenMedium, style=shape.triangleup, location=location.top, size=size.tiny, text="2")
  166. plotshape(M2D, "Marker 2 Dn", color=MyRedMedium, style=shape.triangledown, location=location.top, size=size.tiny, text="2")
  167. plotshape(M3U, "Marker 3 Up", color=MyGreenMedium, style=shape.triangleup, location=location.top, size=size.tiny, text="3")
  168. plotshape(M3D, "Marker 3 Dn", color=MyRedMedium, style=shape.triangledown, location=location.top, size=size.tiny, text="3")
  169. plotshape(M4U, "Marker 4 Up", color=MyGreenMedium, style=shape.triangleup, location=location.top, size=size.tiny, text="4")
  170. plotshape(M4D, "Marker 4 Dn", color=MyRedMedium, style=shape.triangledown, location=location.top, size=size.tiny, text="4")
  171. plotshape(M5U, "Marker 5 Up", color=MyGreenMedium, style=shape.triangleup, location=location.top, size=size.tiny, text="5")
  172. plotshape(M5D, "Marker 5 Dn", color=MyRedMedium, style=shape.triangledown, location=location.top, size=size.tiny, text="5")
  173.  
  174. // —————————— Alert
  175. alertcondition(M1U or M1D or M2U or M2D or M3U or M3D or M4U or M4D or M5U or M5D, title="Ord V: Configured Markers", message="OrdV Marker")
  176.  
  177.  
Add Comment
Please, Sign In to add comment