Multi Time Frame Backtest Analysis/Coding with MQL4

To add comments, please log in or register
biggy8133
13
biggy8133  
Dear MQL4 developers,

What would be best practice to develop pattern recognition EA which is looking on multiple time-frames at same time?

My goal is to find candle pattern (using OHLC prices) on H1 chart and at the same time want to check for same pattern in H4.  If/when both patterns are found, then that is my entry signal.


Also it's required to be able to back-test.

Possible Solution:   I think could work is to run EA on H1 and simply aggregate H1 candles to get H4 candle.     Is this the only approach ?     or is there another better
suggested method of achieving multi time-frame trading with MQL4/MT4 ?


Thanks,

NG

lippmaje
373
lippmaje  

You could retrieve the values with iHigh/iLow etc on PERIOD_H4 like this:

int shift=0;
double o=iOpen(NULL,PERIOD_H4,shift);
double h=iHigh(NULL,PERIOD_H4,shift);
double l=iLow(NULL,PERIOD_H4,shift);
double c=iClose(NULL,PERIOD_H4,shift);
biggy8133
13
biggy8133  
lippmaje:

You could retrieve the values with iHigh/iLow etc on PERIOD_H4 like this:

Thanks for your reply Lippmaje.  I guess my first question is, is it possible to run  a code on two different timeframes/candle stick charts at the same exact time with MQL4, and have them work together(without aggregating data from a lower time frame to create the higher time frame candles) ?
lippmaje
373
lippmaje  
biggy8133:
Thanks for your reply Lippmaje.  I guess my first question is, is it possible to run  a code on two different timeframes/candle stick charts at the same exact time with MQL4, and have them work together(without aggregating data from a lower time frame to create the higher time frame candles) ?
Yes, this should work both with MT4 and 5. Just run your EA on the lower timeframe. The calls above will return the right values. But be aware that the higher timeframe is still bound to its resolution. That is you get a new value for H4 only on 8:00 12:00 16:00 etc but not on 11:00. PERIOD_H4 does not mean 'for the last 4 hours', rather it's aligned with the time of day's hour modulo 4. And you are not running an EA against two different charts. Don't mix charts with timeframes. You are running an EA on exactly one chart object and you're able to make modifications to it such as drawing lines etc. But your EA is free to access candles of any instrument you may need, on any timeframe. You could query M5 candles from EURUSD or M30 candles from AMZN while your EA is sitting on a H1 Nasdaq chart, no problem as long as your terminal got that candle history.
biggy8133
13
biggy8133  
lippmaje:
Yes, this should work both with MT4 and 5. Just run your EA on the lower timeframe. The calls above will return the right values. But be aware that the higher timeframe is still bound to its resolution. That is you get a new value for H4 only on 8:00 12:00 16:00 etc but not on 11:00. PERIOD_H4 does not mean 'for the last 4 hours', rather it's aligned with the time of day's hour modulo 4. And you are not running an EA against two different charts. Don't mix charts with timeframes. You are running an EA on exactly one chart object and you're able to make modifications to it such as drawing lines etc. But your EA is free to access candles of any instrument you may need, on any timeframe. You could query M5 candles from EURUSD or M30 candles from AMZN while your EA is sitting on a H1 Nasdaq chart, no problem as long as your terminal got that candle history.

Thanks for the detailed info.  One other question based on your reply. 

Is it in fact possible to run one EA on two different CHARTS (Not just time frames) at the same time.  This  means your code(EA) could plot data on two different charts (lets say EURUSD H1 and H4) at the same time, and have the charts talk to each other based on the results?

What I need is to run the same logic code(EA) on H1 and H4 and have them both plot the results they obtain on their own respective charts.  Then based on the results that I get from H4, H1 decides whether to enter a trade or not.  Is this scenario possible, and if so what is the best approach?

Thanks in advance for your help.

lippmaje
373
lippmaje  

biggy8133: Is it in fact possible to run one EA on two different CHARTS (Not just time frames) at the same time.  This  means your code(EA) could plot data on two different charts (lets say EURUSD H1 and H4) at the same time, and have the charts talk to each other based on the results?

I think it's impossible to target two different charts with a single EA.

What I need is to run the same logic code(EA) on H1 and H4 and have them both plot the results they obtain on their own respective charts.  Then based on the results that I get from H4, H1 decides whether to enter a trade or not.  Is this scenario possible, and if so what is the best approach?

You could do this with a custom indicator and an EA. The indicator is responsible for updates to the chart drawing and provision of signals. The EA queries the signals from two such indicators (H1/H4) via iCustom and makes the trade decision.

To add comments, please log in or register