take the chart's time frame and go 1 time frame higher

 

What code do you use to

1) find out what the chart's current time frame is (M1,M5,M15,M30,H1,H4,D1 or MN1)

2) go 1 time frame higher: so if the chart right now is M30, use H1 in the code?

This could work for every indicator, but for example with RSI, if you put it on a M30 chart, it becomes

buf[i]=iRSI(0, PERIOD_H1,10,0,iBarShift(NULL,PERIOD_H1,Time[i]));

 

Hi MrH, for the current time frame you can use Period( )

https://docs.mql4.com/windows/period

 

to change timeframe:

https://forum.mql4.com/29052

didnt tested, just found it.

 

I would have an array with available time frames then in the init() determine the next time frame:

int timeFrame[] = {1,5,15,30,60,240,1440,10080,43200},nextTF;

int init()
{
for(int i=0;i<ArraySize(timeFrame);i++){
if(i==ArraySize(timeFrame)-1){nextTF=timeFrame[i];Print("Sorry maximum time frame reached");break;}
if(timeFrame[i]==Period()){nextTF=timeFrame[i+1];break;Print("i "+i);}
}
}
 
Interesting, thank you all for the advice.
Reason: