icustom ZigZag - page 5

 

hello guys, anyone knows how can I save the values in arrays, and access them through their index?


I just solved my inquiry and post here for anyone interested.

void OnStart()
  {
   int zigzag_counter = 0;
   int zigzagfinder = 0;
   double zigzag_array[10];
   ArrayInitialize(zigzag_array,0);
   while(zigzag_counter<10)
     {
      double zigzag_0=iCustom(NULL, 0, "ZigZag", 0, zigzagfinder);
      if(zigzag_0>0)
        {
         zigzag_array[zigzag_counter] = zigzag_0;
         zigzag_counter++;
        }
      zigzagfinder++;
     }
   Print(zigzag_array[1]);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+

you can access the values on the array based on the index. 

Thank you.

 

c0d3:
I'm trying to determine direction of zigzag indicator with the icustom command.

This is what i have so far:

ZigZagHigh=iCustom(NULL,0,"ZigZag",MODE_HIGH,0);
ZigZagLow=iCustom(NULL,0,"ZigZag",MODE_LOW,0);

The lines are drawn on the chart, but both ZigZagHigh and ZigZagLow are equal to zero when I run the program.




How would i determine the trend of the ZigZag indicator with the icustom function?


Thanks



this will search 100 previous candles in M5 and print all 

for( int i =0;i<100;i++){

      double zv=iCustom(Symbol(),PERIOD_M5,"zigzag",0,i);
      if(zv !=0) Print("value zigzag ",i," = ",DoubleToStr(zv,5));

  }    

result is as follows :

2022.09.29 05:00:36.966 BBK_test1_zigzag EURUSD,M5: value zigzag 4 = 0.96866

2022.09.29 05:00:36.966 BBK_test1_zigzag EURUSD,M5: value zigzag 47 = 0.97379

2022.09.29 05:00:36.966 BBK_test1_zigzag EURUSD,M5: value zigzag 72 = 0.97210

2022.09.29 05:00:36.966 BBK_test1_zigzag EURUSD,M5: value zigzag 80 = 0.97504

 

Hi there!


So I have taken code previously written here and changed it a little bit so it just identifies the 2 last ZigZags... 

So... p1 is the latest one, and it is still redrawing, but p0 is the one before that, and it will change into p1 as soon as the direction of the price changes...

my question is.. what do I need to do so that when a certain action is made, exactly at the time when these two switch places?


Here is the code:

void OnTick()
{
        int n = 0;
        int shift = 0;
        double p0 = 0; 
        double p1 = 0; 

        while(n<2)
        {
               	if( p0 > 0) 
                {
                        p1=p0;
                }
                p0=iCustom(Symbol(),0,"zigzag",ExtDepth,ExtDeviation,ExtBackstep,0,shift);
                if(p0 > 0) 
                {
                        n+=1;
                }
                shift++;
        }
        Comment("Price 0 : ",p0,", Price 1 : ",p1);
}
 
Dimitri Mikhalev #: Here is the code:
Simplify, generalize, and refactor.
void OnTick()
{
   double p[2]; GetZigZag(p);
   Comment("Price 0 : ",p[0],", Price 1 : ",p[1]);
}
void GetZigZag(double& p[], int shift=0, int c=WHOLE_ARRAY){
   int n = 0; if(c==WHOLE_ARRAY) c=ArraySize(p);
   while(n<c){
      double v=iCustom(Symbol(),0,"zigzag",ExtDepth,ExtDeviation,ExtBackstep,0,shift);
      if(v > 0) p[n++]=v;
      ++shift;
   }
}
Reason: