i've put comments all over the ea just for easier and quicker understanding. so the problem is that the "control opened positions" part is not working at all. i don't get an error message or anything, thats why i'm posting to this forum. as you can see there is only a buy function in this ea as of yet and it gets triggered correctly, but the order management is not...
There may be other problems as well, e.g. the assumption that there will only ever be a single order open on the entire account, not just a single order from your EA.
thanks for the tip! i made this change
static int ticket_1;
and now the SL is moved to break even just like it needs to and positions are closed at SL, but the TP is never triggered and trades are not closed when price goeas under lower MA.
plus now i have a bunch of this: "OrderModify error 1"
kida strange, because the ordermodify seems to work properly...
btw i'm testing on eurusd 1h
and now the SL is moved to break even just like it needs to and positions are closed at SL, but the TP is never triggered and trades are not closed when price goeas under lower MA.
plus now i have a bunch of this: "OrderModify error 1"
What's happening now is that your b/e condition is being repeatedly met on every tick, with two effects. Firstly, the code keeps trying to do an OrderModify() using what is already the trade's s/l and t/p, which leads to an error. Secondly, the t/p closure condition is never called, because it is part of an if-else-if block, and the earlier if condition for the b/e is always met if the t/p condition is met. The conditions for the b/e must be true if the conditions for the t/p are true. Therefore, the if-block exits without ever getting to the t/p condition.
Going back to the earlier problem, declaring ticket_1 as static will work, but only up to a point. What you have now is an EA which will develop amnesia if MT4 has to be restarted. After a restart it will no longer track any open position.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hi
i've put comments all over the ea just for easier and quicker understanding. so the problem is that the "control opened positions" part is not working at all. i don't get an error message or anything, thats why i'm posting to this forum. as you can see there is only a buy function in this ea as of yet and it gets triggered correctly, but the order management is not...
the ea itself is as simple as it gets... it buys when price goes over MA_High and closes if TP or SL is hit or when price goes under MA_Low. plus there is a break even function (if order is in X plus pips, the SL is moved to break even). thats all
because there are no errors while running the ea i would assume everything is working as it should be, so i hay have a "return(0)" or something like that wrong...
hope someone can help, thanks!