@SleepyZ Would you kindly assist in making a few tweaks to this study?
1. The candles will only change color after a follow through day. For example, if today the signal changed from bullish to bearish, the candlestick color would not change from green to red unless tomorrow's signal also remained bearish on a closing basis. At that time (tomorrow after the close), the candlestick would change from green to red and also the red down arrow would plot tomorrow after the close. The same would happen when the signal changes from bearish to bullish.
2. Option to replace the up and down arrows with bubbles that say "bullish" and "bearish".
My attempts to make these tweaks have resulted in either all the candles painting gray or the bubbles not plotting at all so I am obviously doing something wrong. Thank you for any assistance!
# 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/...-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.DARK_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);
# Volume at Zigzag Reversals
AddChartBubble(showBubblesVolume and !IsNaN(zz) and BarNumber() != 1, if isUp then high * (1 + BubbleOffset) else low * (1 - BubbleOffset), chgVol, 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);
#Arrows
def zzL = if !IsNaN(zz) and !isUp then low else GetValue(zzL, 1);
def zzH = if !IsNaN(zz) and isUp then high else GetValue(zzH, 1);
def dir = CompoundValue(1, if zzL != zzL[1] or low == zzL[1] and low == zzSave then 1 else if zzH != zzH[1] or high == zzH[1] and high == zzSave then -1 else dir[1], 0);
def signal = CompoundValue(1, if dir > 0 and low > zzL then if signal[1] <= 0 then 1 else signal[1] else if dir < 0 and high < zzH then if signal[1] >= 0 then -1 else signal[1] else signal[1], 0);
#Count to limit plot of arrows-------------------------------------------------
input Count = 2;
def cond = if signal > 0 and signal[1] <= 0 or
signal < 0 and signal[1] >= 0
then 1
else 0 ;
def dataCount = CompoundValue(1, if cond then dataCount[1] + 1 else dataCount[1], 0);
def limitplot = HighestAll(dataCount) - dataCount <= Count - 1;
#-------------------------------------------------------------------------------
input showarrows = yes;
plot U1 = showarrows and signal > 0 and signal[1] <= 0 and limitplot;
U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U1.SetDefaultColor(Color.GREEN);
U1.SetLineWeight(4);
plot D1 = showarrows and signal < 0 and signal[1] >= 0 and limitplot;
D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D1.SetDefaultColor(Color.RED);
D1.SetLineWeight(4);
#Color Candles based upon Last X Arrows------------------------------------------
input price_color = yes;
def colorup = if U1 then 1 else if colorup[1] and !D1 then 1 else 0;
def colordn = if D1 then 1 else if colordn[1] and !U1 then 1 else 0;
AssignPriceColor(if !price_color then Color.CURRENT
else if colorup == 1 then Color.GREEN
else if colordn == 1 then Color.RED
else Color.GRAY);
#--------------------------------------------------------------------------------