Download MetaTrader 5

Problem with ZigZag indicator - page 4

To add comments, please log in or register
Unable to find the right application? Order it!
Fernando Carreiro
2349
Fernando Carreiro 2014.02.23 23:02  
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.

AED AED
247
AED AED 2014.02.24 14:11  

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:
Fernando Carreiro
2349
Fernando Carreiro 2014.02.25 01:29  

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

AED AED
247
AED AED 2014.02.25 20:19  
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.

Fernando Carreiro
2349
Fernando Carreiro 2014.02.25 22:04  
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?
1234
To add comments, please log in or register