Multiple timeframes?

 

G'day from downunder,

Firstly, is it possible for the EA to control the timeframe (hour, day, etc.) or does the EA use the timeframe of the underlying chart? In other words, can an EA running on a 5-minute chart be using a one-hour timeframe for its decision making?

If it is possible for the EA to control the timeframe, is it possible to have multiple timeframes? Using Moving Average (MA) as an example (it's easy to understand), is it possible to write code that will buy when the crossover is in the right direction based on 5-minute and one-hour timeframes? If someone could show me the one line of code using two timeframes, that would be magic!!

Finally, and not related to the subject line, will code written in MQ5 work in MetaTrader 4?

To put things in perspective, I've been writing trading systems for 40 years, but only started using MetaTrader three days ago. There's so much that I "need" to learn very quickly and I'm frustrated.

All the best in 2012!

Chuck Rademacher
Auckland, New Zealand

 

The simple answer to all your questions is yes - see https://book.mql4.com//. You have total control of timeframes (higher and lower) from your EA.

As for MQL5 code working in MQL4, the answer is no.

 
ChuckNZ:

G'day from downunder,

Firstly, is it possible for the EA to control the timeframe (hour, day, etc.) or does the EA use the timeframe of the underlying chart? In other words, can an EA running on a 5-minute chart be using a one-hour timeframe for its decision making?


You can use iClose, iHigh, iLow, iOpen to retrieve a single price at a time for a specified time frame.
double iClose( string symbol, int timeframe, int shift)

By specifying symbol as NULL and looping through shift, you will get a series of prices at a desired time frame.

If you think the above method is clumsy, there is a better way of getting time series data at desired time frame by calling ArrayCopyRates(...). As the documentation said "Memory is not really allocated for data array, and no real copying is performed. When such an array is accessed, the access will be redirected. ", it shouldn't have overhead.

Reason: