Repaints ZigZag High Low Stats for ThinkorSwim

Repaints
Code is added to make the last bubble optional. It is placed to the right of the last high/low and can be moved left/right by the bubblemover input. Also, added is a '\n" in both the bubble codes to break the bubble display into 2 lines, which might prevent overlapping current candles. It is easy to remove if you do not wish to use it.

Nice modifications that you made.
Great job with the modification!!! fwiw, for /ES you need to change the tickvalue variable= 12.5 and the margin = 12600
 
Hi, I hope everyone is having an amazing day. I have been trying to get up arrows and down arrows on the zigzag percentage indicator but for some reason when I implement the code that I have placed down below it does not plot the arrows on the chart. This indicator is also a changing indicator which means it may go from "confirmed" to "unconfirmed" in the movement of a candle. What I'm trying to do is have a down arrow appear only on the FIRST "confirmed" red and a up arrow on the FIRST "confirmed" green. I'm confused as to why the arrows are not appearing on the TOS forex chart because what's weird is that this works on stocks but when I move it to forex it does not display the arrows. If anyone knows how to fix it I would greatly appreciate it !!
Ruby:
input price = close;
input reversalAmount = 0.40;
input showBubbles = no;
input showLabel = yes;

Assert(reversalAmount > 0, "'reversal amount' should be positive: " + reversalAmount);

plot "ZZ%" = reference ZigZagHighLow(price, price, reversalAmount, 0, 1, 0);

def zzSave = if !IsNaN("ZZ%") then price else GetValue(zzSave, 1);
def chg = (price / GetValue(zzSave, 1) - 1) * 100;
def isUp = chg >= 0;
def isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue("ZZ%", 1)) and GetValue(isConf, 1));

"ZZ%".EnableApproximation();
"ZZ%".DefineColor("Up Trend", Color.UPTICK);
"ZZ%".DefineColor("Down Trend", Color.DOWNTICK);
"ZZ%".DefineColor("Undefined", Color.DARK_ORANGE);
"ZZ%".AssignValueColor(if !isConf then "ZZ%".Color("Undefined") else if isUp then "ZZ%".Color("Up Trend") else "ZZ%".Color("Down Trend"));

DefineGlobalColor("Unconfirmed", Color.DARK_ORANGE);
DefineGlobalColor("Up", Color.UPTICK);
DefineGlobalColor("Down", Color.DOWNTICK);

def barNumber = BarNumber();

AddChartBubble(showBubbles and !IsNaN("ZZ%") and barNumber != 1, price, Round(chg) + "%", if !isConf then GlobalColor("Unconfirmed") else if isUp then GlobalColor("Up") else GlobalColor("Down"), isUp);
AddLabel(showLabel and barNumber != 1, (if isConf then "Confirmed " else "Unconfirmed ") + "ZigZag: " + Round(chg) + "%", if !isConf then GlobalColor("Unconfirmed") else if isUp then GlobalColor("Up") else GlobalColor("Down"));


def Buy = if chg crosses above 0 and isConf then 1 else 0;
def Sell = if chg crosses below 0 and isConf then 1 else 0;


plot ArrowUp = Buy;
ArrowUp.SetDefaultColor(Color.GREEN);
ArrowUp.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);


plot ArrowDn = Sell;
ArrowDn.SetDefaultColor(Color.RED);
ArrowDn.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_DOWN);
 
Last edited by a moderator:
Hi, I hope everyone is having an amazing day. I have been trying to get up arrows and down arrows on the zigzag percentage indicator but for some reason when I implement the code that I have placed down below it does not plot the arrows on the chart. This indicator is also a changing indicator which means it may go from "confirmed" to "unconfirmed" in the movement of a candle. What I'm trying to do is have a down arrow appear only on the FIRST "confirmed" red and a up arrow on the FIRST "confirmed" green. I'm confused as to why the arrows are not appearing on the TOS forex chart because what's weird is that this works on stocks but when I move it to forex it does not display the arrows. If anyone knows how to fix it I would greatly appreciate it !!



input price = close;
input reversalAmount = 0.40;
input showBubbles = no;
input showLabel = yes;

Assert(reversalAmount > 0, "'reversal amount' should be positive: " + reversalAmount);

plot "ZZ%" = reference ZigZagHighLow(price, price, reversalAmount, 0, 1, 0);

def zzSave = if !IsNaN("ZZ%") then price else GetValue(zzSave, 1);
def chg = (price / GetValue(zzSave, 1) - 1) * 100;
def isUp = chg >= 0;
def isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue("ZZ%", 1)) and GetValue(isConf, 1));

"ZZ%".EnableApproximation();
"ZZ%".DefineColor("Up Trend", Color.UPTICK);
"ZZ%".DefineColor("Down Trend", Color.DOWNTICK);
"ZZ%".DefineColor("Undefined", Color.DARK_ORANGE);
"ZZ%".AssignValueColor(if !isConf then "ZZ%".Color("Undefined") else if isUp then "ZZ%".Color("Up Trend") else "ZZ%".Color("Down Trend"));

DefineGlobalColor("Unconfirmed", Color.DARK_ORANGE);
DefineGlobalColor("Up", Color.UPTICK);
DefineGlobalColor("Down", Color.DOWNTICK);

def barNumber = BarNumber();

AddChartBubble(showBubbles and !IsNaN("ZZ%") and barNumber != 1, price, Round(chg) + "%", if !isConf then GlobalColor("Unconfirmed") else if isUp then GlobalColor("Up") else GlobalColor("Down"), isUp);
AddLabel(showLabel and barNumber != 1, (if isConf then "Confirmed " else "Unconfirmed ") + "ZigZag: " + Round(chg) + "%", if !isConf then GlobalColor("Unconfirmed") else if isUp then GlobalColor("Up") else GlobalColor("Down"));


def Buy = if chg crosses above 0 and isConf then 1 else 0;
def Sell = if chg crosses below 0 and isConf then 1 else 0;


plot ArrowUp = Buy;
ArrowUp.SetDefaultColor(Color.GREEN);
ArrowUp.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_UP);


plot ArrowDn = Sell;
ArrowDn.SetDefaultColor(Color.RED);
ArrowDn.setpaintingStrategy(paintingStrategy.BOOLEAN_ARROW_DOWN);
It is difficult to have a cross and another event, in this case isconf, to both occur at the same time. Changing chg to greater/less than zero first as true, then allows isconf to finally plot an arrow when it is true. As this results at times in many arrows in the same direction, the code in arrowup/arrowdn will help only plot one arrow in each respective direction.

It is important to remember that this indicator repaints. So even if an arrow plots only when confirmed, it can disappear if the price moves such that it becomes unconfirmed.

Capture.jpg
Ruby:
input price = close;
input reversalAmount = 0.40;
input showBubbles = yes;
input showLabel = yes;

Assert(reversalAmount > 0, "'reversal amount' should be positive: " + reversalAmount);

plot "ZZ%" = reference ZigZagHighLow(price, price, reversalAmount, 0, 1, 0);

def zzSave = if !IsNaN("ZZ%") then price else GetValue(zzSave, 1);
def chg = (price / GetValue(zzSave, 1) - 1) * 100;
def isUp = chg >= 0;
def isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue("ZZ%", 1)) and GetValue(isConf, 1));

"ZZ%".EnableApproximation();
"ZZ%".DefineColor("Up Trend", Color.UPTICK);
"ZZ%".DefineColor("Down Trend", Color.DOWNTICK);
"ZZ%".DefineColor("Undefined", Color.DARK_ORANGE);
"ZZ%".AssignValueColor(if !isConf then "ZZ%".Color("Undefined") else if isUp then "ZZ%".Color("Up Trend") else "ZZ%".Color("Down Trend"));

DefineGlobalColor("Unconfirmed", Color.DARK_ORANGE);
DefineGlobalColor("Up", Color.UPTICK);
DefineGlobalColor("Down", Color.DOWNTICK);

def barNumber = BarNumber();

AddChartBubble(showBubbles and !IsNaN("ZZ%") and barNumber != 1, price, Round(chg) + "%", if !isConf then GlobalColor("Unconfirmed") else if isUp then GlobalColor("Up") else GlobalColor("Down"), isUp);
AddLabel(showLabel and barNumber != 1, (if isConf then "Confirmed " else "Unconfirmed ") + "ZigZag: " + Round(chg) + "%", if !isConf then GlobalColor("Unconfirmed") else if isUp then GlobalColor("Up") else GlobalColor("Down"));


def Buy  = if chg > 0 and isConf then 1 else 0;
def Sell = if chg < 0 and isConf then 1 else 0;


plot ArrowUp = !Buy[1] and Buy;
ArrowUp.SetDefaultColor(Color.GREEN);
ArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);


plot ArrowDn = !Sell[1] and Sell;
ArrowDn.SetDefaultColor(Color.RED);
ArrowDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
 
Great ZigZag Indicator. Found here: https://usethinkscript.com/threads/zigzag-high-low-stats-for-thinkorswim.1073/page-2#post-57956

Has anyone created a scanner for this one?
Ruby:
## START CODE
## ZigZagSign TOMO modification, v0.2 written by Linus @Thinkscripter Lounge adapted from Thinkorswim ZigZagSign Script

input price             = close;
input priceH            = high;    # swing high
input priceL            = low;     # swing low
input ATRreversalfactor = 3.2;
def ATR                 = reference ATR(length = 5);
def reversalAmount      = ATRreversalfactor * ATR;
input showlines         = yes;
input displace          = 1;
input showBubbleschange = yes;


def barNumber = BarNumber();
def barCount = HighestAll(If(IsNaN(price), 0, barNumber));

rec state = {default init, undefined, uptrend, downtrend};
rec minMaxPrice;

if (GetValue(state, 1) == GetValue(state.init, 0)) {
    minMaxPrice = price;
    state = state.undefined;
} else if (GetValue(state, 1) == GetValue(state.undefined, 0)) {
    if (price <= GetValue(minMaxPrice, 1) - reversalAmount) {
        state = state.downtrend;
        minMaxPrice = priceL;
    } else if (price >= GetValue(minMaxPrice, 1) + reversalAmount) {
        state = state.uptrend;
        minMaxPrice = priceH;
    } else {
        state = state.undefined;
        minMaxPrice = GetValue(minMaxPrice, 1);
    }
} else if (GetValue(state, 1) == GetValue(state.uptrend, 0)) {
    if (price <= GetValue(minMaxPrice, 1) - reversalAmount) {
        state = state.downtrend;
        minMaxPrice = priceL;
    } else {
        state = state.uptrend;
        minMaxPrice = Max(priceH, GetValue(minMaxPrice, 1));
    }
} else {
    if (price >= GetValue(minMaxPrice, 1) + reversalAmount) {
        state = state.uptrend;
        minMaxPrice = priceH;
    } else {
        state = state.downtrend;
        minMaxPrice = Min(priceL, GetValue(minMaxPrice, 1));
    }
}

def isCalculated = GetValue(state, 0) != GetValue(state, 1) and barNumber >= 1;
def futureDepth =  barCount - barNumber;
def tmpLastPeriodBar;
if (isCalculated) {
    if (futureDepth >= 1 and GetValue(state, 0) == GetValue(state, -1)) {
        tmpLastPeriodBar = fold lastPeriodBarI = 2 to futureDepth + 1 with lastPeriodBarAcc = 1
            while lastPeriodBarAcc > 0
            do if (GetValue(state, 0) != GetValue(state, -lastPeriodBarI))
                then -lastPeriodBarAcc
                else lastPeriodBarAcc + 1;
    } else {
        tmpLastPeriodBar = 0;
    }
} else {
    tmpLastPeriodBar = Double.NaN;
}

def lastPeriodBar = if (!IsNaN(tmpLastPeriodBar)) then -AbsValue(tmpLastPeriodBar) else -futureDepth;

rec currentPriceLevel;
rec currentPoints;
if (state == state.uptrend and isCalculated) {
    currentPriceLevel =
        fold barWithMaxOnPeriodI = lastPeriodBar to 1 with barWithMaxOnPeriodAcc = minMaxPrice
            do Max(barWithMaxOnPeriodAcc, GetValue(minMaxPrice, barWithMaxOnPeriodI));
    currentPoints =
        fold maxPointOnPeriodI = lastPeriodBar to 1 with maxPointOnPeriodAcc = Double.NaN
            while IsNaN(maxPointOnPeriodAcc)
            do if (GetValue(priceH, maxPointOnPeriodI) == currentPriceLevel)
                then maxPointOnPeriodI
                else maxPointOnPeriodAcc;
} else if (state == state.downtrend and isCalculated) {
    currentPriceLevel =
        fold barWithMinOnPeriodI = lastPeriodBar to 1 with barWithMinOnPeriodAcc = minMaxPrice
            do Min(barWithMinOnPeriodAcc, GetValue(minMaxPrice, barWithMinOnPeriodI));
    currentPoints =
        fold minPointOnPeriodI = lastPeriodBar to 1 with minPointOnPeriodAcc = Double.NaN
            while IsNaN(minPointOnPeriodAcc)
            do if (GetValue(priceL, minPointOnPeriodI) == currentPriceLevel)
                then minPointOnPeriodI
                else minPointOnPeriodAcc;
} else if (!isCalculated and (state == state.uptrend or state == state.downtrend)) {
    currentPriceLevel = GetValue(currentPriceLevel, 1);
    currentPoints = GetValue(currentPoints, 1) + 1;
} else {
    currentPoints = 1;
    currentPriceLevel = GetValue(price, currentPoints);
}

plot "ZZ$" = if (barNumber == barCount or barNumber == 1) then if state == state.uptrend then priceH else priceL else if (currentPoints == 0) then currentPriceLevel else Double.NaN;

rec zzSave =  if !IsNaN("ZZ$" ) then if (barNumber == barCount or barNumber == 1) then if IsNaN(barNumber[-1]) and  state == state.uptrend then priceH else priceL else currentPriceLevel else GetValue(zzSave, 1);

def chg = (if barNumber == barCount and currentPoints < 0 then priceH else if barNumber == barCount and currentPoints > 0 then priceL else currentPriceLevel) - GetValue(zzSave, 1);

def isUp = chg >= 0;

#Higher/Lower/Equal High, Higher/Lower/Equal Low
def xxhigh = if zzSave == priceH then Round(high, 2) else Round(xxhigh[1], 2);
def chghigh = Round(Round(high, 2) - Round(xxhigh[1], 2), 2);
def xxlow = if zzSave == priceL then Round(low, 2) else Round(xxlow[1], 2);
def chglow = Round(Round(low, 2) - Round(xxlow[1], 2), 2);


rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue("ZZ$", 1)) and GetValue(isConf, 1));

"ZZ$".EnableApproximation();
"ZZ$".DefineColor("Up Trend", Color.UPTICK);
"ZZ$".DefineColor("Down Trend", Color.DOWNTICK);
"ZZ$".DefineColor("Undefined", Color.WHITE);
"ZZ$".AssignValueColor(if !isConf then "ZZ$".Color("Undefined" ) else if isUp then "ZZ$".Color("Up Trend" ) else "ZZ$".Color("Down Trend" ));

DefineGlobalColor("Unconfirmed", Color.WHITE);
DefineGlobalColor("Up", Color.UPTICK);
DefineGlobalColor("Down", Color.DOWNTICK);

AddChartBubble(showBubbleschange and !IsNaN("ZZ$" ) and barNumber != 1, if isUp then high else low , Round(chg, 2) , if barCount == barNumber or !isConf then GlobalColor("Unconfirmed" ) else if isUp then GlobalColor("Up" ) else GlobalColor("Down" ), isUp);

## END CODE
 
Last edited by a moderator:
Great ZigZag Indicator. Found here: https://usethinkscript.com/threads/zigzag-high-low-stats-for-thinkorswim.1073/page-2#post-57956

Has anyone created a scanner for this one?
Ruby:
## START CODE
## ZigZagSign TOMO modification, v0.2 written by Linus @Thinkscripter Lounge adapted from Thinkorswim ZigZagSign Script

input price             = close;
input priceH            = high;    # swing high
input priceL            = low;     # swing low
input ATRreversalfactor = 3.2;
def ATR                 = reference ATR(length = 5);
def reversalAmount      = ATRreversalfactor * ATR;
input showlines         = yes;
input displace          = 1;
input showBubbleschange = yes;


def barNumber = BarNumber();
def barCount = HighestAll(If(IsNaN(price), 0, barNumber));

rec state = {default init, undefined, uptrend, downtrend};
rec minMaxPrice;

if (GetValue(state, 1) == GetValue(state.init, 0)) {
    minMaxPrice = price;
    state = state.undefined;
} else if (GetValue(state, 1) == GetValue(state.undefined, 0)) {
    if (price <= GetValue(minMaxPrice, 1) - reversalAmount) {
        state = state.downtrend;
        minMaxPrice = priceL;
    } else if (price >= GetValue(minMaxPrice, 1) + reversalAmount) {
        state = state.uptrend;
        minMaxPrice = priceH;
    } else {
        state = state.undefined;
        minMaxPrice = GetValue(minMaxPrice, 1);
    }
} else if (GetValue(state, 1) == GetValue(state.uptrend, 0)) {
    if (price <= GetValue(minMaxPrice, 1) - reversalAmount) {
        state = state.downtrend;
        minMaxPrice = priceL;
    } else {
        state = state.uptrend;
        minMaxPrice = Max(priceH, GetValue(minMaxPrice, 1));
    }
} else {
    if (price >= GetValue(minMaxPrice, 1) + reversalAmount) {
        state = state.uptrend;
        minMaxPrice = priceH;
    } else {
        state = state.downtrend;
        minMaxPrice = Min(priceL, GetValue(minMaxPrice, 1));
    }
}

def isCalculated = GetValue(state, 0) != GetValue(state, 1) and barNumber >= 1;
def futureDepth =  barCount - barNumber;
def tmpLastPeriodBar;
if (isCalculated) {
    if (futureDepth >= 1 and GetValue(state, 0) == GetValue(state, -1)) {
        tmpLastPeriodBar = fold lastPeriodBarI = 2 to futureDepth + 1 with lastPeriodBarAcc = 1
            while lastPeriodBarAcc > 0
            do if (GetValue(state, 0) != GetValue(state, -lastPeriodBarI))
                then -lastPeriodBarAcc
                else lastPeriodBarAcc + 1;
    } else {
        tmpLastPeriodBar = 0;
    }
} else {
    tmpLastPeriodBar = Double.NaN;
}

def lastPeriodBar = if (!IsNaN(tmpLastPeriodBar)) then -AbsValue(tmpLastPeriodBar) else -futureDepth;

rec currentPriceLevel;
rec currentPoints;
if (state == state.uptrend and isCalculated) {
    currentPriceLevel =
        fold barWithMaxOnPeriodI = lastPeriodBar to 1 with barWithMaxOnPeriodAcc = minMaxPrice
            do Max(barWithMaxOnPeriodAcc, GetValue(minMaxPrice, barWithMaxOnPeriodI));
    currentPoints =
        fold maxPointOnPeriodI = lastPeriodBar to 1 with maxPointOnPeriodAcc = Double.NaN
            while IsNaN(maxPointOnPeriodAcc)
            do if (GetValue(priceH, maxPointOnPeriodI) == currentPriceLevel)
                then maxPointOnPeriodI
                else maxPointOnPeriodAcc;
} else if (state == state.downtrend and isCalculated) {
    currentPriceLevel =
        fold barWithMinOnPeriodI = lastPeriodBar to 1 with barWithMinOnPeriodAcc = minMaxPrice
            do Min(barWithMinOnPeriodAcc, GetValue(minMaxPrice, barWithMinOnPeriodI));
    currentPoints =
        fold minPointOnPeriodI = lastPeriodBar to 1 with minPointOnPeriodAcc = Double.NaN
            while IsNaN(minPointOnPeriodAcc)
            do if (GetValue(priceL, minPointOnPeriodI) == currentPriceLevel)
                then minPointOnPeriodI
                else minPointOnPeriodAcc;
} else if (!isCalculated and (state == state.uptrend or state == state.downtrend)) {
    currentPriceLevel = GetValue(currentPriceLevel, 1);
    currentPoints = GetValue(currentPoints, 1) + 1;
} else {
    currentPoints = 1;
    currentPriceLevel = GetValue(price, currentPoints);
}

plot "ZZ$" = if (barNumber == barCount or barNumber == 1) then if state == state.uptrend then priceH else priceL else if (currentPoints == 0) then currentPriceLevel else Double.NaN;

rec zzSave =  if !IsNaN("ZZ$" ) then if (barNumber == barCount or barNumber == 1) then if IsNaN(barNumber[-1]) and  state == state.uptrend then priceH else priceL else currentPriceLevel else GetValue(zzSave, 1);

def chg = (if barNumber == barCount and currentPoints < 0 then priceH else if barNumber == barCount and currentPoints > 0 then priceL else currentPriceLevel) - GetValue(zzSave, 1);

def isUp = chg >= 0;

#Higher/Lower/Equal High, Higher/Lower/Equal Low
def xxhigh = if zzSave == priceH then Round(high, 2) else Round(xxhigh[1], 2);
def chghigh = Round(Round(high, 2) - Round(xxhigh[1], 2), 2);
def xxlow = if zzSave == priceL then Round(low, 2) else Round(xxlow[1], 2);
def chglow = Round(Round(low, 2) - Round(xxlow[1], 2), 2);


rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue("ZZ$", 1)) and GetValue(isConf, 1));

"ZZ$".EnableApproximation();
"ZZ$".DefineColor("Up Trend", Color.UPTICK);
"ZZ$".DefineColor("Down Trend", Color.DOWNTICK);
"ZZ$".DefineColor("Undefined", Color.WHITE);
"ZZ$".AssignValueColor(if !isConf then "ZZ$".Color("Undefined" ) else if isUp then "ZZ$".Color("Up Trend" ) else "ZZ$".Color("Down Trend" ));

DefineGlobalColor("Unconfirmed", Color.WHITE);
DefineGlobalColor("Up", Color.UPTICK);
DefineGlobalColor("Down", Color.DOWNTICK);

AddChartBubble(showBubbleschange and !IsNaN("ZZ$" ) and barNumber != 1, if isUp then high else low , Round(chg, 2) , if barCount == barNumber or !isConf then GlobalColor("Unconfirmed" ) else if isUp then GlobalColor("Up" ) else GlobalColor("Down" ), isUp);

## END CODE
There is no condition in this study to scan for.
  1. define your scan condition
  2. run it through the scan hacker
It will probably vomit the "too complex" error.
But you can always try.
 
This Reversal Indicator thread relates to the ZigZagHighLow.

Look at the code and the ZigZag values within the code.

Can someone create a TOS watchlist label showing the "Bot Line" Value so that I know when certain prices on my watchlist reach that level?

I can't get my watchlist to work as follows: ZigZagHighLow("percentage reversal" = 0.01, "atr reversal" = 0.1)

Thanks!
 
This Reversal Indicator thread relates to the ZigZagHighLow.

Look at the code and the ZigZag values within the code.

Can someone create a TOS watchlist label showing the "Bot Line" Value so that I know when certain prices on my watchlist reach that level?

I can't get my watchlist to work as follows: ZigZagHighLow("percentage reversal" = 0.01, "atr reversal" = 0.1)

Thanks!
That is not currently available :(
 
One of my strategies contain a repainting indicators such as the zigzag. Ever time I try to make a scan for this indicator I never get results back. All in trying to do is make the scan identify when the zigzag turns confirmed green or confirmed red but every time I try I end up with a headache from multiple failures . So my question is, is it possible to make a scan with those conditions. if yes, I would love to hear how its possible. I would appreciate any help given.
 
One of my strategies contain a repainting indicators such as the zigzag. Ever time I try to make a scan for this indicator I never get results back. All in trying to do is make the scan identify when the zigzag turns confirmed green or confirmed red but every time I try I end up with a headache from multiple failures . So my question is, is it possible to make a scan with those conditions. if yes, I would love to hear how its possible. I would appreciate any help given.

Paste the following code in a new study, name it, then go to scanner and use that study name to perform the scan. Example, the code below is in a study named NewStudy2191. The picture shows how it looks in the scanner. There are 2 plots, one for scanup and another for scandn, both set to true within 2 bars. The scandn was ran against the SP500 daily and found the results in the picture.

Capture.jpg
Ruby:
def zz = ZigZagHighLow();
def zzSave  = if !IsNaN(zz) then zz else GetValue(zzSave, 1);
def up = zzSave == zzSave[1] and zzSave[1] < zzSave[2];
def dn = zzSave == zzSave[1] and zzSave[1] > zzSave[2];
plot scanup = up;
plot scandn = dn;
 
Can someone please convert this indicator to histogram in lower indicator. Type in Google: Zig Zak Histogram and there are crazy zig Zak histogram and I was trying to share the image unfortunately i am unable coz this site ask to share link no import image. View attachment 1045
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

Here's the study - you might like to load this study on a Daily chart of AAPL, AMZN or your favorite ticker
You can turn off any information you don't want via the user interface

Code:
# 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);

# 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);

# End ZigZag High Low Stats
 
@Montana101x Can someone please convert this indicator to histogram in lower indicator. Type in Google: Zig Zak Histogram and there are crazy zig Zak histogram and I was trying to share the image unfortunately i am unable coz this site ask to share link no import image. View attachment 1045

One simple way would be to replace the Zig Zag Plot code in the script with the following

Capture.jpg
Ruby:
# Zig Zag Plot
declare lower;
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.SetpaintingStrategy(paintingStrategy.HISTOGRAM);
zzp.EnableApproximation();
zzp.HideBubble();
 
Paste the following code in a new study, name it, then go to scanner and use that study name to perform the scan. Example, the code below is in a study named NewStudy2191. The picture shows how it looks in the scanner. There are 2 plots, one for scanup and another for scandn, both set to true within 2 bars. The scandn was ran against the SP500 daily and found the results in the picture.
Is there any way that I can do this with a zigzagpercent instead of a zigzaghighlow?
 
Is there any way that I can do this with a zigzagpercent instead of a zigzaghighlow?

Yes, added this to the standard code below

#----------------------------------------------------------------
declare lower;
"ZZ%".setpaintingStrategy(paintingStrategy.HISTOGRAM);
#----------------------------------------------------------------

Capture.jpg
Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2011-2021
#

input price = close;
input reversalAmount = 8.0;
input showBubbles = no;
input showLabel = no;

assert(reversalAmount > 0, "'reversal amount' should be positive: " + reversalAmount);

plot "ZZ%" = reference ZigZagHighLow(price, price, reversalAmount, 0, 1, 0);


def zzSave = if !IsNaN("ZZ%") then price else getValue(zzSave, 1);
def chg = (price / getValue(zzSave, 1) - 1) * 100;
def isUp = chg >= 0;
def isConf = AbsValue(chg) >= reversalAmount or (IsNaN(getValue("ZZ%", 1)) and getValue(isConf, 1));

#----------------------------------------------------------------
declare lower;
"ZZ%".setpaintingStrategy(paintingStrategy.HISTOGRAM);
#----------------------------------------------------------------
"ZZ%".EnableApproximation();
"ZZ%".DefineColor("Up Trend", Color.UPTICK);
"ZZ%".DefineColor("Down Trend", Color.DOWNTICK);
"ZZ%".DefineColor("Undefined", Color.DARK_ORANGE);
"ZZ%".AssignValueColor(if !isConf then "ZZ%".color("Undefined") else if isUp then "ZZ%".color("Up Trend") else "ZZ%".color("Down Trend"));

DefineGlobalColor("Unconfirmed", Color.DARK_ORANGE);
DefineGlobalColor("Up", Color.UPTICK);
DefineGlobalColor("Down", Color.DOWNTICK);

def barNumber = barNumber();

AddChartBubble(showBubbles and !IsNaN("ZZ%") and barNumber != 1, price, round(chg) + "%", if !isConf then globalColor("Unconfirmed") else if isUp then globalColor("Up") else globalColor("Down"), isUp);
AddLabel(showLabel and barNumber != 1, (if isConf then "Confirmed " else "Unconfirmed ") + "ZigZag: " + round(chg) + "%", if !isConf then globalColor("Unconfirmed") else if isUp then globalColor("Up") else globalColor("Down"));
 
Hi Folks,

Can anyone assist in making the following tweaks to the Zig Zag study below? I spend the better part of last Sunday trying to figure it out and nothing I tried worked! The brain power on here amazes me sometimes! Thanks very much in advance for any assistance!

Tweaks:
1. Only plot the most recent up arrow and most recent down arrow.
2. Color candlesticks green when the most recent up arrow appeared. Color candlesticks red when the most recent down arrow appeared.
3. Color all candlesticks prior to the most recent up arrow and most recent down arrow gray. So all historical candlesticks prior to the two most recent arrows would be colored gray.


# 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);
input showarrows = no;
plot U1 = showarrows and signal > 0 and signal[1] <= 0;
U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
U1.SetDefaultColor(Color.GREEN);
U1.SetLineWeight(4);
plot D1 = showarrows and signal < 0 and signal[1] >= 0;
D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
D1.SetDefaultColor(Color.RED);
D1.SetLineWeight(4);
 
Hi Folks,

Can anyone assist in making the following tweaks to the Zig Zag study below? I spend the better part of last Sunday trying to figure it out and nothing I tried worked! The brain power on here amazes me sometimes! Thanks very much in advance for any assistance!

Tweaks:
1. Only plot the most recent up arrow and most recent down arrow.
2. Color candlesticks green when the most recent up arrow appeared. Color candlesticks red when the most recent down arrow appeared.
3. Color all candlesticks prior to the most recent up arrow and most recent down arrow gray. So all historical candlesticks prior to the two most recent arrows would be colored gray.

There are inputs for count to limit how many zigzags to plot, and show your candle coloring scheme.

Capture.jpg
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/...-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);
#--------------------------------------------------------------------------------
 
View attachment 1045
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

Here's the study - you might like to load this study on a Daily chart of AAPL, AMZN or your favorite ticker
You can turn off any information you don't want via the user interface

Code:
# 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);

# 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);

# End ZigZag High Low Stats
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.
 
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.
I probably should have been more specific. I am using the zigzag high low stats version that was posted on this site.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
554 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top