Help with my expert advisor

 

I'm trying to program my first expert advisor..

And I want to use 2 indicators. -- MACD and Stochastic..

I want to use them on 2 different time periods. --

The MACD on daily chart (iMACD(1440,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0))

and the Stochastic on 1 hour chart (iStochastic(60,0,5,3,3,MODE_SMA,0,MODE_MAIN,0)).

I want to set the buying and selling signals using the results of those two indicators.

In back-testing, I'm supposed to establish the period of back-testing -- And I cannot choose both daily chart for MACD and also hourly chart for Stochastic.

If I'm using back-testing on the Daily chart, MetaTrader loads both the MACD and the Stochastic with daily parameters (AND I DON'T KNOW WHY...), and thus, I cannot use different time periods. -- I have tested the stochastic with both the 60 minutes time interval and 1440 time interval and obtained the same resuts (

Does anyone know:

1. How I can perform back-testing for 2 different time periods for the 2 indicators I want to use in my EA?

2. If I'm using this kind of expert advisor in forward testing, when comparing the results of the indicator, MetaTrader shall use the time periods stated by me in the EA code, or it shall use the time period of the chart the EA is set on?

 
daniel.tiru:
I'm trying to program my first expert advisor..

And I want to use 2 indicators. -- MACD and Stochastic..

I want to use them on 2 different time periods. --

The MACD on daily chart (iMACD(1440,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0))

and the Stochastic on 1 hour chart (iStochastic(60,0,5,3,3,MODE_SMA,0,MODE_MAIN,0)).

Daniel,

Function call is wrong. The first parameter is the currency pair and the second parameter is the time frame. The defaults are NULL-Current chart (first parameter) and 0-current chart time frame (second parameter).

Change your code,

iMACD(1440,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0)

iStochastic(60,0,5,3,3,MODE_SMA,0,MODE_MAIN,0)

To

iMACD(NULL,1440,12,26,9,PRICE_CLOSE,MODE_MAIN,0)

iStochastic(NULL,60,5,3,3,MODE_SMA,0,MODE_MAIN,0)

Hope it helps.

 

PERIOD_D1

PERIOD_H1

Try those instead of 1440 and 60. I use them and they work.

 
fxd01:
Daniel,

Function call is wrong. The first parameter is the currency pair and the second parameter is the time frame. The defaults are NULL-Current chart (first parameter) and 0-current chart time frame (second parameter).

Change your code,

iMACD(1440,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0)

iStochastic(60,0,5,3,3,MODE_SMA,0,MODE_MAIN,0)

To

iMACD(NULL,1440,12,26,9,PRICE_CLOSE,MODE_MAIN,0)

iStochastic(NULL,60,5,3,3,MODE_SMA,0,MODE_MAIN,0)

Hope it helps.

Thanks a lot..

It seems it's working.. (I mean, -- I get different results .. if I use the daily and hourly charts)

but the .. the EA still loses money.. --- I need to learn more to make it work.

Thank you

 

Hi!

never use current bar in your ea (last parameter - shift). You should use at least last closed bar: shift - 1. In other case your tests won't be valid

Reason: