I am having a problem with the plotting of the zigzag volume bubbles. It seems to be overplotting the upgoing and downgoing wave volumes in certain instances, but not always. I o not understand why. I would appreciate any suggestions to the problem. Thanks. See enclosed screen capture of the issue.
See if this revised volume bubbles at reversals helps. It shows an optional debug_volume bubbles with the current bar volume and cumulative reversal volume. These should then correspond to the cumulative volume at the reversal point's bubbles.
Ruby:# ZigZag High Low Stats # tomsk # 11.16.2019 # V1.0 - 11.16.2019 - tomsk - Initial release of ZigZag High Low Stats # Extracted idea from RDMercer's post #369 of a variant of a massive # Zig Zag High Low Supply Demand study that comprises many different # components # # https://usethinkscript.com/threads/trend-reversal-indicator-with-signals-for-thinkorswim.183/page-19#post-369 # # I heavily modified, cleaned up and extracted some interesting Zig Zag statistical information resulting in this study called Zig Zag High # Low Stats. It displays the following information represented via bubbles at each of the Zig zag turning points # # Label for Confirmed/Unconfirmed Status of Current Zigzag # Price Change between Zigzags # Price at Zigzag High/Low # Bar Count between Zigzags # Volume at Zigzag Reversals input showBubblesChange = no; # Price Change between Zigzags input showBubblesPrice = no; # Price at Zigzag High/Low input showBubblesBarCount = no; # Bar Count between Zigzags input showBubblesVolume = no; # Volume at Zigzag Reversals input BubbleOffset = .0005; input PercentAmount = .01; input RevAmount = .05; input ATRreversal = 3.0; input ATRlength = 5; def zz = ZigZagHighLow("price h" = high, "price l" = low, "percentage reversal" = PercentAmount, "absolute reversal" = RevAmount, "atr length" = ATRlength, "atr reversal" = ATRreversal); def ReversalAmount = if (close * PercentAmount / 100) > Max(RevAmount < ATRreversal * reference ATR(ATRlength), RevAmount) then (close * PercentAmount / 100) else if RevAmount < ATRreversal * reference ATR(ATRlength) then ATRreversal * reference ATR(ATRlength) else RevAmount; # Zig Zag Specific Data def zzSave = if !IsNaN(zz) then zz else GetValue(zzSave, 1); def chg = (if zzSave == high then high else low) - GetValue(zzSave, 1); def isUp = chg >= 0; def isConf = AbsValue(chg) >= ReversalAmount or (IsNaN(GetValue(zz, 1)) and GetValue(isConf, 1)); # Price Change Specific Data def xxHigh = if zzSave == high then high else xxHigh[1]; def chgHigh = high - xxHigh[1]; def xxLow = if zzSave == low then low else xxLow[1]; def chgLow = low - xxLow[1]; # Bar Count Specific Data def zzCount = if zzSave[1] != zzSave then 1 else if zzSave[1] == zzSave then zzCount[1] + 1 else 0; def zzCountHiLo = if zzCountHiLo[1] == 0 and (zzSave == high or zzSave == low) then 1 else if zzSave == high or zzSave == low then zzCountHiLo[1] + 1 else zzCountHiLo[1]; def zzHiLo = if zzSave == high or zzSave == low then zzCountHiLo else zzCountHiLo + 1; def zzCountHigh = if zzSave == high then zzCount[1] else Double.NaN; def zzCountLow = if zzSave == low then zzCount[1] else Double.NaN; # Volume Specific Data def vol = if BarNumber() == 0 then 0 else volume + vol[1]; def vol1 = if BarNumber() == 1 then volume else vol1[1]; def xxVol = if zzSave == high or zzSave == low then TotalSum(volume) else xxVol[1]; def chgVol = if xxVol - xxVol[1] + vol1 == vol then vol else xxVol - xxVol[1]; # Zigzag Status Label AddLabel(BarNumber() != 1, (if isConf then "Confirmed " else "Unconfirmed ") + "ZigZag: " + chg + " ATRrev " + Round(reference ATR(ATRlength) * ATRreversal, 2) + " RevAmt " + Round(ReversalAmount, 2), if !isConf then Color.DARK_ORANGE else if isUp then Color.GREEN else Color.RED); # Zig Zag Plot plot zzp = if isUp <= 1 then zz else Double.NaN; zzp.AssignValueColor(if isUp then Color.GREEN else if !isUp then Color.RED else Color.DARK_ORANGE); zzp.SetStyle(Curve.FIRM); zzp.EnableApproximation(); zzp.HideBubble(); # Bubbles # Price Change between Zigzags AddChartBubble(showBubblesChange and !IsNaN(zz) and BarNumber() != 1, if isUp then high * (1 + BubbleOffset) else low * (1 - BubbleOffset), "$" + Round(chg, 2), if isUp and chgHigh > 0 then Color.GREEN else if isUp and chgHigh < 0 then Color.RED else if isUp then Color.YELLOW else if !isUp and chgLow > 0 then Color.GREEN else if !isUp and chgLow < 0 then Color.RED else Color.YELLOW, isUp); # Price at Zigzag High/Low AddChartBubble(showBubblesPrice and !IsNaN(zz) and BarNumber() != 1, if isUp then high * (1 + BubbleOffset) else low * (1 - BubbleOffset), if isUp then "$" + high else "$" + low, if isUp and chgHigh > 0 then Color.GREEN else if isUp and chgHigh < 0 then Color.RED else if isUp then Color.YELLOW else if !isUp and chgLow > 0 then Color.GREEN else if !isUp and chgLow < 0 then Color.RED else Color.YELLOW, isUp); # Bar Count between Zigzags AddChartBubble(showBubblesBarCount and !IsNaN(zz) and BarNumber() != 1, if isUp then high * (1 + BubbleOffset) else low * (1 - BubbleOffset), if zzSave == high then zzCountHigh else zzCountLow, if isUp and chgHigh > 0 then Color.GREEN else if isUp and chgHigh < 0 then Color.RED else if isUp then Color.YELLOW else if !isUp and chgLow > 0 then Color.GREEN else if !isUp and chgLow < 0 then Color.RED else Color.YELLOW, if isUp then yes else no); #Revised Volume at Reversals Bubbles------------------------------------------------------ # Volume at Zigzag Reversals def bn = BarNumber(); def z = if !IsNaN(zz) then 0 else z[1] + 1; def v = if z == 1 then volume else v[1] + volume; input debug_volume = yes; AddChartBubble(debug_volume and v, if isUp or !IsNaN(zz) == low then low else high, volume + "\n" + v, Color.WHITE, if isUp then no else yes); AddChartBubble(showBubblesVolume and !IsNaN(zz) and BarNumber() != 1, if isUp then high * (1 + BubbleOffset) else low * (1 - BubbleOffset), v, if isUp and chgHigh > 0 then Color.GREEN else if isUp and chgHigh < 0 then Color.RED else if isUp then Color.YELLOW else if !isUp and chgLow > 0 then Color.GREEN else if !isUp and chgLow < 0 then Color.RED else Color.YELLOW, if isUp then yes else no); #------------------------------------------------------------------------------------------- # End ZigZag High Low Stats