MT4 gurus: How do I access an indicator of a different time frame?

 

Hi,

I came across this problem before and gave up.

Now I've encountered it again while trying to code another indicator. It is a common problem so I'm sure someone must know the answer.

The question is, using iCustom or built in iIndicator functions, how do I access data from another time frame? I know that there is a time frame parameter, and I use it but the problem is that the shift is still from the current chart.

I tried dividing shift by the ratio of the time frames (e.g. 4 for accessing H1 from M15) but that didn't seem to work for me.

example:

CoolIndicator1 is running on M15. It wants to read the value of RSI for current time frame... no problem call iRSI with timeframe of 0 or PERIOD_M15.

But how do I get the value of RSI for this point in time for M30? or H1?

I tried using iBarShift( ) but that didn't work out for me. Sounds like it is the right thing to use though.

So if anyone has any code that could be of use or simply any comments that could point me in the right direction, please post.

thanks!

 

I had the same problem with some indicator's that wouldn't let me read data with iCustom.

There's a way to access all data from anywhere, that is if you are able to locate the variable(s) in the indicator that provide the data. I've been using this method for several months now, and I never missed any data with it. It sounds like a cludge and of course it is, but at least for testing purposes it works. By then you could decide if it's worth while to code a more robust solution.

Simply write te value of the indicator to a file. Then read it with the other indicator or expert. There's an example of this in the standard samples. Name the file with a combination of the indicators name with the timeframe and the symbol to keep them apart.

Maybe this helps (a bit).

 

Take a look at the code in the Price Channel Stop indicator that Igorad made. It should help you with what you are trying to accomplish.

https://www.mql5.com/en/forum/172970

 

thanks... that should come in handy for something in the future, I'm sure.

I think I found the answer to my Q. just now.

http://www.metaquotes.net/forum/1290/

I tried this earlier but my mind was tied up in a knot and I realize now the mistake I made. I was using Open[shift] instead of Time[shift] for the open time parameter in iBarShift.

My brain was kind of on autopilot and in a nosedive :-)

So I'll read the article, try it again and hopefully should work.

 
ycomp:
Hi,

I came across this problem before and gave up.

Now I've encountered it again while trying to code another indicator. It is a common problem so I'm sure someone must know the answer.

The question is, using iCustom or built in iIndicator functions, how do I access data from another time frame? I know that there is a time frame parameter, and I use it but the problem is that the shift is still from the current chart.

I tried dividing shift by the ratio of the time frames (e.g. 4 for accessing H1 from M15) but that didn't seem to work for me.

example:

CoolIndicator1 is running on M15. It wants to read the value of RSI for current time frame... no problem call iRSI with timeframe of 0 or PERIOD_M15.

But how do I get the value of RSI for this point in time for M30? or H1?

I tried using iBarShift( ) but that didn't work out for me. Sounds like it is the right thing to use though.

So if anyone has any code that could be of use or simply any comments that could point me in the right direction, please post.

thanks!

Just create an other indicator with this iRSI((NULL,period, ...) and in the beginning of the indicator (or EA) wrote like this;

extern int period = PERIOD_H1;

 

Hi newdigital,

thanks but that won't work for me... I think that metaquotes link I posted holds the key, I'll find out when I get back to working on this indicator.

Reason: