EA & indicator with multiple timeframes?

 

Hi all,


I've read thru the MQL4 documentation and it all seem'd to be quite straightforward for developing own EA's or indicators. Anyway, I couldn't find any documentation on how to develope an EA or an indicator that would use data and from multiple time frames, for example 5M, 30M and 4H.


Usually an indicator is attached to a data window with one specific timeframe, so is it anyhow possible to develope an indicator that would show data from many timeframes?


Also, when some EA is started it is attached to some data windows with just on time frame selected. And, when using optimizer I once again must select just one time frame from the menu. So is it anyhow possible to develop an EA that uses information from many indicators with different timeframes?

 

AP


You can indeed get data from indicators on other timeframes (or even other pairs) - its a very good basis for checking trends.

Some example code that could be called in, say, an EA on an M5 chart


//============================ INFO FROM OTHER PERIODS/INSTRUMENTS =======================================
double EMA_D_5_1 = iMA(strSymbol,PERIOD_D1,5,0,MODE_EMA,PRICE_CLOSE,1);
double EMA_D_5_0 = iMA(strSymbol,PERIOD_D1,5,0,MODE_EMA,PRICE_CLOSE,0);
double EMA_D_20_0 = iMA(strSymbol,PERIOD_D1,20,0,MODE_EMA,PRICE_CLOSE,0);

double EMA_H1_5_1 = iMA(strSymbol,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,1);
double EMA_H1_5_0 = iMA(strSymbol,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,0);
double EMA_H1_20_0 = iMA(strSymbol,PERIOD_H1,20,0,MODE_EMA,PRICE_CLOSE,0);

//============================ INFO FROM OTHER PERIODS/INSTRUMENTS =======================================

Good luck

-BB-

 
BarrowBoy:

AP


You can indeed get data from indicators on other timeframes (or even other pairs) - its a very good basis for checking trends.

Some example code that could be called in, say, an EA on an M5 chart


//============================ INFO FROM OTHER PERIODS/INSTRUMENTS =======================================
double EMA_D_5_1 = iMA(strSymbol,PERIOD_D1,5,0,MODE_EMA,PRICE_CLOSE,1);
double EMA_D_5_0 = iMA(strSymbol,PERIOD_D1,5,0,MODE_EMA,PRICE_CLOSE,0);
double EMA_D_20_0 = iMA(strSymbol,PERIOD_D1,20,0,MODE_EMA,PRICE_CLOSE,0);

double EMA_H1_5_1 = iMA(strSymbol,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,1);
double EMA_H1_5_0 = iMA(strSymbol,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,0);
double EMA_H1_20_0 = iMA(strSymbol,PERIOD_H1,20,0,MODE_EMA,PRICE_CLOSE,0);

//============================ INFO FROM OTHER PERIODS/INSTRUMENTS =======================================

Good luck

-BB-


Oh, it was that easy in EA... Thank you very much BarrowBoy!


But then, what is the point that you must select a time period for EA when running it on the tester? How does it effect on the EA, or does it actually?


And, if I create my own indicator, can I draw candles from many time patterns to the chart?

 
AlliumPorrum:
BarrowBoy:

AP


You can indeed get data from indicators on other timeframes (or even other pairs) - its a very good basis for checking trends.

Some example code that could be called in, say, an EA on an M5 chart


//============================ INFO FROM OTHER PERIODS/INSTRUMENTS =======================================
double EMA_D_5_1 = iMA(strSymbol,PERIOD_D1,5,0,MODE_EMA,PRICE_CLOSE,1);
double EMA_D_5_0 = iMA(strSymbol,PERIOD_D1,5,0,MODE_EMA,PRICE_CLOSE,0);
double EMA_D_20_0 = iMA(strSymbol,PERIOD_D1,20,0,MODE_EMA,PRICE_CLOSE,0);

double EMA_H1_5_1 = iMA(strSymbol,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,1);
double EMA_H1_5_0 = iMA(strSymbol,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,0);
double EMA_H1_20_0 = iMA(strSymbol,PERIOD_H1,20,0,MODE_EMA,PRICE_CLOSE,0);

//============================ INFO FROM OTHER PERIODS/INSTRUMENTS =======================================

Good luck

-BB-


Oh, it was that easy in EA... Thank you very much BarrowBoy!


But then, what is the point that you must select a time period for EA when running it on the tester? How does it effect on the EA, or does it actually?


And, if I create my own indicator, can I draw candles from many time patterns to the chart?




Can't anyone help with those last two questions..?

 

Tester only makes test data from one timframe (I think).

Yes, you can draw candles for many timeframes manually.

 
phy:

Tester only makes test data from one timframe (I think).

Yes, you can draw candles for many timeframes manually.

Are we actually saying that there is no way of backtesting an EA using multiple timeframes ?

If that is true, I think we have a major flaw in this otherwise excellent software.....

 
gmack:

Are we actually saying that there is no way of backtesting an EA using multiple timeframes ?

If that is true, I think we have a major flaw in this otherwise excellent software.....

I know this is possible. Just have not figures it out yet..

 

AP

> no way of backtesting an EA using multiple timeframes

Typically the EA will operate on one chart at one timeframe, other timeframes can be referred to at anytime in the code

You can still backtest just fine - indeed I would wonder about an EA that had no reference to other timeframes.....

> And, if I create my own indicator, can I draw candles from many time patterns to the chart?

These do not have to be visualised, just the relevant values calculated in the indicator and/or EA as if they were on the chart

FWIW

-BB-

 
Have you guys developed an indicator for this you would share?
 

Do you really expect them to reply after 10 years. Don't resurrect old threads without a very good reason.

Go to the code base and search for multi-timeframe (MTF) indicators.

Tester works fine for at least 8 years.
Reason: