Can someone help with this code, been driving me nuts

 

So this is what I have:

a custom indicator displaying on a chart the values of two standard indicators ATR and MA.

MA on the current chart time frame,  no problems, but the ATR is supposed to be for the higher timeframe i got it this far:

  for(int i=startIndex; i<rates_total && !IsStopped(); i++){

    //read values from the ATR handleATR handle pointing to a higher time frame
    int shift = ???? //how do i get the shift here i miss the good old iBarShift
    int atrRead = CopyBuffer(handleATR,0,shift,1,ATRValue);
    int maRead = CopyBuffer(handleMA,0,(rates_total-i),1,MovingAverageValue);


 I tried to use the iBarShift library on https://www.mql5.com/en/code/1864 didn't work for me, i need to pass the time and how do i get the time in this loop?

iBarShift
iBarShift
  • votes: 31
  • 2013.10.25
  • Alain Verleyen
  • www.mql5.com
There is a lot of users who searched for iBarShift function like in MQL4. But this function is no more include in MQL5, mainly because MQL5 provides all necessary basic, low-level, functions to process such thing in a library.
 

Try iBarShift(NULL/*current symbol*/, 0 /*current Period()*/, time[i]). If you want to use a period other than current Period() you should calculate it yourself, because the notion of "higher timeframe" may be specific to your use case and requirements.

Here is an example how you can calculate higher timeframes - https://www.mql5.com/en/code/2226 

Change Chart and Timeframe
Change Chart and Timeframe
  • votes: 6
  • 2014.06.06
  • eselstreckdich
  • www.mql5.com
Modified scripts to change Charts(next,previous) and Timeframes(higher,lower) of all charts quickly by hotkeys.
Reason: