MQL4 - Need Help Creating/Coding Simple Exit Rule

 

Hey everyone, I'm new to MQL4 programming and was wondering how I would code this in MQL4


if  Previous Bar Closes BELOW (less than?)

{
Simple Moving Average (1) Shift (5) - 0.0020

}

, Close LONG position at Market price.

If Previous Bar Closes  ABOVE (greater than?)

{
Simple Moving Average (1) Shift (5) + 0.0020

}

Close SHORT position at Market Price




If anybody has resources to point me to or can be generous enough if this is extremely simple for them to write, I would be very grateful.

 I will gladly pay  someone some beer money and share my expert if there are any other newbies out there like myself.

Thanks! =)

 
Bradford Hall:

Hey everyone, I'm new to MQL4 programming and was wondering how I would code this in MQL4


if  Previous Bar Closes BELOW (less than?)

{
Simple Moving Average (1) Shift (5) - 0.0020

}

, Close LONG position at Market price.

If Previous Bar Closes  ABOVE (greater than?)

{
Simple Moving Average (1) Shift (5) + 0.0020

}

Close SHORT position at Market Price




If anybody has resources to point me to or can be generous enough if this is extremely simple for them to write, I would be very grateful.

 I will gladly pay  someone some beer money and share my expert if there are any other newbies out there like myself.

Thanks! =)

if(Close[1]<iMA(Symbol(),0,1,5,MODE_SMA,PRICE_CLOSE,1))

 {

     if(OrderSelect(OrderTicket,SELECT_BY_TICKET,MODE_TRADES))

         OrderClose(OrderTicket(),OrderLots(),Bid,3,clrRed);

}

and do the opposite for the SHORT closing

also see the documentation about OrderSelect() and OrderClose() functions

Reason: