Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add depth parameter to ZigZag indicator #694

Open
islero opened this issue Jan 31, 2022 · 20 comments
Open

Add depth parameter to ZigZag indicator #694

islero opened this issue Jan 31, 2022 · 20 comments
Labels
enhancement New feature or request

Comments

@islero
Copy link

islero commented Jan 31, 2022

the depth parameter to zigzag indicator will allow to have less noise at the chart and the high and low points will be more obvious. Currently the depth option is not available and simply equals to 0, this means that almost each bar will be H or L if set percentage to 1.
gráfico-zigzag

https://tradeasy.tech/en/zig-zag/

@islero islero added the enhancement New feature or request label Jan 31, 2022
@DaveSkender
Copy link
Owner

@islero thanks for contributing ideas. Please review our documentation for Zig Zag. I think the "depth" parameter you are seeking is called percentChange in our library and it is already available.

It may be confusing because there is a default value of 5, so the method can be used without specifying the parameter.

@DaveSkender DaveSkender added user support Help a user with their implementation and removed enhancement New feature or request labels Jan 31, 2022
@islero
Copy link
Author

islero commented Jan 31, 2022

@DaveSkender, thank you for your reply, I checked documentation and even code, but unfortunately, I've noticed that percentChange is obviously a Deviation percent
What is Zig Zag_ - tradEAsy - Google Chrome 2022-0
By depth I meant the minimum distance (in # candles, integer value) between "H" and "H" or "L" and "L", so for example depth=10 means for example if "H" index is 4, the next "H" should be allowed at index 14, but it doesn't mean that exactly 14 will be the next "H". Need to consider that "H" and "L" points in between this depth=10 candles range are involved, but shouldn't be shown as "H" and "L" points.

I've override GetZigZag extension method locally and simply skipped
if (trendUp && index - lastHighPoint.Index <= depth) continue; if (!trendUp && index - lastLowPoint.Index <= depth) continue;
10 candles in EvaluateNextPoint method, but this led to new extremums right after 10 candles, bcoz percentage change exceeded default percentChange=5.

So, honestly I've no idea how to implement that so far

@DaveSkender
Copy link
Owner

Oh, I see, this is a setting that sets a minimum number of bars between pivots?
I'll take a look, though sounds a bit confusing to interpret if used with small "% deviation".

@islero
Copy link
Author

islero commented Jan 31, 2022

@DaveSkender, this is a setting to set a min number of bars between extremums, like X bars between "H" and "H", same between "L" and "L", thanks :)

@DaveSkender DaveSkender added enhancement New feature or request and removed user support Help a user with their implementation labels Jan 31, 2022
@DaveSkender
Copy link
Owner

DaveSkender commented Mar 26, 2022

See also discussion with @M22arius494

@DaveSkender
Copy link
Owner

DaveSkender commented Mar 27, 2022

I'm seeing here that the TradeEasy and TradingView have two different APIs. TradeEasy also includes a Backstep parameter that limits the minimum number of bars between H/L reversals. Do they both treat Depth the same way? Which one is right?

@DaveSkender
Copy link
Owner

This is what TradingView does with the last leg with a few depth variations. These don't look right to me:

  1. The line segment should never go from L to L

image

  1. It seems to have missed an obvious peak H:

image

I suspect you're trying to avoid this whipsaw scenario:

image

Without the depth parameter, this would usually be fixed by increasing the Deviation value:

image

@DaveSkender DaveSkender removed the enhancement New feature or request label May 16, 2022
@DaveSkender DaveSkender added the enhancement New feature or request label May 31, 2022
@anthonypuppo
Copy link

anthonypuppo commented Aug 13, 2022

There doesn't appear to be much standardization around this. Some sites indicate depth is the minimum bars between extremes while others say it should be extremes of the same time (maxima/minima). If going off the standard offered by TradingView, it appears they divide depth by two and use that as their search window?

[iH, pH] = pivots(high, math.floor(depth / 2), true)
[iL, pL] = pivots(low, math.floor(depth / 2), false)

Snippet from my implementation (where i is a standard i++ increment beginning at the last found ZigZag point):

var chunk = dataPoints.Skip(i).Take(depth).Select((x, y) => (DataPoint: x, Index: y + i)).ToList();
var chunkMin = chunk.MinBy((x) => x.DataPoint.Low);
var chunkMax = chunk.MaxBy((x) => x.DataPoint.High);

I then use the min/max as extreme points to check for reversals instead of just looking one ahead.

@jkaa2
Copy link

jkaa2 commented Aug 13, 2022

Hi,
did anyone managed to clone the zigzag indicator for the Tradeview with same params list (deviation, depth) ?, the library indicator yields different results for the same quote list compared to binance zigzag indicator,

Screenshot 2022-08-13 134526

@tr5x
Copy link

tr5x commented Dec 19, 2022

Hi,

Started using your amazing library recently and also encountered a problem where results are different comparing to TradingView, probably due to depth parameter. Especially it can be seen on recent data, where small price fluctuations are being registered as ZigZag points. If I increase the param of the indicator then the most recent extremes are not registered as ZigZag points too.

For example, the library still shows 1180.18 as the most recent low point but TradingView shows 1172.75.

image

Thanks!

@DaveSkender
Copy link
Owner

DaveSkender commented Dec 19, 2022

Thanks for the info. I’ll take a closer look at depth when I get around to this one.

Just an FYI to everyone, TradingView is not always a reliable standard nor is it a good source for basing accuracy. See #801 for some examples, including some obvious problems I’d shown above.

We’ve been basing our definition on how it is described by Investopedia and by Chart School at stockcharts.com; but do agree that there’s no clear expert source author on this one. I usually defer to original expert author publications to clarify.

@vedattaylan

This comment was marked as off-topic.

@DaveSkender

This comment was marked as off-topic.

@vedattaylan

This comment was marked as off-topic.

@DaveSkender

This comment was marked as off-topic.

@vedattaylan

This comment was marked as off-topic.

@DaveSkender
Copy link
Owner

DaveSkender commented Jul 12, 2023

I still have a lot of uncertainty how depth might negatively impact the quality of this indicator. It doesn’t smell right. I can try to explain.

What I hear is that you essentially want to ignore quick reversals — for example, you don’t want to eat ice cream every day, but once a week is okay. 🍦

Where I struggle with this concept: if ice cream arrives on Monday, Tuesday, and Wednesday, why would you want to arbitrarily rule out Tuesday or Wednesday as the best day in the week to eat ice cream? It doesn’t add up, logically.

If your goal is to avoid whipsaw reversals, my recommendation is either increase your percentChange (deviation) or use a pre-smoother like ALMA to prevent random spikes from triggering reversals.

// use chaining to pre-smooth
// UPDATE: this is impossible, won’t work
var results = quotes
    .GetAlma(..)
    .GetZigZag(..);

I’ll keep this issue open for a while longer to see if there’s any strong, compelling counter arguments to my logic, but am leaning towards skipping this one.

@DaveSkender
Copy link
Owner

DaveSkender commented Jul 12, 2023

And now I’ll eat my words. You can’t chain ALMA to ZIG ZAG, it needs a full quote! 😵‍💫

I can update Zig Zag to allow this chaining option, but you’ll not have a high/low option for endType when using in this manner. This will also have a side benefit of enabling Zig Zag on all the basic quote transforms — the aggregate options like HLC3 can also solve the random spike problem.

@DaveSkender
Copy link
Owner

DaveSkender commented Jul 12, 2023

@anthonypuppo I think has the best lead here. If I understood it correctly, he’s saying a reversal point also has to be a Williams Fractal, where depth is the windowSpan parameter. This could enable my ice cream on Wednesday scenario, possibly.

@vedattaylan
Copy link

Hi Dave.
From what I understand it seems unlikely. Thank you for your interest in this matter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

No branches or pull requests

6 participants