ZigZag indicator doesn't work in expert advisor

 

Hello everyone,

I tried to sort out this by myself, but didnt succeed... the problem is that I always receive zig zag indicator value as "0".

Below this is all the code I have:

#property copyright ""
#property link ""

//ZIG ZAG parameters
extern int ExtDepth=3;
extern int ExtDeviation=3;
extern int ExtBackstep=3;

int i = 0;
int start()
{
double zigzagprice=iCustom(Symbol(),0,"ZigZag",ExtDepth,ExtDeviation,ExtBackstep,0,0);

i++;
Print(zigzagprice + " " +i +" -> " +iOpen(Symbol(),Period(),0));
return(0);

}


In print message, I always get "0" value in zigzagprice parameter, why is this is like that? Any idea? Because it seems I tried everything:) I do test this in strategy tester in meta trader, thats where I get this value, variables "i" and "iOpen" works, just "zigzagprice" doesnt work.

thanks!

 
cedas:

Hello everyone,

I tried to sort out this by myself, but didnt succeed... the problem is that I always receive zig zag indicator value as "0".

Below this is all the code I have:

print message, I always get "0" value in zigzagprice parameter, why is this is like that? Any idea? Because it seems I tried everything:) I do test this in strategy tester in meta trader, thats where I get this value, variables "i" and "iOpen" works, just "zigzagprice" doesnt work.

thanks!

Hi cedas,

1. Use SRC button to post your code, that way it makes us easier to read your code

2. You don't do that with zig zag. Zig zag always repaint, always change, so you have to search for it. Search the forum first and you may get a lot of example, I mean a lot, such as this https://www.mql5.com/en/forum/140244

:D

 
Hi, the thing is, i looked over all posts in this forum about zigzag, and none of them didnt help. What i want to know about zigzag for expert advisor is do i need to store all values in some array before making decisions, i need to find zig zag points first. Also how to make zigzag visible in expert advisor? thanks
 
cedas:
Hi, the thing is, i looked over all posts in this forum about zigzag, and none of them didnt help. What i want to know about zigzag for expert advisor is do i need to store all values in some array before making decisions, i need to find zig zag points first. Also how to make zigzag visible in expert advisor? thanks

Hi cedas,

Search for it.

int i = 0;
int start()
  {
  double zigzagprice = 0.0;

  for (int bar = 0; bar < Bars; bar ++)
     {
     zigzagprice = iCustom(Symbol(),Period(),"ZigZag",ExtDepth,ExtDeviation,ExtBackstep,0,bar);
     if (zigzagprice != 0.0) break;     
     }

  i++; 
  Print(zigzagprice, " at bar ", bar," with i ", i ," -> " ,iOpen(Symbol(),Period(),0));
  return(0);

  }

:D

 

Hello,

Now I understand what you said that it repaints. Thanks for your previous reply, I did investigate ZIGZAG in Expert Advisor.. I can get the prices, however because indicator always changes (last data), I can't seem to get turning points. May be there is a way in Expert Advisor how to get ZigZag Turning Points? I just need some Print text and thats it.

Need to mark turning points except the last one zig zag values (because that always repaints).

I can write the code, just need some ideas for it, how to do it. Thanks!

 
cedas:

Hello,

Now I understand what you said that it repaints. Thanks for your previous reply, I did investigate ZIGZAG in Expert Advisor.. I can get the prices, however because indicator always changes (last data), I can't seem to get turning points. May be there is a way in Expert Advisor how to get ZigZag Turning Points? I just need some Print text and thats it.

Need to mark turning points except the last one zig zag values (because that always repaints).

I can write the code, just need some ideas for it, how to do it. Thanks!


Hello Cedas,

You will never -ever- get turning points with ZigZag indicator, since the past buffer values are overriden all the time as further highs/lows take place. If you want to play a bit with it though, take a look at my ZigZag non-repainting indicator here: https://www.mql5.com/en/code/10647, which shows how ZigZag really works if you took all signals. To make them a little less verbose, only fractals points are showed.

It also simplifies the buffer work for you (Just read buffer 0 and 1 with iCustom)

Reason: