ClosePosition() from MT4

 

Hi All

 Apologies if this has been answered before, but I can't find a suitable answer.

How do I close an open position when certain criteria are met?

For example:

if(fast moving average crosses over and above slow moving average)

Open long position

if(fast moving average crosses over and below slow moving average)

Close the open (long) position <== This is the part I can't do.

In MT4 it was easy with the ClosePosition () function, but MT5 works differently.

Please help. 

 
#include <Trade\Trade.mqh>

CTrade ctrade;

ctrade.PositionClose(
   const string  symbol,              
   ulong         deviation=ULONG_MAX    
   );
//or by ticket
ctrade.PositionClose(
   const ulong   ticket,              
   ulong         deviation=ULONG_MAX
   );

 
Gruwel:
...

In MT4 it was easy with the ClosePosition () function, but MT5 works differently.

Please help. 

There is no ClosePosition() on "MT4".

Your question is about mql4 or mql5 ?

Reason: