Can we close orders or position without #include <trade/trade.mqh> ?

 

Just curious if there a neat way of closing order without using CTrade in trade.mqh file in MT5.

 Just miss simple standalone "OrderClose" function in MT4.

 
FinanceEngineer:

Just curious if there a neat way of closing order without using CTrade in trade.mqh file in MT5.

 Just miss simple standalone "OrderClose" function in MT4.

"closing order", do you mean a pending order or a position ?
 
angevoyageur:
"closing order", do you mean a pending order or a position ?
Must be a position otherwise he/she would have said "miss OrderDelete()" . . .  just send an equivalent order of the same size as you want to close but in the opposite direction, so to close a Buy open a Sell.
 
RaptorUK:
Must be a position otherwise he/she would have said "miss OrderDelete()" . . .  just send an equivalent order of the same size as you want to close but in the opposite direction, so to close a Buy open a Sell.

You are right.

To answer the OP, you can use MqlTradeRequest as you have done here to modify your sl/tp. CTrade class is only a wrapper class using MqlTradeRequest internally.

 
angevoyageur:

You are right.

To answer the OP, you can use MqlTradeRequest as you have done here to modify your sl/tp. CTrade class is only a wrapper class using MqlTradeRequest internally.

Sorry for confusion I would like to close positions not a pending orders. Thanks for clarification. Yes I thought about using MqlTradeRequest method.

Then I checked Trade Operation Type and I can't find any actions related to Closing positions.

These are all trade actions I can find from MQL references and am I looking at wrong place? :

 

Identifier

Description

TRADE_ACTION_DEAL

Place a trade order for an immediate execution with the specified parameters (market order)

TRADE_ACTION_PENDING

Place a trade order for the execution under specified conditions (pending order)

TRADE_ACTION_SLTP

Modify Stop Loss and Take Profit values of an opened position

TRADE_ACTION_MODIFY

Modify the parameters of the order placed previously

TRADE_ACTION_REMOVE

Delete the pending order placed previously

 
FinanceEngineer:

Sorry for confusion I would like to close positions not a pending orders. Thanks for clarification. Yes I thought about using MqlTradeRequest method.

Then I checked Trade Operation Type and I can't find any actions related to Closing positions.

These are all trade actions I can find from MQL references and am I looking at wrong place? :

RaptorUK:
 . . .  just send an equivalent order of the same size as you want to close but in the opposite direction, so to close a Buy open a Sell.
 
FinanceEngineer:

Sorry for confusion I would like to close positions not a pending orders. Thanks for clarification. Yes I thought about using MqlTradeRequest method.

Then I checked Trade Operation Type and I can't find any actions related to Closing positions.

These are all trade actions I can find from MQL references and am I looking at wrong place? :

 

Identifier

Description

TRADE_ACTION_DEAL

Place a trade order for an immediate execution with the specified parameters (market order)

Yes, as RaptorUK wrote, you have to send a request (ACTION_DEAL) for an order, in the opposite direction with same volume.

Order management is very different in mql5 relative to mql4 : read this article

Orders, Positions and Deals in MetaTrader 5
Orders, Positions and Deals in MetaTrader 5
  • 2011.02.01
  • MetaQuotes Software Corp.
  • www.mql5.com
Creating a robust trading robot cannot be done without an understanding of the mechanisms of the MetaTrader 5 trading system. The client terminal receives the information about the positions, orders, and deals from the trading server. To handle this data properly using the MQL5, it's necessary to have a good understanding of the interaction between the MQL5-program and the client terminal.
 
RaptorUK:

Thanks
 
angevoyageur:

Yes, as RaptorUK wrote, you have to send a request (ACTION_DEAL) for an order, in the opposite direction with same volume.

Order management is very different in mql5 relative to mql4 : read this article

Thanks
 
Alain Verleyen:

Yes, as RaptorUK wrote, you have to send a request (ACTION_DEAL) for an order, in the opposite direction with same volume.

Order management is very different in mql5 relative to mql4 : read this article

Why is it not possible to close positions with TRADE_ACTION_PENDING ? This removes the possibility for creating manual stop losses and take profits.
Reason: