Array out of range

 

Compiler doesn't get Error but when I attach Indicator to the chart Expert logs Array out of range (116,32)
it means Close[z]

by the way all of calculation of pprice() function correctly is done and it's drawn on the chart, but it doesn't generate any output

//+-------------------------------------------------------------------+
//|                  hlc3 Calculation                                 |
//+-------------------------------------------------------------------+
double pprice(int x)
  {
   ArrayInitialize(HH,EMPTY_VALUE);
   ArrayInitialize(LL,EMPTY_VALUE);
   ArrayInitialize(tClose,EMPTY_VALUE);
   ArrayInitialize(hlc3,EMPTY_VALUE);
   int counted_bar=IndicatorCounted();
   int limit=Bars-counted_bar;
   for(int x=0; x<limit; x++)
     {
         Num_Period    = InpMAPeriod-1;
         z = (InpMAPeriod-1)+x;
         HH[x] = iHigh(Symbol(),PERIOD_CURRENT,iHighest(NULL,0, MODE_HIGH,Num_Period,x)); 
         LL[x] = iLow(Symbol(),PERIOD_CURRENT,iLowest(NULL,0, MODE_LOW,Num_Period,x));
         if ((Close[x] >= Close[z] && Close[x] >= Open[z]) || (Close[x] <= Close[z] && Close[x] <= Open[z]))
         tClose[x] = Close[x];
         else
         tClose[x] = Close[z];
         hlc3[x]=(HH[x]+LL[x]+tClose[x])/3;
     }   
  
      
//---
   return(hlc3[x]);
  }
 
Ashomid7:

Compiler doesn't get Error but when I attach Indicator to the chart Expert logs Array out of range (116,32)
it means Close[z]

by the way all of calculation of pprice() function correctly is done and it's drawn on the chart, but it doesn't generate any output

When x= Bars-1, z will be > Bars and so is out of range.

 
Please edit your post and

use the code button (Alt+S) to paste code.

Don't use an image.

 
Keith Watford:
Please edit your post and

use the code button (Alt+S) to paste code.

Don't use an image.

Thanks, it's working