How do I ??

 

Hello everyone,

How do I write a code based on the example below.

For example:

If current price CLOSE is above EMA 5 HIGH take buy trade

If current price CLOSE is below EMA 5 LOW take sell trade

 
santhoshabraham:

Hello everyone,

How do I write a code based on the example below.

For example:

If current price CLOSE is above EMA 5 HIGH take buy trade

If current price CLOSE is below EMA 5 LOW take sell trade

If(close>EMAhigh)return OP_BUY;
If(close<EMAlow)return OP_SELL;
 
William Brandon Autry #:
If([1]>EMA5)return OP_BUY;
If([1]<EMA5)return OP_SELL;

William thanks for the replay, I am trying to do this.  See the image below. 


 
santhoshabraham #:

William thanks for the replay, I am trying to do this.  See the image below. 


You can get the value of the EMAs using iMA:

* MT4: https://docs.mql4.com/indicators/ima
* MT5: https://www.mql5.com/en/docs/indicators/ima

Then, you can get the value of the previous close using iClose.

Then, compare the values check if they meet your buy / sell criteria.

Also, specify which version of MT you're programming for so it's easier to help you out.

iMA - Technical Indicators - MQL4 Reference
iMA - Technical Indicators - MQL4 Reference
  • docs.mql4.com
iMA - Technical Indicators - MQL4 Reference
 
santhoshabraham #:

William thanks for the replay, I am trying to do this.  See the image below. 


I edited my post. 

You’ll also need to define the lines using iMA and the candle as iClose. 
 
santhoshabraham # :

William thanks for the replay, I am trying to do this.  See the image below. 


Try it: Two iMA High Low Simple

Two iMA High Low Simple

 

Hello Everyone,


I am new to ea's but I am trying out a few courses and trying to get my head around it all.


in the mean time, how do I:-


1. if a position has been opened on say a 4 hour candle, 

and if its still open

or if closed

don't open another position on candle "0"


2. If a position is open on candle "0"

Close the trade on the close of candle "0"


3. Use a trailing stop on whatever position is open. 


If only I understood coding as I do english.... soon, hopefully. Thanks


ps, im learning mt4. for starters

 
1 & 2) Remember the bar time and check if it has changed or not.

For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
          New candle - MQL4 programming forum #3 (2014)

Reason: