getting hourly range in a day and over x days

Dua Yong Rew  

Hi all,

I need to get the hourly range High - Low of a day and over x days.

I written a sample to get daily range, how do I modify to get hourly range for a day and over x days?

   double   low  = 0,
            high = 0,
            total = 0,

            adjustPT;

   for(int i = 0; i < SymbolsTotal(1); i++)
   {
      total = 0;

      adjustPT = SymbolInfoDouble(SymbolName(i, 1), SYMBOL_POINT);

      for(int x = 1; x <= count; x++)
      {
         low  = iLow(SymbolName(i, 1), PERIOD_D1, x);
         high = iHigh(SymbolName(i, 1), PERIOD_D1, x);

         total += (high - low) / adjustPT;
      }

      Print(SymbolName(i, 1) + "," + DoubleToString(total / count));
Ahmet Metin Yilmaz  
Dua Yong Rew :

Hi all,

I need to get the hourly range High - Low of a day and over x days.

I written a sample to get daily range, how do I modify to get hourly range for a day and over x days?

Use the barshift function to get information about a specific bar

William Roeder  
  1. Dua Yong Rew: I written a sample to get daily range, how do I modify to get hourly range for a day and over x days?

    Why not just call iATR?

  2. Dua Yong Rew: I need to get the hourly range High - Low of a day and over x days.

    That you have to code yourself.

    Not tested, not compiled, just typed.

    double ave_range_hour(int count, int hour){
       datetime when = date() + hour*PeriodSeconds(PERIOD_H1);
       double   sum=0; int n=0;
       while(n < count){
          int      iBar=iBarShift(_Symbol, PERIOD_H1, when, true);
          if(iBar >= 0)){
             sum  += iHigh(_Symbol, PERIOD_H1, iBar)
                   -  iLow(_Symbol, PERIOD_H1, iBar);  ++n;
          }
          when -= PeriodSeconds(PERIOD_D1);
       }
       return sum / count;
    }

    Not tested, not compiled, just typed.

              Find bar of the same time one day ago - MQL4 programming forum #1 & #6 (2017)