Trying (and failing) to create a simple EA...appealing to all FXDreema gurus!
-
Hi All,
I really hope someone can help me with this! I am trying to create what I think should be a relatively simple EA (for the M15 chart) that does the following:
Executes a BUY trade when all the following conditions are true of the previous candle close:
- Previous candle is a bull candle
- The previous bull candle closed above the slow EMA
- On previous candle close the MACD histogram bar is above the 0.00 line
- On previous candle close the MACD histogram bar is above the MACD signal line.
Like this:

Exits the BUY trade when the following condition is true of the previous candle close:
- On previous candle close the MACD histogram bar is below the MACD signal line, like this:

Executes a SELL trade when all the following conditions are true of the previous candle close:
- Previous candle is a bear candle
- The previous bear candle closed below the fast EMA
- On previous candle close the MACD histogram bar is below the 0.00 line
- On previous candle close the MACD histogram bar is below the MACD signal line.
Like this:

Exits the SELL trade when the following condition is true of the previous candle close:
- On previous candle close the MACD histogram bar is above the MACD signal line
Your help would be massively appreciated!!!!
Many thanks for taking a look,
Andrew
-
@SirBoyce Something like this maybe?
Haven't done much testing but the basics should be fulfilled.
-
@trader-philipps Thanks man! Let me look into that and see what I can see!!!
-
@trader-philipps OK, I've taken a look....and it's actually very similar to what I had done. The main difference appears to be the inclusion of the Once Per Bar blocks. I have to admit I don't really understand those (I'm new here!) but will have another go and hopefully that and a few parameter checks might actually work! I'll let you know how I get on. Thanks ever so much for this.
-
The 'Once per bar' block is the way to stop your EA to be executed on every tick arriving to the platform. This is a common mistakes for rookies, don't worry about that. This of it as a funnel concentrating what you want the EA to do in a more controlled way.
-
@l-andorrà Thanks!
-
@trader-philipps Hi there. The EA you sent me was a big big help. Thanks so very much, I learned a lot. However, despite a few tweaks my end it still didn't perform as expected, particularly with regards to exiting positions.
I'm now trying to take things one step at a time and simply trying to get a BUY to ENTER TRADE on the desired MACD conditions....when 15min candle has CLOSED and has closed displaying the following conditions:
- MACD Main is above 0.000000 value...
- AND when MACD Main is above the MACD Signal line

When I back tested the above (and when I changed the candle ID to 0, as well) it's clear its entering buy trades when the MACD Main line at candle close is below the Signal line, and even when the candle close is below the 0.00 Line:

Why would this be happening?
Cheers!
-
@sirboyce Switch back to candle ID 1, please! It will help to understand what's printed on the chart and what EA did better.
However, if you don't want a new trade each bar that the conditions are met, you should put a no trade block in front. It's that what you are complaining about? -
@trader-philipps Hello again! Thanks for all your help on this, it is very much appreciated. I'm getting there I promise

The no trade block was not the issue I was trying to resolve, I simply wanted to see that the buys were entering on the conditions I had set. However, your advise to switch the candle ID was spot-on.
It is clear from testing that a close trade on MACD main to (on a BUY, for example) below the MACD signal line is not ideal, and I am now thinking a trailing stop is the way to go to close out any trades (on testing my market entry is good but the MACD retrace is stopping me out of many trades before they have a chance to 'mature' and is also closing trades at a loss in temporarily ranging markets with lots of short-term up and down MACD movement).
For my BUY EA, Instead of the condition of trade close being MACD Main below MACD Signal line on previous candle close, if I wanted to use instead a trailing stop - with the initial stop less set at, say, 15 pips - and so that every time the price moves up 15 pips the stop loss shifts up by the same amount, would you mind telling me if the following parameters are correct and also where the Trailing Stop block should be placed in the EA chain???

Thanks again for all the amazing advice!
-
Could you please share your project instead of just showing a screenshot? Many relevant information is within the blocks.
-
@l-andorrà Not sure I follow. All I want to know is where should the trailing stop block be placed in the previous screenshot to enable the buy trade close to be triggered by it, and what parameters for that block to set the stop loss on trade open at 15 pips below, and trail the price moving up by 15 pips at a time. How do I share a project anyway?
-
@sirboyce The trailing parameters look good. For trailing step I"d use a higher value such as 1 or 2 in that case cause I don't like too many order modifications.
You might also consider to user atr or a multiplier of it as a trailing distance. In order to give more room on volatile market conditions. -
@trader-philipps Hi there. I can't get this to work properly. All I want is for a buy to open when - upon a bull candle close - the candle closes above the slow EMA & the MACD main has crossed from below to above the MACD 0.00 line & above the MACD signal line. When the buy opens, I want a stop loss of 15 pips below automatically, and for every 15 pips the price rises during the open trade...the stop loss to move up by 15 pips.
I had the buy opening conditions working fine, but introducing the stop loss has produced some crazy results on testing (some orders open with what appears to be a stop loss, others don't etc.).
If you can show me how to share my project with you, could you just show me how to do this? That would be greatly appreciated!
Thanks.
-
@sirboyce You can share a link so we can see the specifics of the blocks which is the proper way to diagnose the problem. Go to "projects" and then click on "create a shared copy (web link)" then post that link in this thread.
-
@trader-philipps Just for your reference, with Trailing Stop set at 15, Trailing Step at 10, and Trailing Start at Open Price, here are some screens from testing 2nd September to 25th September:
First Buy Open (should have hit a 15 pip stop loss, conditions for a profitable buy missed later on):

Buy conditions met but no Trade (would have hit TP):

No S/L on Open:

Apparent correct Buy Open, Trailing S/L and TP Reached:

-
@line Gotcha. Thanks!
-

-

-
Try those changes and see if it works.
-
Made some mods on it and it made some profit.