MQL4 Custom Indicator

 
Hi, does anyone know why Alert(array1[]) is showing values of 0? Even though LineBuffer1 is plotting the line correctly with values. Thanks #property indicator_separate_window //#property indicator_minimum 0 //#property indicator_maximum 1 #property indicator_buffers 1 #property indicator_plots   1 //--- plot line1 #property indicator_label1  "line1" #property indicator_type1   DRAW_LINE #property indicator_color1  clrRed #property indicator_style1  STYLE_SOLID #property indicator_width1  1 //--- indicator buffers input int AveragingPeriod = 20; extern int History  =400;            // Amount of bars in calculation history double array1[400];
double line1Buffer[];
//+------------------------------------------------------------------+ //| Custom indicator initialization function                         | //+------------------------------------------------------------------+ int init()   { //--- indicator buffers mapping    SetIndexBuffer(0,line1Buffer);    ArraySetAsSeries(array1,true); //---    return(INIT_SUCCEEDED);   } //+------------------------------------------------------------------+ //| Custom indicator iteration function                              | //+------------------------------------------------------------------+
//+------------------------------------------------------------------+ int start()                            // Special function start()   {    int i,                              // Bar index        n,                              // Formal parameter (index)        k,                              // Index of indicator array element        Counted_bars;                   // Number of counted bars        double        high;                            // High and Low sum for the period //--------------------------------------------------------------------    Counted_bars=IndicatorCounted();    // Number of counted bars    i=Bars-Counted_bars-1;              // Index of the 1st uncounted    if (i>History-1)                    // If too many bars ..      { i=History-1; }                    // ..calculate for specified amount.      while(i>=0)                         // Loop for uncounted bars      {      array1[i] =iBands(NULL,NULL,20,2,0,0,1,i) - iBands(NULL,NULL,20,2,0,0,2,i);           if(array1[i]>high) {high= array1[i];}                        line1Buffer[i] = array1[i]/high;       if(i=20)       {       Alert(array1[22]); // showing value of 0       Alert(array1[10]); //showing value of 0       break;}         i--;                             // Calculating index of the next bar      } //--------------------------------------------------------------------    return;                             // Exit the special funct. start()
 

Alert(array1[10]) equals to zero makes sense because at i = 20 it has not calculated the index 10 yet

for the other one i dunno it should work

 
  1. Hi, does anyone know why Alert(array1[]) is showing values of 0? Even though LineBuffer1 is plotting the line correctly with values.
    
    Thanks
    You typed your comments inside SRC block and made it non-SRC

    Please edit your (original) post and use the CODE button (Alt-S)!
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?