ZigZag Volatility
Author: Gerig
Creation Date: 1/1/2015 3:48 PM
profile picture

Gerig

#1
Perfectly realized in Wealth-lab indicator ZigZag. ZigZag class using in algorithm of counting Elliott waves to determine the wave 3, 5. However, when significant changes in volatility there is a need to apply a different ZigZag with large percent the parameters determining the peaks and trough. The idea to make ZigZag Volatility, where the parameter that will be determined by the peaks and troughs will vary depending on the volatility.
Unfortunately I do not know how to implement ZigZag class in the algorithm, so sketched out his version, which will illustrate the idea.
I want this indicator add custom indicators, but first I would like to implement in the indicator records of all peaks and trough, as is done in the ZigZag class
If you could find a few minutes to make any suggestions in correcting my logic I would be grateful.
CODE:
Please log in to see this code.
profile picture

Eugene

#2
QUOTE:
However, when significant changes in volatility there is a need to apply a different ZigZag with large percent the parameters determining the peaks and trough.


Igor, have you tried calling the .Value method of Peak/Trough to calculate a ZZ with different percentage on demand?
profile picture

Gerig

#3
Thank you for the quick response Eugene.
Yes, initially I was going that way. Inside the loop bar calculated interest on which are defined peaks and troughs. The result - the slow work of the script and drawing several chatting ZigZag, pass signals. This effect reminded me peeking. The second step I made several ZigZag with different parameters, the algorithm selects one of the many ZigZag, which corresponded to the volatility at the time. The result is a remarkable complication of the algorithm and the slow work of the script.

Especially trade Elliott Wave is the definition section with the most probable direction of price movement. The levels Fibonacci calculated target. Of course, this value is directly linked to the price levels of peaks and troughs. If the value percent is very low, the peaks and troughs are very common and can actually equal High and Low candles. In other words, peaks and valleys correspond volatility. Volatility is uncertainty. That would increase the likelihood of a favorable outcome to choose other peaks and troughs separated by a distance greater than the volatility. Therefore, the idea to calculate the volatility of the average value of High and Low previous 13-21 candles. Then, on the basis of this value are defined peaks and troughs.
profile picture

Eugene

#4
QUOTE:
The result - the slow work of the script and drawing several chatting ZigZag, pass signals.

Good point.

QUOTE:
Unfortunately I do not know how to implement ZigZag class in the algorithm,

Let me recommend doing what the ZigZag class is internally built upon: a collection of ZigZag events. When a peak/trough occurs, instantiate a new "ZigZag" and assign values to its significant properties (such as bar, price etc.), then add it to the collection (in case of ZigZag class, it's a Dictionary). See the source code in the Wiki for inspiration.
profile picture

Gerig

#5
Of course, Eugene, I looked Wiki Wealth-lab, but there is a description of ZZ and Syntax ZigZag class. Script calculates ZigZag missing. Otherwise, everything is I would have done. I have to make their own algorithm of the indicator, and then compare it with the results of ZigZag Wealth-lab. I can say that the idea to define the parameters ZigZag, depending on the volatility justified. I took one algorithm, but in one version used ZigZag Wealth-lab (algorithm PTS), and the other ZigZag Volatility (algorithm ZZV1). Results are shown.
profile picture

Gerig

#6
If you want you can compare for yourself. Only need to select the paper with high liquidity.
Trade System PTS:
CODE:
Please log in to see this code.

Trade System ZZV1:
CODE:
Please log in to see this code.

profile picture

Gerig

#7
Gradually move towards creating your own indicator, since it tests conducted showed its effectiveness. Now, however, need your help. When you run the attached script, no errors Wealth-lab does not show, just no errors in Visual Studio, but no indicator on the chart. I would be grateful if you help me to understand this.
CODE:
Please log in to see this code.
profile picture

Eugene

#8
The variables troughbar and peakbar return 0 so neither one of your conditions in Execute() applies. Hence no DrawLine output.
profile picture

Gerig

#9
Methods Peakbar and Troughbar I checked separately, I think they are not the problem ...
CODE:
Please log in to see this code.
profile picture

Eugene

#10
QUOTE:
I think they are not the problem ...

Don't think. ;) Try setting a breakpoint and debugging step by step in Visual Studio. You'll quickly see that they return 0.
profile picture

LenMoz

#11
Are you missing an initialize?
CODE:
Please log in to see this code.
profile picture

Gerig

#12
Thank you, Leonard to pay attention to my problem. Volat variable initialization occurs at the very beginning
CODE:
Please log in to see this code.
profile picture

LenMoz

#13
QUOTE:
occurs at the very beginning

1. I saw that, but I think it is the wrong place. Your code is summing the most current bars plus the leftover Volat value from the prior bar. Perhaps that is what you want.

2. Another observation related to performance. It seems that a Drawline occurs at every bar, redrawing the same line if troughbar and peakbar have the same values, as they often will.
profile picture

Gerig

#14
Thank you, Leonard. I tried to rearrange “Volat” variable at the specified location. This does not change the situation.
Let me make some clarifications:
- Valid indicator Volat (Volatility) is calculated as the average of a number of previous candles. Number of previous candle determined by the parameter “_candles”.
- Troughbar number bar, where there is a trough;
- Peakbar number bar, where there is a peak;
- Used object Bars, which contains information about the values High, Low, Open, Close each candle.
Thus having a peakbar value of the bar number or troughbar can easily determine the value of a peak or trough.
For example - Peak = High [peakbar], and Trough = Low [troughbar]
Methods “public int Peakbar (int bar, DataSeries Peak)” and
“public int Troughbar (int bar, DataSeries Trough)” are needed that would calculate the number of bars, which were earlier peaks and troughs.

Causing, for example Peakbar (peakbar, Peak), you can get a number of the bar, where he was earlier peak.

In general, the light operates (See script in message Gerig # 9), but I need to translate it into a custom indicator for frequent call. Because there is the idea of calling this indicator with other parameters, which will be exhibited levels of stop-loss orders.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).