Topic closed, moved to Market.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello all,
Facing a problem when coding my simple moving average EA in mql4, just lacking mql4 knowledge really.
How do I make it stop the trade when going 30 pips below/above MA, this is to protect from bad trades or negative SMA as I call it (see image). I don't want to use a stop loss.
Currently it set to stop trading when crossing SMA and second candle and closes, but its too late by then.
if (OrdersTotal()>=1 && Close[1] < sma) {
OrderClose(ticket, Lots, OrderClosePrice(), 10);
}
else if (OrdersTotal()>=1 && Close[1] > sma) {
OrderClose(ticket, Lots, OrderClosePrice(), 10);
}
My trial and error
Change to Close[0], this didn't work.
Changed High[1] and Low[1], didn't work either.
All I need is it to stop a trade after crossing MA and 30 above/below. Close by live pip amount, (similar to take profit at).
Please see image: