Need help with implementing an indicator in an EA

 

Hi there,


i am fairly new to writing EAs, so i wanted to start of small and let the EA grow over the time. At the moment i am stuck with exporting values from the ZigZag2_R_ indicator to my EA. As stated on the page of the indicator ( https://www.mql5.com/en/code/7762 ) you can read out the peaks and bottoms with the following code:

iCustom(NULL, 0, "Zigzag2_R_", 12, 5, 3, 0, index) - peaks 
iCustom(NULL, 0, "Zigzag2_R_", 12, 5, 3, 1, index) - bottoms

When i use it this way, i get an error that index is not defined, which makes sense. But i delete the index or replace it with any number the EA compiles fine, but as output i only get "0".

I debug the thing by just printing the output of the variable in MetaTrader by using the following code: (Yes the variable ZZ_high and ZZ_low are initialized at the top and the following code is excuted bellow start(), just to avoid misunderstandings)

ZZ_high = iCustom(NULL, 0, "ZigZag2_R_", 12, 5, 3, 0, 0);
ZZ_low = iCustom(NULL, 0, "ZigZag2_R_", 12, 5, 3, 1, 0);
Print("Zig Zag High:", ZZ_high);
Print("Zig Zag Low:", ZZ_low);

Can anyone please tell me where my mistake is and how to get the last peak and bottom as output?

Thanks in advance.


Greetings Adrian

 
who can tell, we need to c the ZigZag2_r_ indicator to answer
 
qjol:
who can tell, we need to c the ZigZag2_r_ indicator to answer

The Link to the indicator can be found in my first post and now again here. https://www.mql5.com/en/code/7762


Thanks for you help.
 
oluminion:

Hi there,


i am fairly new to writing EAs, so i wanted to start of small and let the EA grow over the time. At the moment i am stuck with exporting values from the ZigZag2_R_ indicator to my EA. As stated on the page of the indicator ( https://www.mql5.com/en/code/7762 ) you can read out the peaks and bottoms with the following code:

When i use it this way, i get an error that index is not defined, which makes sense. But i delete the index or replace it with any number the EA compiles fine, but as output i only get "0".

I debug the thing by just printing the output of the variable in MetaTrader by using the following code: (Yes the variable ZZ_high and ZZ_low are initialized at the top and the following code is excuted bellow start(), just to avoid misunderstandings)

Can anyone please tell me where my mistake is and how to get the last peak and bottom as output?

Maybe there isn't a Peak or Bottom on the current candle ? try creating a for loop looking at the last 100 bars and use the value from the loop and print the iCutom values . . . where you get something other than a 0 should be where there is a Peak or Bottom
 

u need to find the right candle where the ZigZag_r_ is located, it's not always on bar[0] so, u have to find the right bar

b.t.w it's impossible that ZigzagPeakBuffer & ZigzagLawnBuffer to be on one same bar

 
Ok, so if i am right by now, this ZigZag indicator stores the last peak and the last bottom in the buffer array. The index number is the number of the bar, where the peak or bottom is located and if i wirte a loop like: "start at the current bar, shift back till you get a number other than zero for the peaks" (and the same for bottoms of course), then i can get the right values for the last peak and bottom. The loop is then run every tick looking for new peaks and bottoms since they are always some bars behind. Am i right with that? If yes then i think i can get on with my EA.
 
   int n, i = 0; 

      while(n<6)
      {
      if(p0>0) {p5=p4; p4=p3; p3=p2; p2=p1; p1=p0; }
      p0=iCustom(Symbol(),0,"zigzag",ExtDepth,ExtDeviation,ExtBackstep,0,i);
      if(p0>0) {n+=1; }
      i++;
      }

I use that loop for calling zigzag (found it somewhere in the forum).

p4 to p1 are the last highs / lows. That works fine :)