Filtered ATR using an array

 

Hi everyone, I'm still a noob so please excuse errors. 

I'm trying to calculate ATR of 1H based only on certain candles defined by input. For example if input are 8,18 and 10, then the code will calculate the true range of all 1H candles from 08:00 AM to 18:00 AM in the last 10 days and then it will calculate the average of all stored values. 

What I tried to do was:

// Setup
#property copyright "ironhak"
#property description "Indicate current candle open"
#property strict
#property show_inputs
#property indicator_chart_window

// Define number of buffers
#property indicator_buffers 1

input string   none_1            = "------------------------";       //Indicator Parameters
input int i_lnStart                   = 8;     // London session start
input int i_lnFinish                  = 18;    // London session finish

// Initialisation event handler
int OnInit(void)
  {
   return INIT_SUCCEEDED;  // Successful initialisation of indicator
  };

// Calculation event handler
int OnCalculate(
   const int      rates_total,
   const int      prev_calculated,
   const datetime &time[],
   const double   &open[],
   const double   &high[],
   const double   &low[],
   const double   &close[],
   const long     &tick_volume[],
   const long     &volume[],
   const int      &spread[]
)
  {
   double atr_Array[]; //array where all TR values will be stored
   
   int lookback = 100;  //just here for example, if i'm on m1 it will go trough last 100 minutes
   for(int iBar = Bars-1-MathMax(lookback, prev_calculated); iBar >= 0; --iBar)
     {
     
      int index_Hsession = iBarShift(0,60,Time[iBar-1],false); //retrive 1H index candle given current TF one
      int index_atrArray = -1; //array index counter         
     
      if(TimeHour(Time[iBar-1])>i_lnStart && TimeHour(Time[iBar])<=i_lnFinish && TimeHour(Time[iBar-1])!=TimeHour(Time[iBar])){ 
        // If current candle hour is between the choosen hour range, and if current candle hour is different than the last one (this last condition is in order to consider 1H candle only one time, if I was on 1m I don't want 60 times the same TR value of current 1H candle
        index_atrArray++;
        
        double atr = iHigh(0,60,index_Hsession)-iLow(0,60,index_Hsession);
        ArrayFill(atr_Array,index_atrArray,1,atr);
      }
     };

   return rates_total-1;
  };

This is how far I got and apparently no values are getting stored inside the array or the code actually stop working because if I try to put the atr_Array inside an alert nothing happen and no values are being displayed. Can someone please point me out my errors? Thanks. 

 

Easier than I thought, for anyone curious:

   double adr[];
   int period=2; //Number of days to analyse (must run the indicator on TF<=60m)
   Alert("");
   Alert("");

   Alert("------");
   ArrayResize(adr,10*period); //10 hours a day to be averaged times the numbers of days
    int array_index;
   
   for(int i=1;i<24*period+1;i++){ // 24 1H candles to go trough times the numbers of chosen days
  
   if(TimeHour(iTime(0,60,i))>=8&&TimeHour(iTime(0,60,i))<18) //If index time is between desidered hour range then fill array with TR values of 1H candles
     {
    
      Alert("");
      Alert(iTime(0,60,i));
      Alert("High: "+iHigh(0,60,i)); 
      Alert("Low: "+iLow(0,60,i));
      adr[array_index] = iHigh(0,60,i) - iLow(0,60,i);
      Alert("Index n. "+array_index+" ATR: "+adr[array_index]);
      array_index++;
     }

From there it's quite easy to find an average of all array values.