Get hi/lo yesterday of a specific candle

 

HI,


could you help me with this? I need for every candle in OnCalculate event, to know the high and low of yesterday, relative to this candle.


If I use this 

      double highestY = iHigh(Symbol(),PERIOD_D1,1);
      double lowestY = iLow(Symbol(),PERIOD_D1,1);

I'm getting the yesterday hi/lo for all candles, but not the yesterday hi/lo of the specific candle


I don't find the way to do it


Thank you

 
israelhernando: could you help me with this? I need for every candle in OnCalculate event, to know the high and low of yesterday, relative to this candle. I'm getting the yesterday hi/lo for all candles, but not the yesterday hi/lo of the specific candle. I don't find the way to do it

Please note that the following code is untested and it does not check if the shift/index is valid and if within the Bars indexing range. You will have to add the necessary code to check for that.

int
   dayIndex = iBarShift( _Symbol, PERIOD_D1, time[ i ]    );
double
   highestY = iHigh(     _Symbol, PERIOD_D1, dayIndex + 1 ),
   lowestY  = iLow(      _Symbol, PERIOD_D1, dayIndex + 1 );
 

great, sometimes it does rare things, but it works fine

I'll revise 

thank you

 

I've seen the problem is the sundays



The mondays, the range is calculated with the range of sunday ....

 

I fixed this, by getting the weekday, and finding the correct day


      int
         dayIndex = iBarShift( _Symbol, PERIOD_D1, time[i], true);

      MqlDateTime stm;
      TimeToStruct(time[i],stm);
      
      int dif;
      if (stm.day_of_week == 1)
         dif = 3;
      else if (stm.day_of_week == 7) 
         dif = 2;
      else
         dif = 1;
      
      double
         highestY = iHigh(_Symbol, PERIOD_D1, dayIndex + dif),
         lowestY  = iLow(_Symbol, PERIOD_D1, dayIndex + dif);

I don't know if this is the best way, but it seems work.


Thanks

Reason: