Simple MQL4 Programming Problem (Closing Trades)

 

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:

Stop Bad Trades 

 
Topic closed, moved to Market.
Reason: