Add Moving Average for Trend indicator on EA

 

Hi all,

I need to add a single moving Average to an EA I am using, I will use the moving average to determine if the trend is up or down.

I just need to very simply compare the current candle MA to the last candle MA to give me my 'UP' or 'Down' trend indication (is MA greater or less than last candle MA?)

I'm confident in feeding the UP/Down into my Buy/Sell triggers, but I'm not sure how to add the MA or perform the above calc?

Any help would be much appreciated!

Thanks

Aug

 
augustus: I need to add a single moving Average to an EA ... but I'm not sure how to add the MA or perform the above calc?
Read the book, read the docs especially iMA - MQL4 Documentation
 
WHRoeder:
Read the book, read the docs especially iMA - MQL4 Documentation


Thanks, I'll have a look at iMA and see how I get on.

Aug.

 
augustus:


Thanks, I'll have a look at iMA and see how I get on.

Aug.


I've added a MA ok using iMA, but I'm not sure how to do the below - all the examples I can find are for MA crossovers, where as I want to compare the MA to itself to determine the slope.

I want to effectively be able to do this:

MA[1] > MA[2]


Thanks.

 
augustus:


I've added a MA ok using iMA, but I'm not sure how to do the below - all the examples I can find are for MA crossovers, where as I want to compare the MA to itself to determine the slope.

I want to effectively be able to do this:

MA[1] > MA[2]


Thanks.

a moving average of a moving average
iMAOnArray
 
deVries:
a moving average of a moving average
iMAOnArray

Ah, thanks :)
 
augustus: MA to itself to determine the slope. MA[1] > MA[2]
iMAOnArray is irrelevant - the OP wants the slope. What is the last parameter in iMA? What does your 1 and 2 mean?
 
WHRoeder:
iMAOnArray is irrelevant. What is the last parameter in iMA? What does your 1 and 2 mean?


If I have a 100 SMA moving average, I would like to compare the SMA value 1 candle ago against 2 candles ago, to determine if the slope of the SMA is currently up or down.

Thanks

 
Answer my other question.
 
WHRoeder:
Answer my other question.


The Shift? So I could create two iMA's with a Shift of 0 and 1 respectively, and this would effectively give me the last and second to last values from the moving average? If so, sounds good.

Just an aside, is there any best practice to ensure when using MA's in an EA that you avoid 'looking into the future' when using the strategy tester? If I use a shift of 0 will it always be entirely safe?

Reason: