Download MetaTrader 5

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

To add comments, please log in or register
Young Ho Seo
16339
Young Ho Seo 2014.01.24 15:08 

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.

Alain Verleyen
Moderator
31090
Alain Verleyen 2014.01.24 15:19  
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 ?
Simon Gniadkowski
Moderator
18002
Simon Gniadkowski 2014.01.24 15:25  
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.
Alain Verleyen
Moderator
31090
Alain Verleyen 2014.01.24 15:29  
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.

Young Ho Seo
16339
Young Ho Seo 2014.01.24 15:40  
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

Simon Gniadkowski
Moderator
18002
Simon Gniadkowski 2014.01.24 16:09  
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.
Alain Verleyen
Moderator
31090
Alain Verleyen 2014.01.24 16:09  
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.
Young Ho Seo
16339
Young Ho Seo 2014.01.24 16:28  
RaptorUK:

Thanks
Young Ho Seo
16339
Young Ho Seo 2014.01.24 16:28  
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
To add comments, please log in or register