ZigZag iCustom always getting value = 0

 

Hey again all,

I have this code as part of an EA:

   ZigCurr = iCustom(NULL, 0, "ZigZag", 12, 5, 3, 0, 1);
   ZigPrev = iCustom(NULL, 0, "ZigZag", 12, 5, 3, 0, 2);

I also have the bar shift ranging from 1-49 in another loop. All are giving me ZigCurr and ZigPrev as both 0. One of the bar shifts gives a number for ZigCurr but not ZigPrev. Can anyone tell me what's going on?

 
ubuntuboy:

Hey again all,

I have this code as part of an EA:

I also have the bar shift ranging from 1-49 in another loop. All are giving me ZigCurr and ZigPrev as both 0. One of the bar shifts gives a number for ZigCurr but not ZigPrev. Can anyone tell me what's going on?

I use the ZigZag this way...

   for ( x=0; x<Bars; x++ )
   {
      if( iCustom(NULL, 0, "ZigZag", 12, 5, 3, 0, x)==0 ){
         continue;
      }
      if( first==0 ){
         first = x;
         continue;
      }
      if( second==0 ){
         second = x;
         break;
      }
   }
   if( second==0 ) second=100;
   

can you see what this does? If ZigZag is 0, keep looking

if not, and "first" has not yet been marked, mark it and keep looking

if not and "second" has not yet been marked, mark it and break

if "second" is not marked, set it to 100

simple?

 

It looks like you search for a nonzero value, marking the first and second occurrences. What's this deal with setting the second mark to 100 if you didn't find it? Doesn't second represent how many bars back from the current bar the second nonzero value is?

Also, I still don't understand why we're getting nonzero values in the first place. I went ahead and output the bar indices from your loop as well - there's a 12 bar discrepancy! What's up with that?!

Reason: