How to find the last two ZigZag values?

 

Dear forum,

I'm trying to get the previous two, fixed ZigZag values -- I've tried the method found here, but it doesn't seem to work. What I have now is this:

   for(int k = 1; k < Bars; k++){   // Get most recent ZigZag
      if(iCustom(NULL, 0, "ZigZag", Depth, 5, 3, k) > 0){
         ZigZag = iCustom(NULL, 0, "ZigZag", Depth, 5, 3, k);
         break;
         }
      }

   for(int z = 1; z < k; z++){   // Get second most recent ZigZag
      if(iCustom(NULL, 0, "ZigZag", Depth, 5, 3, z) > 0){
          ZigZagPrev = iCustom(NULL, 0, "ZigZag", Depth, 5, 3, z);
         break;
         }
      }

But the log is still showing "0.000000" for both values. Can anyone point out what's wrong?

Thanks for your help.

UPDATE :: This code, a modified version of the code from zzuegg's indicator, seems to do the trick:

      double SwingValue[2]={0,0};
      int Found = 0;
      int k = 0;
      while(Found <= 2){
         if(iCustom(NULL, 0, "ZigZag", Depth, 5, 3, 0, k) != 0){
            SwingValue[Found] = iCustom(NULL , 0, "ZigZag", Depth, 5, 3, 0, k);
            Found++;
         }
         k++;
      }
 

try bigger than 0 instead ( icustom > 0)

 
enotrek:

try bigger than 0 instead ( icustom > 0)


enotrek, thanks for the fast response! I modified my original post to include your suggestion. Unfortunately, it still isn't getting the values. Anything else you can think of?
 

https://www.mql5.com/ru/code/9997

I have used ZigZag in this indicator...

//z

 

ups sorry, the _my would not work for your ;)

https://www.mql5.com/ru/code/9997

 

Z, that code was a huge help. The log is showing the proper values. Thanks for answering my question! Unfortunately, my EA still isn't trading... but that's another question, I'll post that in a new topic. At least I'm getting the right the zigzag values =)

For anyone in the future searching the forum for this same question, the first post reflects the working piece of code.

 
thx a lot, thats just the problem i had to solve myself ...
 
alexboyd:

Z, that code was a huge help. The log is showing the proper values. Thanks for answering my question! Unfortunately, my EA still isn't trading... but that's another question, I'll post that in a new topic. At least I'm getting the right the zigzag values =)

For anyone in the future searching the forum for this same question, the first post reflects the working piece of code.

Hello!

alex, can you to show me the code for to find the last two value of zigzag?

thank you/

 
 
zzuegg:

ups sorry, the _my would not work for your ;)

https://www.mql5.com/ru/code/9997

I left some comments about your Indicator ;-)
 
alexboyd:

Dear forum,

I'm trying to get the previous two, fixed ZigZag values -- I've tried the method found here, but it doesn't seem to work. What I have now is this:

But the log is still showing "0.000000" for both values. Can anyone point out what's wrong?

Thanks for your help.

UPDATE :: This code, a modified version of the code from zzuegg's indicator, seems to do the trick:

i think it must be code with <>0 for a specific period.
Reason: