Need help with the execution of my exact entry/exit
-
Hello everyone!
I am trying to build an EA, that does the following:
- On candle close, if the 2 EMA crossed the 7 EMA to the upside, buy now (once)
- stay in the trade UNTIL the 2 crossed the 7 on candle close (since it could cross multiple times during a candle and I really want the confirmation that the close of the candle caused the EMA's to stay crossed)
- the same vice-versa (so sell if 2 crosses 7 below etc...)
I added a "take profit" if you will, which should set a trailing stop once the unrealized profit reaches point A and close the trade once it reaches point B
Here is the project: https://fxdreema.com/shared/ND7gRSW3b
I encountered various problems which the EA and I hope somebody can help me out since I really can't find the (probably obvious) solution:
- sometimes the EMA opens up trades if the EMAs crossed during the last candle, so not with candle close, but also it it happened during the opening, which is a problem since I plan on using this EMA on high volatile pairs
- the "take profit" and "set trailing stop" does not work at all
- I also found some problems with my take on "close trades", since sometimes they simply kept on going
Unfortunately, I could not find a mistake pattern ...
I put all my blocks in the "On Tick" Event since my TP did not trigger in the "On Trade" Event
I would be very glad if somebody would take the time to help me out!
Cheers
-
@feliziano7 why the counters here?

Otherwise I dont see anything wrong here, you'll have to provide some screenshots explaining whats happening and what you expected
-
I encountered the problem with high volatile pairs (f.e. XAUUSD) that the EA opens up a trade as it should, but when my TP was hit within the same candle, it opened up another trade immediately.
For Example:
The EA should open a buy trade if the X EMA and Y EMA crossed to the upside on candle close id 1.
Now, my trade opened, reached TP within some minutes, but checked the condition again and opened up another trade since the condition is still true.
So I added the counters that the EA opens up just one trade per change of short-time trend and the counter will reset after the EMAs cross again in the other direction.Question:
Does the "check profit (unrealized)" work on demo account? That is one thing I imagine could cause the trades not to close ...Thanks for your relply!
-
@feliziano7 ok, makes sense! You could also use "check type (last closed)" == buy/sell.
Mql4 makes no difference between demo and real. Your trades dont close because you have set a group number in the entry logic but no group number in closing blocks. Remove the group # or set the same number everywhere:
