Multiple Time Frames for same EA

 

Hello,


I am a newbie to this forum so apologies in case this have been solved already (I have tried to search before asking but haven't found an aswer I am happy with).


I am trying to see how to best code an algo that will look at different time frames (TF). For instance, you may enter with a signal on the 30min chart and exit with a signal on the 5min chart. So you need to be constantly looking at different TFS.


On MetaTrader you drop the EA on a single chart so I was thinking that in order to have multiple TFs I could do:


1) Drop the EA on a 5min chart. The algo can then look at the different 5min candles or group 6 candles to get the 30 min value

2) Drop the EA on a 5min graph and a 30min graph. Then you can open and close positions (the 5min EA will close any position the 30min EA will open).


Now, I think there should be an easier way of doing that. After al MQL was created with the trader in mind so why wouldn't there be an easy way of mixing diffrent TFs.


Thanks so much for your help guys,


Yona

 

Hello,

Have a look to https://docs.mql4.com/series/iLow

 

Thanks Jacques,


So if I got it right, I will have something like (I am not doing perfect syntax here):


For the 5min indicator:

LOWPrice5= ilow(Symbol, PERIOD_M5, 0)

CLOSEPrice5 = iclose(...)

OPENPrice5 = ...

etc.


For the 30min

LOWPRice30=ilow(symbol, PERIOD_M30, 0)

etc.


However, what happens if I drop this on a 5min chart? Lets say on T=5min the previous OPEN is T=0min (because we are looking at PERIOD_M5). When the next tick comes at T=5min:1sec: Is the OPEN still T=0min (and won't change until T=10 in which case OPEN will be the one for T=5min)? Or will it be the OPEN of T=0min:1sec?


I suppose that the use of PERIOD_XX is to avoid this case of scenarios (so at T=5min iLow(symbol, PERIOD_M5, 1) is the same that at T=5min:Xsec and will only change at T=10min).

Reason: