Problem with ZigZag indicator - page 3

 
FMIC:


As explained before in an earlier post, you can not just use the High and Low buffer to get ZigZag points as they also include repainted points as well (cyan and pink dots on mine). On the standard ZigZag it is this way too, but you just don't see them. That is why my indicator shows them so you can understand it better.

You have to compare the High and Low buffers to the first one that holds BOTH Low and Highs in order to filter out ONLY ZigZag points.

NB! 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).

If you want, attach your file to a post, and I will correct it so you can see how to use it correctly ( ATTACH it, don't use SRC so as not to be long post ).


Hi FMIC,

Thanks for your explanation and help. I could not yet succeed to get the high and low values. The issue is that it repaints (normally) and I cannot find the historical high and low. I'm also using mode 0 and mode 1 or mode 0 and mode 2 in original zigzag indicator however all the results already has both values. I mean there is no single line with zh (mode 1) or zl (mode 2) with values but no zz (mode 0). So I could not succeeded to use that method.

Besides I used the index of iCustom() function but could not succeed. It seems very simple but I'm working on it more than 1 day but could not find a solution.

Please find my code in the attachment (version 5). Any help is very much appreciated.

Files:
 

I run some more tests and also perform visual test. I even put the iCustom index to 100 ticks back in order to avoid repainting but it does. The issue is that when ever a call the zigzag indicator it's looking to the actual data; 100 tick before, 10 ticks before or 1000 ticks before doesn't have any impact on it. So it's better to use index as 1.

My understanding is that I need to perform another loop checking the arrays and correcting the highs and lows by eliminating the data; such as if there are two consecutive highs it will eliminate the lowest one and do the opposite for lows. My initial thinking is again going back say 100 days in the array and check if there are consecutive highs. I have not conclude to the algorithm yet.

Do you have a better idea? Including using completely a different approach to identify highs and lows in the historical data?

 
aed71:

I run some more tests and also perform visual test. I even put the iCustom index to 100 ticks back in order to avoid repainting but it does. The issue is that when ever a call the zigzag indicator it's looking to the actual data; 100 tick before, 10 ticks before or 1000 ticks before doesn't have any impact on it. So it's better to use index as 1.

My understanding is that I need to perform another loop checking the arrays and correcting the highs and lows by eliminating the data; such as if there are two consecutive highs it will eliminate the lowest one and do the opposite for lows. My initial thinking is again going back say 100 days in the array and check if there are consecutive highs. I have not conclude to the algorithm yet.

Do you have a better idea? Including using completely a different approach to identify highs and lows in the historical data?


Hello aed71,

I just came back from a job and it is time to go to bed. I will take a look at your code in more detail in the morning and provide you with a correct solution.

However, as a quick note, you don't have to look back 1000 or 100 bars, just enough to contemplate the "depth" and the "backstep" parameters.

Also, since you are only collecting and analysing the data, consider a Script to walk forward instantly over the entire history data, instead of an EA using tick intervals. This way, you will not have to worry about repainting.

Tomorrow I will provide you with a more complete explanation.

Best regards,
FMIC

 

Hello FMIC,

Since yesterday I'm working on the algorithm how to eliminate the false highs and lows and I have coded the attached version for that. It somehow eliminates the false signals however it sometimes deletes the original one where it should NOT do it.

The principle behind the code is:

If there is a high; it goes back till to the last known low and step by step checks if the current high is higher than the previous one then it will erase the previous high.

The same valid for low part. I put some explanations to the code.

At least I do not have any concurrent highs or lows anymore :-)

Now I need to find the bug where it deletes the original high/low points.

If you can have a look to my code may be you can understand the bug in a short time. I'm too much concentrated may be can't see the even simple bugs...

Thanks for your help again.

Files:
 

Good morning "aed71",

I have not yet looked at your most recent file, but here is my Script (not Indicator, not EA) to review a certain time period and output the ZigZag Highs and Lows to a CSV file.

Just attach the Script to a chart and it will run in seconds. Then just review the CSV file that is generated in the "MQL4\Files" folder. I have included an example run on EURUSD Daily Chart for the Year 2013.

Since this is a Script you do not have to worry about repaints at all.

Best regards,
FMIC

PS! I will review you latest file next and the give you my comments.

EDIT: I have looked at your latest code and it is all over the place. Just take a look at my code and see that testing for Highs an Lows is much simpler. No need for all that confusion in your code. Here is an extract (full code in ZIP file):

if( dblZigZagPoint > 0 )  // Test if a ZigZag Point is found
{
   intZZCount++;  // Increment ZigZag Counter

   // Test if it is a High, Low or Unknown
   string strZZType = strZZUnknown;
   if( dblZigZagHigh > 0 ) strZZType = strZZHigh;
   else if( dblZigZagLow > 0 ) strZZType = strZZLow;
               
   // Output the ZigZag Point Data to CSV File
   FileWrite( intCSVFileHandle, intZZCount, strZZType, DoubleToString( dblZigZagPoint, intDigits ), Time[ intBarShift ] );
}
Files:
 
FMIC:

Good morning "aed71",

I have not yet looked at your most recent file, but here is my Script (not Indicator, not EA) to review a certain time period and output the ZigZag Highs and Lows to a CSV file.

Just attach the Script to a chart and it will run in seconds. Then just review the CSV file that is generated in the "MQL4\Files" folder. I have included an example run on EURUSD Daily Chart for the Year 2013.

Since this is a Script you do not have to worry about repaints at all.

Best regards,
FMIC

PS! I will review you latest file next and the give you my comments.

EDIT: I have looked at your latest code and it is all over the place.
Just take a look at my code and see that testing for Highs an Lows is much simpler.
No need for all that confusion in your code.


Great work, worked smoothly, should be included in the code base.... Thank you.

I have two questions if you don't mind:

1-) My data that I downloaded and see in the graph was showing 4 digits but the output of the script was 5 digits. How can it be possible? I mean 5 digits without zero at the end.

Count,Type,Price,DateTime

1,H,1.34962,2013.11.04 00:30:00

2,L,1.34861,2013.11.04 02:15:00

3,H,1.35015,2013.11.04 03:00:00

4,L,1.34417,2013.11.04 05:15:00

5,H,1.35127,2013.11.04 11:15:00

6,L,1.34910,2013.11.04 15:45:00

7,H,1.35236,2013.11.04 18:15:00

8,L,1.35045,2013.11.04 19:45:00

9,H,1.35203,2013.11.04 22:45:00

2-) The script is very much useful however this was the first part of my project where I analyse the historical data. Afterwards I was planning to include the code to my expert and somehow find the correlation between the recent history and decide for further optimization of the current variables accordingly. In other words I need to run something similar in the expert as well. So how would it be possible to convert it to expert?

Thanks again for your help :-)


 
aed71:


Great work, worked smoothly, should be included in the code base.... Thank you.

I have two questions if you don't mind:

1-) My data that I downloaded and see in the graph was showing 4 digits but the output of the script was 5 digits. How can it be possible? I mean 5 digits without zero at the end.

2-) The script is very much useful however this was the first part of my project where I analyse the historical data. Afterwards I was planning to include the code to my expert and somehow find the correlation between the recent history and decide for further optimization of the current variables accordingly. In other words I need to run something similar in the expert as well. So how would it be possible to convert it to expert?

Thanks again for your help :-)

  1. If you have a 5 digit broker, then data will have the 5 digits. The problem in many Indicators is that they do not use the "IndicatorDigits()" function so end up displaying only the default number of digits irrespective of what is provided by the broker. If you look at my ZigZagZug code you will see that I explicitly set this, to correct the problem, something that MetaQuotes has failed to do in their own code:

    // Set Number of Digits (Precision)
       IndicatorDigits( Digits );

  2. As for using the code in an expert, that really depends on many things, such as the strategy and how the repaints will affect it. Some strategies are not affected by the repaints, others are very sensitive to them. I will not be able to offer much advice for an "unknown" strategy. You would have to be specific about it in that case. But remember, that you do not need to look back 1000 bars. If you learn how ZigZag works and how it uses high and low break-outs and how it searches back, sometimes you only need to look back for a distance of (Depth + Backstep) bars - depending on the strategy it could be slightly more or even less, but never the 1000 or 100 you use.

 

Thanks for the information about digits. It's a headache for me, I need to read and understand the details of it...

Let me elaborate more what I'm trying to achieve. I've quite profitable expert (currently) that I have tested in last 10 years. However the expert is not behaving all well in each condition, not very bad but not promising in some years/moths. It has some pre-optimized variables that impacts it's profitability. I'm willing to find a correlation between recent-history and today in order to self-optimize the variables.

So what I need is to find the peaks and lows in the historical data to calculate the periods and amplitude of the historical data. I'll try to manually find a correlation between the recent-historical data and current profitable variables of the expert. If I can find it somehow, I'll add a similar code to my expert, every day it will check the statistical data of last one week and according to the correlated constants it will self-optimize the expert variables.

So this is the strategy. I've worked on many other topics to analyse the historical data including Fourier, Hurts Cycles, Goertzel, MESA etc but I concluded that using a method that run over the existing data will be much better.

So I do not need a real-time high-low analysis, in 15M data set, I'm ready to loose half-day data (almost 45 ticks). Most probably I'll look at last 5 days and 4.5days change is I guess enough to find the new optimized values.

Regarding my code, I think the problem is; while it is checking the previous highs it goes too much to back, should stop on the local lowest value. I'm still working on it since I need the expert part of the tool.

 
aed71:

Thanks for the information about digits. It's a headache for me, I need to read and understand the details of it...

Let me elaborate more what I'm trying to achieve. I've quite profitable expert (currently) that I have tested in last 10 years. However the expert is not behaving all well in each condition, not very bad but not promising in some years/moths. It has some pre-optimized variables that impacts it's profitability. I'm willing to find a correlation between recent-history and today in order to self-optimize the variables.

So what I need is to find the peaks and lows in the historical data to calculate the periods and amplitude of the historical data. I'll try to manually find a correlation between the recent-historical data and current profitable variables of the expert. If I can find it somehow, I'll add a similar code to my expert, every day it will check the statistical data of last one week and according to the correlated constants it will self-optimize the expert variables.

So this is the strategy. I've worked on many other topics to analyse the historical data including Fourier, Hurts Cycles, Goertzel, MESA etc but I concluded that using a method that run over the existing data will be much better.

So I do not need a real-time high-low analysis, in 15M data set, I'm ready to loose half-day data (almost 45 ticks). Most probably I'll look at last 5 days and 4.5days change is I guess enough to find the new optimized values.

Regarding my code, I think the problem is; while it is checking the previous highs it goes too much to back, should stop on the local lowest value. I'm still working on it since I need the expert part of the tool.


What you have described does not really help understand the nature of the EA in order to give you advice.

If you wish, send me a Private Message with the details and I can take a good look at your EA and suggest the necessary code for it.

Alternatively all I can suggest is that you try to implement it as best you can, and when you have a specific problem you need to solve, come back to the forum and post a query specific to it and see if users can help.

 

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.

Reason: