Efficiency: Multiple iterations of ZigZag

 

I have a need to retrieve the last 5 ZigZag swing prices & times for multiple iterations of ZigZag Depth.

With an eye to efficiency, what is the best mode of attack for this?

1. iCustom call

2. Incorporate ZigZag into the indicator as a function

3. Makes no difference between 1 and 2

4. Something else entirely

Any thoughts greatly appreciated!

 
toast:

I have a need to retrieve the last 5 ZigZag swing prices & times for multiple iterations of ZigZag Depth.

With an eye to efficiency, what is the best mode of attack for this?

1. iCustom call

2. Incorporate ZigZag into the indicator as a function

3. Makes no difference between 1 and 2

4. Something else entirely

Any thoughts greatly appreciated!


I believe that WHRoeder posted some code re getting the last 2 zigzag values in recent days.

It can probably be adapted to retrieve 5

Just look through recent topics with zigzag in the title

 
GumRai:


I believe that WHRoeder posted some code re getting the last 2 zigzag values in recent days.

It can probably be adapted to retrieve 5

Just look through recent topics with zigzag in the title


& here it is
 

Many thanks for the replies.

I can loop ZigZag from iCustom, but I'm more wondering about efficiency.

Every time I call iCustom (x10 times) is iCustom having to recalculate all values from scratch? I only need the last 5 values... so that seems like a lot of wasted effort. But then the EA Journal show iCustom being loaded only once (for each iteration) during the course of the EA running.

Which is why I'm wondering if there is a better way to approach this, such as incorporating a function into the indicator which is a modified version of ZigZag that can utilize prev_calculated to speed things up... but I'd really rather not re-invent the wheel if it is totally unnecessary!

 
   //Zigzag Code shift can = zero
   double P0 = 0, P1 = 0, P2 = 0, P3 = 0, P4 = 0, P5 = 0;
   int T0, T1, T2, T3, T4, T5;   
   
   int x=0, t = shift;
   while(x<6)
   {
     if( P0>0 ) { P5=P4; P4=P3; P3=P2; P2=P1; P1=P0; T5=T4; T4=T3; T3=T2; T2=T1; T1=T0; }
     P0=iCustom(Symbol(),Period(),"ZigZag",5,5,3,0,t);
     T0=t;
     ObjectDelete(GetName("s",T0));
     ObjectCreate(GetName("s",T0), OBJ_TEXT, 0, Time[T0], P0);
     ObjectSetText(GetName("s",T0), P0, 8, "Times New Roman", Color_Text);

     if(P0>0) {x++;}
     t++;
   }
 

Once I worked on this. One call of ZigZag calculates the whole buffer array, you can add a function at the end

of the main loop of ZigZag which finds the elements you need in the array. You can then pass on the values with say GVs.

 
Thanks for the replies!
Reason: