Referencing previous ohlc values

 

I do it like this, but it seems a little hackish.  Is there a better way? Thanks.

   for ( int i = bars; i >= 0; i-- )
      {
         Value = high[i-2];

     }


Also, is there a function that adds up the previous X amount of ohlc values?  MathSum is the only one I could find, but it only adds up one entire array, when I want only X number of bars to be calculated.

 
The biggest drawback to this method is that it's highly susceptible to array out of range errors.
 

Anyone?  Is this how everyone does it?

double Value[];
for ( int i = 0; i < rates_total; i++ ) {
         if (i<2){
             Value[i] = 0;
             continue;
             }
         Value[i] = high[i-2];
     }
Sometimes my indicator comes up blank.  I'm not sure if there is another method of doing this.
 
antiseptic: ?  Is this how everyone does it?Sometimes my indicator comes up blank. 
  1. The array has no size, therefor any assignment to it will fail.
  2. Do your lookbacks correctly. and don't process every every tick.