Help with the ZigZag

ShinJ

New member
So I try to modify zigzag study to show the wave length in $ at the pivot points

It is "UpWavePrice" and "DownWavePrice" in the code below. For now it is just a failed attempt to do this.

If anyone can help me with that it would be awesome

Thanks!

Code:
declare upper;

input price = close;
input reversalAmount = 1.0;
input reversalMode = {default price, percent};

def mode = if  reversalMode ==  reversalMode.price then ZigZagTrendSign(price = price, reversalAmount = reversalAmount) else ZigZagTrendPercent(price = price, reversalAmount = reversalAmount);
def inflection = if reversalMode == reversalMode.price then if !IsNaN(ZigZagSign(price = price, reversalAmount = reversalAmount)) then 1 else 0 else if !IsNaN(ZigZagPercent(price = price, reversalAmount = reversalAmount)) then 1 else 0;
rec trend = if inflection == 1 and mode == -1 then 1 else if inflection == 1 and mode == 1 then -1 else trend[1];

#Wave Length In $

rec UpWavePrice = if inflection==1 and trend==1 and close > open then 0 else if inflection==1 and trend==1 and close <= open then high[-1]-low[-1] else if trend==1 or (inflection==1 and trend ==-1 and close >= open) then upWavePrice[1] + if high>=high[-1] then high-low[-1] else 0 else 0;

rec DownWavePrice = if inflection == 1 and trend == -1 and close < open then price else if inflection == 1 and trend == -1 and close >= open then 0 else if trend == -1 or (inflection == 1 and trend == 1 and close <= open) then downWavePrice[1] + (low - low[1]) else 0;

#Plot

plot uPrice = if (displayMode == displayMode.volume and barsDown == 1 and barsUp == 0) then upWavePrice[1] else Double.NaN;
uVol.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

plot dPrice = if (displayMode == displayMode.volume and barsUp == 1 and barsDown == 0) then  downWavePrice[1] else Double.NaN;
dVol.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
 

SleepyZ

Active member
So I try to modify zigzag study to show the wave length in $ at the pivot points

It is "UpWavePrice" and "DownWavePrice" in the code below. For now it is just a failed attempt to do this.

If anyone can help me with that it would be awesome

Thanks!

Code:
declare upper;

input price = close;
input reversalAmount = 1.0;
input reversalMode = {default price, percent};

def mode = if  reversalMode ==  reversalMode.price then ZigZagTrendSign(price = price, reversalAmount = reversalAmount) else ZigZagTrendPercent(price = price, reversalAmount = reversalAmount);
def inflection = if reversalMode == reversalMode.price then if !IsNaN(ZigZagSign(price = price, reversalAmount = reversalAmount)) then 1 else 0 else if !IsNaN(ZigZagPercent(price = price, reversalAmount = reversalAmount)) then 1 else 0;
rec trend = if inflection == 1 and mode == -1 then 1 else if inflection == 1 and mode == 1 then -1 else trend[1];

#Wave Length In $

rec UpWavePrice = if inflection==1 and trend==1 and close > open then 0 else if inflection==1 and trend==1 and close <= open then high[-1]-low[-1] else if trend==1 or (inflection==1 and trend ==-1 and close >= open) then upWavePrice[1] + if high>=high[-1] then high-low[-1] else 0 else 0;

rec DownWavePrice = if inflection == 1 and trend == -1 and close < open then price else if inflection == 1 and trend == -1 and close >= open then 0 else if trend == -1 or (inflection == 1 and trend == 1 and close <= open) then downWavePrice[1] + (low - low[1]) else 0;

#Plot

plot uPrice = if (displayMode == displayMode.volume and barsDown == 1 and barsUp == 0) then upWavePrice[1] else Double.NaN;
uVol.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

plot dPrice = if (displayMode == displayMode.volume and barsUp == 1 and barsDown == 0) then  downWavePrice[1] else Double.NaN;
dVol.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

Here is something I did awhile ago on the zigzaghighlow study that shows the price, price change and bar count change. See if this helps:

Code:
#TOS Zigzaghighlow with Price and Price Change Bubbles
#Sleepyz
input show_price_bubble  = yes;
input show_change_bubble = yes;
input show_count_bubble  = yes;

input zzotherpriceh = high;
input zzotherpricel = low;
input zzotherperrev = 0.0;
input zzotheratrrev = 5.0;
input zzotheratrlen = 14;
input bubbleoffset  = .0005;
plot zzother  = reference ZigZagHighLow(zzotherpriceh, zzotherpricel,  zzotherperrev, "atr length" = zzotheratrlen, "atr reversal" = zzotheratrrev).ZZ;
zzother.EnableApproximation();
zzother.SetDefaultColor(Color.CYAN);
zzother.SetLineWeight(3);
def zzoth    = if !IsNaN(zzother) then zzother else zzoth[1];
def chgzzoth = AbsValue(zzoth[1] - zzoth);
def count    = if !IsNaN(zzother) then BarNumber() else count[1];

AddChartBubble(!IsNaN(zzother) and show_count_bubble,
                if zzother == high
                then high * (1 + bubbleoffset)
                else low * (1 - bubbleoffset) ,
                "Bars: " + (count - count[1]),
                color.yellow,
                if zzother == high then yes else no); 

AddChartBubble(!IsNaN(zzother) and show_change_bubble,
                if zzother == high
                then high * (1 + bubbleoffset)
                else low * (1 - bubbleoffset)   ,
                "Chg: " + AsText(chgzzoth) ,
                Color.CYAN,
                if zzother == high then yes else no);                                     

AddChartBubble(!IsNaN(zzother) and show_price_bubble,
                if zzother == high
                then high * (1 + bubbleoffset)
                else low * (1 - bubbleoffset)   ,
                (if zzother == high then "H:   " else "L:    ") + AsText(zzother) ,
                if !isnan(zzother) > !isnan(zzother[1]) then Color.GREEN else Color.RED,
                if zzother == high then yes else no);
Capture.jpg
 

ShinJ

New member
Here is something I did awhile ago on the zigzaghighlow study that shows the price, price change and bar count change. See if this helps:
Thank you! I really appreciate your help and I'll try to use your study

That being said, I really need to modify my version of the study. It is a part of my much more complex study with volume and volatility and wave length is the last variable that I need to finish it.

I just cant wrap my head around how to come up with zigzag wave length. It is seems to be a very easy task but I get the wrong values again and again.

Code:
declare upper;

input price = close;
input reversalAmount = 1.0;
input reversalMode = {default price, percent};

def mode = if  reversalMode ==  reversalMode.price then ZigZagTrendSign(price = price, reversalAmount = reversalAmount) else ZigZagTrendPercent(price = price, reversalAmount = reversalAmount);
def inflection = if reversalMode == reversalMode.price then if !IsNaN(ZigZagSign(price = price, reversalAmount = reversalAmount)) then 1 else 0 else if !IsNaN(ZigZagPercent(price = price, reversalAmount = reversalAmount)) then 1 else 0;
rec trend = if inflection == 1 and mode == -1 then 1 else if inflection == 1 and mode == 1 then -1 else trend[1];

#Wave Length In $$$

rec UpWavePrice = ???

rec DownWavePrice = ???

#Plot

plot uPrice = if (displayMode == displayMode.volume and barsDown == 1 and barsUp == 0) then upWavePrice[1] else Double.NaN;
uVol.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

plot dPrice = if (displayMode == displayMode.volume and barsUp == 1 and barsDown == 0) then  downWavePrice[1] else Double.NaN;
dVol.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
 
Last edited:

SleepyZ

Active member
Thank you! I really appreciate your help and I'll try to use your study

That being said, I really need to modify my version of the study. It is a part of my much more complex study with volume and volatility and wave length is the last variable that I need to finish it.

I just cant wrap my head around how to come up with zigzag wave length. It is seems to be a very easy task but I get the wrong values again and again.

Code:
declare upper;

input price = close;
input reversalAmount = 1.0;
input reversalMode = {default price, percent};

def mode = if  reversalMode ==  reversalMode.price then ZigZagTrendSign(price = price, reversalAmount = reversalAmount) else ZigZagTrendPercent(price = price, reversalAmount = reversalAmount);
def inflection = if reversalMode == reversalMode.price then if !IsNaN(ZigZagSign(price = price, reversalAmount = reversalAmount)) then 1 else 0 else if !IsNaN(ZigZagPercent(price = price, reversalAmount = reversalAmount)) then 1 else 0;
rec trend = if inflection == 1 and mode == -1 then 1 else if inflection == 1 and mode == 1 then -1 else trend[1];

#Wave Length In $$$

rec UpWavePrice = ???

rec DownWavePrice = ???

#Plot

plot uPrice = if (displayMode == displayMode.volume and barsDown == 1 and barsUp == 0) then upWavePrice[1] else Double.NaN;
uVol.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

plot dPrice = if (displayMode == displayMode.volume and barsUp == 1 and barsDown == 0) then  downWavePrice[1] else Double.NaN;
dVol.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
Your code does not have all of the variables needed to plot the zigzag, so it is hard to help you with your code. Since TOS has basically replaced the ZigZagTrendSign with the Zigzaghighlow code I used, if you provide a more complete code, I might be able to assist you.
 

ShinJ

New member
Your code does not have all of the variables needed to plot the zigzag, so it is hard to help you with your code. Since TOS has basically replaced the ZigZagTrendSign with the Zigzaghighlow code I used, if you provide a more complete code, I might be able to assist you.

This code is the basic ZigZag study with price or percent reversal that I use for my study. I like the simplicity of it.

If you can help me figure out how to calculate the length of the wave, I would be immensely grateful.

Code:
declare upper;

input price = close;
input reversalAmount = 1.0;
input reversalMode = {default price, percent};

def mode = if  reversalMode ==  reversalMode.price then ZigZagTrendSign(price = price, reversalAmount = reversalAmount) else ZigZagTrendPercent(price = price, reversalAmount = reversalAmount);

