Download MetaTrader 5

Code for closing position

To add comments, please log in or register
Fringe
6
Fringe  

Hi,

Can someone write for me short simple code which close position.

I used that code to open position but I can not close it.

            request.action = TRADE_ACTION_DEAL;
            request.symbol = _Symbol;
            request.volume = Lot;
            request.price = Bid;
            request.sl = Loss;
            request.tp = Profit;
            request.deviation = SP;
            request.type = PositionDirection;
            request.type_filling = ORDER_FILLING_FOK;
            OrderSend(request, result);

I expect something simple too.

Thanks for help. 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Trade Operation Types - Documentation on MQL5
Jin
1539
Jin  
Fringe:

Hi,

Can someone write for me short simple code which close position.

I used that code to open position but I can not close it.

            request.action = TRADE_ACTION_DEAL;
            request.symbol = _Symbol;
            request.volume = Lot;
            request.price = Bid;
            request.sl = Loss;
            request.tp = Profit;
            request.deviation = SP;
            request.type = PositionDirection;
            request.type_filling = ORDER_FILLING_FOK;
            OrderSend(request, result);

I expect something simple too.

Thanks for help. 

You should try to use the stardand library, in particular, CTrade (#include <Trade\Trade.mqh>).

It simplify a lot stuffs like that. If you don't want to you it for some reason, look it anyway to find examples on how to use this kind of function corretly.

regards.

Dua Yong Rew
5481
Dua Yong Rew  

Fringe 

Hi,

Can someone write for me short simple code which close position.

I used that code to open position but I can not close it.

            request.action = TRADE_ACTION_DEAL;
            request.symbol = _Symbol;
            request.volume = Lot;
            request.price = Bid;
            request.sl = Loss;
            request.tp = Profit;
            request.deviation = SP;
            request.type = PositionDirection;
            request.type_filling = ORDER_FILLING_FOK;
            OrderSend(request, result);

I expect something simple too.

Thanks for help. 

You can send a ordersend with the opposite direction to close the trade 

To add comments, please log in or register