Incorporating ZigZag into an EA

 

Hey All,

I have no programing experience, but recently started playing with Forex Generator 4 to create an EA. It is a fantastic program and I
have pretty much included all the conditions of the manual strategy that I am trying to automate, except for the ZigZag.
Is it posible to incorporate ZigZag into an EA due to its re-drawing etc ?

One of the conditons of my strategy is that (for buy signal) the current price is lower than the pervious 3 low swings of the ZigZag.

Any help/answers or suggestions on how it could be done would be greatly appreciated - thanks ..

 
Is it possible to incorporate ZigZag into an EA due to its re-drawing etc? Yes, just don't use current value.
 

Thanks ubzen...

 
JoBlo:

Hey All,

I have no programing experience, but recently started playing with Forex Generator 4 to create an EA. It is a fantastic program and I
have pretty much included all the conditions of the manual strategy that I am trying to automate, except for the ZigZag.
Is it posible to incorporate ZigZag into an EA due to its re-drawing etc ?

One of the conditons of my strategy is that (for buy signal) the current price is lower than the pervious 3 low swings of the ZigZag.

Any help/answers or suggestions on how it could be done would be greatly appreciated - thanks ..


I have the same problem as you do . i have read all the topic in the website but none is usesul to me. If you found the solution pls. let me know....regards.

Hope you can find the answer as early as possible. 

 
JoBlo:


Is it posible to incorporate ZigZag into an EA due to its re-drawing etc ?

One of the conditons of my strategy is that (for buy signal) the current price is lower than the pervious 3 low swings of the ZigZag.

Any help/answers or suggestions on how it could be done would be greatly appreciated - thanks ..

Yes, it is very simple to include ZigZag in your strategy, you just need to understand how MQL4 works and a bit of programming intuition.

Using the ZigZag indicator that comes with MT4 you can use the following piece of code from one of my EA's to guide you:


_currentZigZag = iCustom(_symbol, trading.FIRST_PERIOD, "ZigZag", ext_zzDepth, ext_zzDev, ext_zzBckStep, 0, 2); //previous candle will be auto zigzag if going down or up so look at previous
if (_currentZigZag > 0)
        if (_currentZigZag == iCustom(g_symbol, period, "ZigZag", ext_zzDepth, ext_zzDev, ext_zzBckStep, 1, 2))
        {
                if (g_zigzag_down_at_2 > g_zigzag_up_at_2)
                        g_zigzag_up_at_3 = g_zigzag_up_at_2;
                if (g_zigzag_down_at_1 > g_zigzag_up_at_1)
                        g_zigzag_up_at_2 = g_zigzag_up_at_1;
                g_zigzag_up_at_1 = iTime(g_symbol, period, 2);
        }
        else
        if (_currentZigZag == iCustom(g_symbol, trading.FIRST_PERIOD, "ZigZag", ext_zzDepth, ext_zzDev, ext_zzBckStep, 2, 2))
        {
                if (g_zigzag_up_at_2 > g_zigzag_down_at_2)
                        g_zigzag_down_at_3 = g_zigzag_down_at_2;
                if (g_zigzag_up_at_1 > g_zigzag_down_at_1)
                        g_zigzag_down_at_2 = g_zigzag_down_at_1;
                g_zigzag_down_at_1 = iTime(g_symbol, period, 2);
        }

Use iCustom to obtain the current value of ZigZag from buffer 0. If it is >0 then we either have a high or low point. Use buffers 1 and 2 to identify which one it is. Once you know that you have a zigzag point, move your previous zigzag points

g_zigzag_up_at_2 and g_zigzag_up_at_3

back since you got a new point at g_zigzag_up_at_1. Zigzags alternate up and down so compare them to know which one to move. Draw it out if that helps understanding what it is doing. (Same logic for "down" variables that store low zigzag points)

You can see I am using iTime to store the time of the Zigzag points in the variables.

You can obtain the value of a zigzag by calling iLow() on the iBarShift() of the variables above. (Since you are storing iTime value). For example:

g_ZigZag_down_at_1_value = iLow(g_symbol,period,iBarShift(g_symbol, period,g_zigzag_down_at_1));

Let's remember that if you are looking for a price lower than the previous 3 low zigzags, the bar that satisfies this condition will become the next zigzag when the bar ends, so

once you have these variables with the right values, your strategy needs to check the following:

if (g_zigzag_down_at_4_value > g_zigzag_down_at_1_value && g_zigzag_down_at_3_value > g_zigzag_down_at_1_value && g_zigzag_down_at_2_value > g_zigzag_down_at_1_value)
{
     //condition is true, open buy trade
}

I know you said you have no programming experience but if you want to get anywhere with MT4, you need to start reading and understanding code. This is the way I use Zigzag in my strategies, hope it helps.


Regards,

Note: variables are defined somewhere else in the code. "ext_" variables are just extern variables used for optimization.

 
sokramm:

Yes, it is very simple to include ZigZag in your strategy, you just need to understand how MQL4 works and a bit of programming intuition.


make it more simple 

https://www.mql5.com/en/forum/100932/page3

Message from qjol 

 
deVries:

make it more simple 

https://www.mql5.com/en/forum/100932/page3

Message from qjol 


Yes, that solution is more simple but:

1. It will calculate the 5 points every tick and therefore perform redundant calculations

2. You don't know which ones are high or low points without adding extra logic

3. You don't know when those zigzag points occurred

If one does not care about those three points, then that code suits you.

 
sokramm:

Yes, that solution is more simple but:

1. It will calculate the 5 points every tick and therefore perform redundant calculations

2. You don't know which ones are high or low points without adding extra logic

3. You don't know when those zigzag points occurred

If one does not care about those three points, then that code suits you.



don't agree with you

1. why should you calculate every tick ??

if you have calculate you know the extremes  if bid higher or lower then last point you know enough

2   no extra logic needed     if 5 higher then 4 what do you think is low point

3   ofcours i know   and where they happened only last point can repaint

Reason: