Problem with ZigZag indicator - page 4

 
aed71:

OK Thanks FMIC.

In fact my problem was about the expert that I shared in the forum. Your script is works fine many thanks for that but basically I need it in the form of expert that can work near real-time mode as well.

Your original queries on this thread were:

  1. How to properly access data from the ZigZag indicator via the use of "iCustom" function?
  2. How to collect and process the ZigZag High and Low points for statistical analysis?

My script has provided you with example code and the knowledge to answer both those queries, so that you can now apply that knowledge to other uses such as an EA that you wish to develop. All you have to do is use my code for the iCustom() usage and the testing the of ZigZag High and Low points and apply it to your EA code.

However, the other query, that you mentioned later, of how to use the ZigZag data in an EA specific to the needs of optimising a strategy that you already have functioning in another EA, has not been put forward or described in sufficient detail here on this thread. So, in essence, I am unable to offer advice or help you because I do not know what it is you require.

If you read the article that accompanies my ZigZagZug indicator in the codebase, you will see that using the ZigZag in strategies and EAs is not easy because of the constant repainting, and requires careful understanding of how it works and how it can possibly be used in different strategies and EAs.

In other words, the marriage between ZigZag data and a EA strategy is complex and needs to be well defined. So without knowing anything about your current strategy or how it is to be optimised, I cannot offer you more help or advice.

Since it is understandable that you may not want to be more forthcoming publically, I even offered you the chance to do it in private, and at no cost. I am a Software Developer and I normally charge for these services.

Other, than what I have already offered you, I can do no more or offer you any more advice without understanding the nature of the problem you want to solve.

 

Hi,

I managed to correct my code. There was a mistake in the logic of the loops, now it works fine as far as I tested.

Those who are interested could use it. It is designed to be used as expert and it uses metaquotes standard ZigZag indicator.

What it does basically finds the real high and low points in the zigzag indicator. It can be used to find low and high points in historical data also for period and amplitude analysis.

It's not real-time! It goes back to the last high and low values, so depending on the last trend length, it could go back and correct the values. Do not use it before a quick test in strategy tester.

FMIC, thanks for your efforts and help.

Files:
 

Hello aed71,

There is still a few logic bugs in your code.

  1. Your so called "tick loop", is in fact a "New Bar Condition", since you are testing the "Time[0]" for a change in time in order to detect a new bar. I suggest changing the comment so as not to misrepresent the code.
  2. You are assigning values to the array before testing conditions and then you are testing certain variables multiple times without need in order to erase it again. It will only slow down your code and also makes it difficult to follow the logic.
  3. Your way of finding repaint points is incorrect and not at all robust. You should really study how the ZigZag works in order to find the repaint points properly. Read it's code, or that of the ZigZagZug (which ever is easier for you to follow) in order to understand its its logic.
  4. You are storing null values in the array without need. Why keep incrementing the counter and adding to the array even when there is no ZigZag point available. You are just wasting valuable resources (RAM and CPU cycles) without need. It will slow down your code execution. Rather use dynamically grown arrays instead of static because you cannot guarantee a certain size requirement beforehand.
  5. In order to analyse the data afterwards, such as wave periods or frequencies, you will also need to keep track of the Time index and/or Bar Shift index as well.

Best regards,
FMIC

 
FMIC:

Hello aed71,

There is still a few logic bugs in your code.

  1. Your so called "tick loop", is in fact a "New Bar Condition", since you are testing the "Time[0]" for a change in time in order to detect a new bar. I suggest changing the comment so as not to misrepresent the code.
  2. You are assigning values to the array before testing conditions and then you are testing certain variables multiple times without need in order to erase it again. It will only slow down your code and also makes it difficult to follow the logic.
  3. Your way of finding repaint points is incorrect and not at all robust. You should really study how the ZigZag works in order to find the repaint points properly. Read it's code, or that of the ZigZagZug (which ever is easier for you to follow) in order to understand its its logic.
  4. You are storing null values in the array without need. Why keep incrementing the counter and adding to the array even when there is no ZigZag point available. You are just wasting valuable resources (RAM and CPU cycles) without need. It will slow down your code execution. Rather use dynamically grown arrays instead of static because you cannot guarantee a certain size requirement beforehand.
  5. In order to analyse the data afterwards, such as wave periods or frequencies, you will also need to keep track of the Time index and/or Bar Shift index as well.

Best regards,
FMIC

Thanks again for your comments;

I'm not a good programmer so the code itself may not be perfect :-) However let me try to explain my logic;

1-) The comment part could be changed to "every new bar"..

2-) 4-) 5-) The logic of using large arrays is that afterwards with a new process I'll count the zero valued bars between highs or between high and low in order to find the period, amplitude etc. So I need to initialize the array before using it and I do not need to deal with the time index etc. Just more buffer which is not a big issue for my project currently.

3-) I have traced the zigzag and zigzagzug several times. in zigzag although you have real high and lows at the end, if you put those values in to an array, you will see that there are in-between lows or highs. You cannot avoid them and weather you use mode0 and mode1/mode2 combination. There always be in-between lows and highs. In zigzagzug you can clearly see those points. Beside this I see that there are cases where mode0 is zero but mode1 or mode2 are greater than zero which are incorrect points. So I decided to put extra code to avoid these points.

As I mentioned, this may not be the best code for finding zigzag points however the code it self is working correct in my tests. I have tested several times. I always recommend that those who wants to use it should test it before.

Have you test it? Doesn't it give the correct points. When you say it's not robust or it is incorrect, I assume that your tests failed, is it?

Thanks.

 
aed71:

Thanks again for your comments;

I'm not a good programmer so the code itself may not be perfect :-) However let me try to explain my logic;

1-) The comment part could be changed to "every new bar"..

2-) 4-) 5-) The logic of using large arrays is that afterwards with a new process I'll count the zero valued bars between highs or between high and low in order to find the period, amplitude etc. So I need to initialize the array before using it and I do not need to deal with the time index etc. Just more buffer which is not a big issue for my project currently.

3-) I have traced the zigzag and zigzagzug several times. in zigzag although you have real high and lows at the end, if you put those values in to an array, you will see that there are in-between lows or highs. You cannot avoid them and weather you use mode0 and mode1/mode2 combination. There always be in-between lows and highs. In zigzagzug you can clearly see those points. Beside this I see that there are cases where mode0 is zero but mode1 or mode2 are greater than zero which are incorrect points. So I decided to put extra code to avoid these points.

As I mentioned, this may not be the best code for finding zigzag points however the code it self is working correct in my tests. I have tested several times. I always recommend that those who wants to use it should test it before.

Have you test it? Doesn't it give the correct points. When you say it's not robust or it is incorrect, I assume that your tests failed, is it?

Thanks.


You are missing the point! The code I provided shows you how to properly identify the High/Low ZigZag points; yet you choose to ignore it and do it your own way that makes the code more difficult to understand and slower as well as use more resources than is necessary. Why?
 
Fernando Carreiro #:

You are using the ZigZag incorrectly in your iCustom example. The Standard ZigZag by MetQuotes has THREE (not two) Buffers (Modes or Line Index in iCustom)

  1. Mode = 0: Hold both the High and Low ZigZag Points.
  2. Mode = 1: High Points but not necessarily only ZigZag points (as it also holds repaint points).
  3. Mode = 2: Low Points but not necessarily only ZigZag points (as it also holds repaint points).

You will need to compare the first buffer (Mode 0) with the other 2 buffers in order do decide if it is a High Point or a Low Point (e.g. if both Buffer 1 and Buffer 3 have the same value then it is a Low ZigZag point, and if both Buffer 1 and Buffer 2 are the same then it is a High point).

Also, in order to better understand how a ZigZag works and how it repaints, I suggest playing around with my ZigZagZug indicator. However, in your code use the the MetaQuotes ZigZag, as it is faster. My version does more processing because of the extra features and is thus slower.

PS! If Buffer 1 (Mode = 0) has a value of 0.0, but the other buffers have non-zero values, then they are older repaint points and NOT ZigZag Points.

In your code your are using the Mode 0 Buffer as the Low and Mode 1 Buffer as High. That is totally incorrect.

u will not believe how much this helped me thanks a lot 
Reason: