Download MetaTrader 5

ClosePosition() from MT4

To add comments, please log in or register
Gruwel
12
Gruwel  

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. 

Yerlan Imangeldinov
885
Yerlan Imangeldinov  
#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
   );

Alain Verleyen
Moderator
33610
Alain Verleyen  
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 ?

To add comments, please log in or register