def inflection = if reversalMode == reversalMode.price then if !IsNaN(ZigZagSign(price = price, reversalAmount = reversalAmount)) then 1 else 0 else if !IsNaN(ZigZagPercent(price = price, reversalAmount = reversalAmount)) then 1 else 0;
rec trend = if inflection == 1 and mode == -1 then 1 else if inflection == 1 and mode == 1 then -1 else trend[1];

plot wave =  if  reversalMode ==  reversalMode.price then ZigZagSign(price = price, reversalAmount = reversalAmount) else ZigZagPercent(price = price, reversalAmount = reversalAmount);
wave.EnableApproximation();
wave.AssignValueColor(if trend[1] == 1 then color.red else color.red);
wave.SetDefaultColor(Color.RED);
wave.SetLineWeight(1);
 
Last edited:

SleepyZ

Active member
This code is the basic ZigZag study with price or percent reversal that I use for my study. I like the simplicity of it.

If you can help me figure out how to calculate the length of the wave, I would be immensely grateful.

Code:
declare upper;

input price = close;
input reversalAmount = 1.0;
input reversalMode = {default price, percent};

def mode = if  reversalMode ==  reversalMode.price then ZigZagTrendSign(price = price, reversalAmount = reversalAmount) else ZigZagTrendPercent(price = price, reversalAmount = reversalAmount);

def inflection = if reversalMode == reversalMode.price then if !IsNaN(ZigZagSign(price = price, reversalAmount = reversalAmount)) then 1 else 0 else if !IsNaN(ZigZagPercent(price = price, reversalAmount = reversalAmount)) then 1 else 0;
rec trend = if inflection == 1 and mode == -1 then 1 else if inflection == 1 and mode == 1 then -1 else trend[1];

plot wave =  if  reversalMode ==  reversalMode.price then ZigZagSign(price = price, reversalAmount = reversalAmount) else ZigZagPercent(price = price, reversalAmount = reversalAmount);
wave.EnableApproximation();
wave.AssignValueColor(if trend[1] == 1 then color.red else color.red);
wave.SetDefaultColor(Color.RED);
wave.SetLineWeight(1);

I used the code I gave you to add the bubbles to your code. It was mostly just substituting 'zzother' for 'wave'. See if this is works for you:

Code:
declare upper;

input price = close;
input reversalAmount = 1.0;
input reversalMode = {default price, percent};

def mode = if  reversalMode ==  reversalMode.price then ZigZagTrendSign(price = price, reversalAmount = reversalAmount) else ZigZagTrendPercent(price = price, reversalAmount = reversalAmount);

def inflection = if reversalMode == reversalMode.price then if !IsNaN(ZigZagSign(price = price, reversalAmount = reversalAmount)) then 1 else 0 else if !IsNaN(ZigZagPercent(price = price, reversalAmount = reversalAmount)) then 1 else 0;
rec trend = if inflection == 1 and mode == -1 then 1 else if inflection == 1 and mode == 1 then -1 else trend[1];

plot wave =  if  reversalMode ==  reversalMode.price then ZigZagSign(price = price, reversalAmount = reversalAmount, "show bubbles" = Yes) else ZigZagPercent(price = price, reversalAmount = reversalAmount);
wave.EnableApproximation();
wave.AssignValueColor(if trend[1] == 1 then color.red else color.red);
wave.SetDefaultColor(Color.RED);
wave.SetLineWeight(1);

def zzoth    = if !IsNaN(wave) then wave else zzoth[1];
def chgzzoth = AbsValue(zzoth[1] - zzoth);
def count    = if !IsNaN(wave) then BarNumber() else count[1];

input show_price_bubble  = yes;
input show_change_bubble = yes;
input show_count_bubble  = yes;
input bubbleoffset       = .0005;

AddChartBubble(!IsNaN(wave) and show_count_bubble,
                if zzoth>zzoth[1]
                then high * (1 + bubbleoffset)
                else low * (1 - bubbleoffset) ,
                "Bars: " + (count - count[1]),
                color.yellow,
                if zzoth>zzoth[1] then yes else no);

AddChartBubble(!IsNaN(wave) and show_change_bubble,
                if zzoth>zzoth[1]
                then high * (1 + bubbleoffset)
                else low * (1 - bubbleoffset)   ,
                "Chg: " + AsText(chgzzoth) ,
                Color.CYAN,
                if zzoth>zzoth[1] then yes else no);                                  

AddChartBubble(!IsNaN(wave) and show_price_bubble,
                if zzoth>zzoth[1]
                then high * (1 + bubbleoffset)
                else low * (1 - bubbleoffset)   ,
                (if wave == close then "C:   " else "C:    ") + AsText(wave) ,
                if !isnan(wave) > !isnan(wave[1]) then Color.GREEN else Color.RED,
                if zzoth>zzoth[1] then yes else no);
Capture.jpg
 
Last edited:

Similar threads

Top