Zigzag returns me 0 - page 2

Vladimir Karputov
Moderator
240035
Vladimir Karputov  
ashkankhalaj :

Still it doesn't run when the market is closed. There is no Price Ticking

Correct your mistake first.

ashkankhalaj
52
ashkankhalaj  
Vladimir Karputov:

Correct your mistake first.

int zigzag,xs;
double zigzagDown[];


int OnInit()
  {

   zigzag=iCustom(_Symbol,PERIOD_D1,"Examples\\ZigZag",12,5,3);


   return(INIT_SUCCEEDED);
  }
  
void OnTick()
  {
   CopyBuffer(zigzag,0,0,Bars(_Symbol,PERIOD_D1),zigzagDown);
   ArraySetAsSeries(zigzagDown,true);

   //I Set xs as 1 in order to skip the current Candle in order if the trend is bearish it wont count it
   for(xs=0; xs<Bars(_Symbol,PERIOD_D1); xs++)
     {
      if(zigzagDown[xs]!=PLOT_EMPTY_VALUE && zigzagDown[xs] < SymbolInfoDouble(_Symbol,SYMBOL_LAST))
         break;
     }

   Print(zigzagDown[xs]);

  }  

Ok This would be how it looks.

Vladimir Karputov
Moderator
240035
Vladimir Karputov  
ashkankhalaj :

Ok This would be how it looks.

Errors:

  • indicator handle is not checked - indicator handle SHOULD BE CHECKED
  • in CopyBuffer, 0,0 is a very, very bad habit - you need to accurately write the values
  • Bars - error again: no check.
And the main question remains: WHY GET all the values from the time of birth of dinosaurs to the current moment, if you are essentially looking for the freshest value (on the graph this is the rightmost value)?
ashkankhalaj
52
ashkankhalaj  
Vladimir Karputov:

Errors:

  • indicator handle is not checked - indicator handle SHOULD BE CHECKED
  • in CopyBuffer, 0,0 is a very, very bad habit - you need to accurately write the values
  • Bars - error again: no check.
And the main question remains: WHY GET all the values from the time of birth of dinosaurs to the current moment, if you are essentially looking for the freshest value (on the graph this is the rightmost value)?

I'm writing this code for a new born stock market which the entire history is not much bigger than a thousand bars whit lots of securities with  less than a hundred bars- I mean the entire history. the entire code is much bigger than this and actually it's not gonna end with just the first extremum and it keeps going on and checks the last 5 or 6 highs and lows, my only problem is why on earth I can't get the values of ZigZag extremums with this code also I have other functions which sync the data before calling the ZigZag, and it Ioops through 660 securities which I save them before on an sql file. just wonder why this piece of code which it seems to be as easy as a piece of cake keeps returning me just 0.

ashkankhalaj
52
ashkankhalaj  
By the way I edited the code for your Satisfaction

int zigzag,xs;
double zigzagDown[];


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {

   zigzag=iCustom(_Symbol,PERIOD_D1,"Examples\\ZigZag",12,5,3);


   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(zigzag!=INVALID_HANDLE && Bars(_Symbol,PERIOD_D1)>0)
     {
      CopyBuffer(zigzag,0,TimeCurrent(),Bars(_Symbol,PERIOD_D1),zigzagDown);
      ArraySetAsSeries(zigzagDown,true);
      
      //I Set xs as 1 in order to skip the current Candle in order if the trend is bearish it wont count it
      for(xs=0; xs<Bars(_Symbol,PERIOD_D1); xs++)
        {
         if(zigzagDown[xs]!=PLOT_EMPTY_VALUE && zigzagDown[xs] < SymbolInfoDouble(_Symbol,SYMBOL_LAST))
            break;
        }
     }
   Print(zigzagDown[xs]);
  }  
//+------------------------------------------------------------------+


Vladimir Karputov
Moderator
240035
Vladimir Karputov  
ashkankhalaj :
By the way I edited the code for your Satisfaction


ZigZag can be not only 'PLOT_EMPTY_VALUE', ZigZag can be '0.0'.

ashkankhalaj
52
ashkankhalaj  
Vladimir Karputov:

ZigZag can be not only 'PLOT_EMPTY_VALUE', ZigZag can be '0.0'.

Oh Yesssss I Can see it now. it works as a charm. you are a life saver I can't tell how I'm thankful.

I wish you all the best