Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- //@author=LucF
- // Ord Volume [LucF]
- // v1.2, 2019.07.17 15:25 — Luc
- // Shows average volume for each price wave (a Tim Ord concept).
- // It's basically Weis Wave with average volume instead of cumulative volume, plus a few goodies.
- // Credits to LazyBear for original Weis Wave code (a David Weis concept).
- // Docs: https://www.tradingview.com/script/lhda3xOg-Ord-Volume-LucF/
- study("Ord Volume [LucF]", shorttitle="Ord Volume4")
- // —————————— Colors
- 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)
- 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)
- MyOrangeRaw = color.new(#FF9800,0), MyOrangeMedium = color.new(#FF9800,30), MyOrangeSemiDark = color.new(#FF9800,50), MyOrangeDark = color.new(#FF9800,60)
- Invisible = color.new(color.white,100), MyBlack = color.new(color.black,0)
- // —————————— Inputs
- TD1 = "Both"
- TD2 = "Longs Only"
- TD3 = "Shorts Only"
- ColorAvg = input(true, "Distinguish rising/falling states")
- ColorBars = input(false, "Color chart bars with rising/falling states & bars")
- ShowAvgEma = input(false, "EMA of averages")
- ShowLastAvg = input(false, "Last Wave's Ending Average")
- ShowLastHighestAvg = input(false, "Last Wave's Highest Average")
- TrendReversalLength = input(2, "Trend reversal length", minval=2)
- PriceSource = input(close, "Price Source for trend detection")
- TradeDirection = input(TD1, "Trade Direction", options=[TD1, TD2, TD3])
- ShowMarker1 = input(false, "Marker 1: Breach of previous wave's highest Average")
- ShowMarker2 = input(false, "Marker 2: n Consecutive increasing bars in same wave")
- Marker2Bars = input(3, "... n", minval=2)
- ShowMarker3 = input(false, "Marker 3: Last wave's volume was <% than the previous one.")
- Marker3Pct = input(50.0, "... % Trheshold", minval=1.0)
- ShowMarker4 = input(false, "Marker 4: Average volume crosses its EMA.")
- ShowMarker5 = input(true, "Marker 5: Breach of previous wave's highest Average on smaller avg")
- ShortsOnly = TradeDirection==TD3
- LongsOnly = TradeDirection==TD2
- // —————————— Detect Price Waves
- var Trend = 0
- var Wave = 0
- var WaveBars = 0
- var CumVolume = volume
- UpOrDn = PriceSource>PriceSource[1] ? 1 : PriceSource<PriceSource[1] ? -1 : 0 // Price movement Up->1, Dn->-1, No change->0
- Trend := (UpOrDn != 0) and (UpOrDn != UpOrDn[1]) ? UpOrDn : Trend // Trend changes when price reverses direction.
- ReversalTrend = rising(PriceSource, TrendReversalLength) or falling(PriceSource, TrendReversalLength) // Detect reversal condition.
- Wave := (Trend != Wave and ReversalTrend) ? Trend : Wave // Stay in wave until a counter trend of trendDetectionLength occurs.
- // —————————— States
- BullWave = Wave==1
- BearWave = Wave==-1
- SameWave = Wave==nz(Wave[1])
- // —————————— Build average volume for current wave.
- CumVolume := SameWave ? CumVolume+volume : volume
- WaveBars := SameWave ? WaveBars+1 : 1
- AverageWaveVolume = CumVolume/WaveBars
- AverageWaveVolumeMA = ema( AverageWaveVolume,20)
- // ————— Keep track of last wave's hi/lo price.
- // ————— Consecutive increasing average volume bars in same wave.
- var IncreasingBars = 0
- IncreasingBars := SameWave ? AverageWaveVolume>nz(AverageWaveVolume[1])? IncreasingBars+1 : 0 : 0
- // ————— Keep track of last wave's maximum average.
- var CurrentMaxAvg = 0.0
- CurrentMaxAvg := SameWave ? max(AverageWaveVolume, CurrentMaxAvg) : AverageWaveVolume
- // ————— Keep track of last wave ending averages.
- var LastMaxAvg = CurrentMaxAvg
- var LastAvg1 = 0.0
- var LastAvg2 = 0.0
- var LastAvg3 = 0.0
- // ————— Keep track of last wave his/los.
- var LastHi = 0.0
- var LastLo = 0.0
- LastHi := SameWave ? max(PriceSource, LastHi) : PriceSource
- LastLo := SameWave ? min(PriceSource, LastLo) : PriceSource
- var LastHi1 = 0.0
- var LastLo1 = 0.0
- var LastHi2 = 0.0
- var LastLo2 = 0.0
- var LastHi3 = 0.0
- var LastLo3 = 0.0
- // ————— Wave Strength
- var PriceMove = 0.0
- var WaveStrength = 0.0
- // Update numbers when changing waves.
- if not SameWave
- // Last 3 Averages.
- LastAvg3 := LastAvg2
- LastAvg2 := LastAvg1
- LastAvg1 := nz(AverageWaveVolume[1])
- LastMaxAvg := CurrentMaxAvg[2]
- // Last 3 His/Los.
- LastHi3 := LastHi2
- LastHi2 := LastHi1
- LastHi1 := nz(LastHi[1])
- LastLo3 := LastLo2
- LastLo2 := LastLo1
- LastLo1 := nz(LastLo[1])
- // Wave strength
- PriceMove := abs(LastHi1-LastLo1)/(BullWave[1]?LastLo1:LastHi1)
- WaveStrength := PriceMove*CumVolume[1]
- // plot(WaveStrength)
- // plotchar(PriceMove,"PriceMove","")
- // plotchar(CumVolume[1],"CumVolume[1]","")
- // plotchar(WaveStrength, "WaveStrength","")
- // plotchar(LastHi3,"LastHi3","")
- // plotchar(LastHi2,"LastHi2","")
- // plotchar(LastHi1,"LastHi1","")
- // plotchar(LastHi,"LastHi","")
- // plotchar(LastLo3,"LastLo3","")
- // plotchar(LastLo2,"LastLo2","")
- // plotchar(LastLo1,"LastLo1","")
- // plotchar(LastLo,"LastLo","")
- // —————————— Markers
- // ————— Marker 1: Last wave's maximum average surpassed
- M1U = ShowMarker1 and not ShortsOnly and BullWave and close>open and (crossover(AverageWaveVolume, LastMaxAvg) or (not SameWave and AverageWaveVolume>CurrentMaxAvg[1]))
- M1D = ShowMarker1 and not LongsOnly and BearWave and close<open and (crossover(AverageWaveVolume, LastMaxAvg) or (not SameWave and AverageWaveVolume>CurrentMaxAvg[1]))
- // ————— Marker 2: consecutive increasing bars in same wave
- M2U = ShowMarker2 and not ShortsOnly and BullWave and IncreasingBars==Marker2Bars
- M2D = ShowMarker2 and not LongsOnly and BearWave and IncreasingBars==Marker2Bars
- // ————— Marker 3: Last wave's volume was <% than the previous one.
- M3U = ShowMarker3 and not ShortsOnly and BullWave and not SameWave and (LastAvg1<LastAvg2*Marker3Pct/100 or LastAvg1<LastAvg3*Marker3Pct/100) and LastLo1<LastLo3
- M3D = ShowMarker3 and not LongsOnly and BearWave and not SameWave and (LastAvg1<LastAvg2*Marker3Pct/100 or LastAvg1<LastAvg3*Marker3Pct/100) and LastHi1>LastHi3
- // ————— Marker 4: Avg volume crosses its MA.
- M4U = ShowMarker4 and not ShortsOnly and BullWave and crossover(AverageWaveVolume, AverageWaveVolumeMA)
- M4D = ShowMarker4 and not LongsOnly and BearWave and crossover(AverageWaveVolume, AverageWaveVolumeMA)
- // ————— Marker 5: Avg volume crosses its MA.
- M5U = ShowMarker5 and not ShortsOnly and BullWave and (crossover(AverageWaveVolume, LastMaxAvg) or (not SameWave and AverageWaveVolume>CurrentMaxAvg[1])) and LastMaxAvg < LastAvg3
- M5D = ShowMarker5 and not LongsOnly and BearWave and (crossover(AverageWaveVolume, LastMaxAvg) or (not SameWave and AverageWaveVolume>CurrentMaxAvg[1])) and LastMaxAvg < LastAvg3
- // plot(LastAvg3)
- // plotchar(LastAvg1,"LastAvg","")
- // plotchar(LastAvg2,"LastAvg2","")
- // plotchar(LastAvg2*Marker3Pct/100,"LastAvg2*Marker3Pct/100","")
- // plotchar(LastAvg3,"LastAvg3","")
- // plotchar(LastAvg3*Marker3Pct/100,"LastAvg3*Marker3Pct/100","")
- AvgUp = rising(AverageWaveVolume,1)
- // plotchar(AvgUp and close>open and BullWave and ColorBars, "Rising", "+")
- // —————————— Plots
- ColorOfAvg = BullWave? AvgUp and ColorAvg? MyGreenDark:MyGreenDarkDark: AvgUp and ColorAvg? MyRedDark:MyRedDarkDark
- ColorOfBars = ColorBars? BullWave? AvgUp and close>open? MyGreenRaw:na : AvgUp and close<open ? MyRedRaw:na : na
- // ColorOfBars = ColorBars? BullWave? rising(AverageWaveVolume,1) and close>open? MyGreenRaw:na : rising(AverageWaveVolume,1) and close<open ? MyRedRaw:na : na
- // ColorOfAvg = BullWave? rising(AverageWaveVolume,1) and ColorAvg? MyGreenDark:MyGreenDarkDark: rising(AverageWaveVolume,1) and ColorAvg? MyRedDark:MyRedDarkDark
- // ColorOfBars = ColorBars? BullWave? rising(AverageWaveVolume,1) and close>open? MyGreenRaw:na : rising(AverageWaveVolume,1) and close<open ? MyRedRaw:na : na
- // ColorOfBars = ColorBars? BullWave? rising(AverageWaveVolume,1) and close>open ? MyGreenRaw:MyOrangeRaw: rising(AverageWaveVolume,1) and close<open ? MyRedRaw:MyOrangeRaw : na
- // ColorOfBars = ColorBars? BullWave? rising(AverageWaveVolume,1) ? MyGreenRaw:MyGreenMedium: rising(AverageWaveVolume,1) ? MyRedRaw:MyRedMedium : na
- plot(AverageWaveVolume, "Average Volume", color=ColorOfAvg, linewidth=1, style=plot.style_area)
- plot(ShowAvgEma? AverageWaveVolumeMA:na, "EMA of Average Volume", color=MyOrangeMedium, linewidth=1)
- plot(ShowLastAvg ? LastAvg1:na, "Last Wave Average", color=BullWave? MyRedMedium:MyGreenMedium, linewidth=2, style=plot.style_circles)
- plot(ShowLastHighestAvg ? LastMaxAvg:na, "Last wave Maximum Average", color=not SameWave? Invisible: BullWave? MyRedMedium:MyGreenMedium, linewidth=2, style=plot.style_line)
- barcolor(color=ColorOfBars)
- plotshape(M1U, "Marker 1 Up", color=MyGreenMedium, style=shape.triangleup, location=location.top, size=size.tiny, text="1")
- plotshape(M1D, "Marker 1 Dn", color=MyRedMedium, style=shape.triangledown, location=location.top, size=size.tiny, text="1")
- plotshape(M2U, "Marker 2 Up", color=MyGreenMedium, style=shape.triangleup, location=location.top, size=size.tiny, text="2")
- plotshape(M2D, "Marker 2 Dn", color=MyRedMedium, style=shape.triangledown, location=location.top, size=size.tiny, text="2")
- plotshape(M3U, "Marker 3 Up", color=MyGreenMedium, style=shape.triangleup, location=location.top, size=size.tiny, text="3")
- plotshape(M3D, "Marker 3 Dn", color=MyRedMedium, style=shape.triangledown, location=location.top, size=size.tiny, text="3")
- plotshape(M4U, "Marker 4 Up", color=MyGreenMedium, style=shape.triangleup, location=location.top, size=size.tiny, text="4")
- plotshape(M4D, "Marker 4 Dn", color=MyRedMedium, style=shape.triangledown, location=location.top, size=size.tiny, text="4")
- plotshape(M5U, "Marker 5 Up", color=MyGreenMedium, style=shape.triangleup, location=location.top, size=size.tiny, text="5")
- plotshape(M5D, "Marker 5 Dn", color=MyRedMedium, style=shape.triangledown, location=location.top, size=size.tiny, text="5")
- // —————————— Alert
- 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")
Add Comment
Please, Sign In to add comment