Replicating Netting account with Hedging account-PENDING orders

 

Hello,

I am trying to replicate the behaviour of a netting account using a hedging account (my broker does not offer one). I want to use the filling of an opposite order to close the initial one. This is automatic with TRADE_ACTION_DEAL but not with TRADE_ACTION_PENDING that I want to use.

I have tried the following:

-In a hedging account the combination of a STOP_BUY order and a STOP_SELL order results in a long position+a short position. The exposure (seen in Exposure tab) is null because earnings in one position would result in losses in the other one.

-If you try to close the long and short positions created with  TRADE_ACTION_PENDING using 2x opposite TRADE_ACTION_DEAL at the same time it will have additional losses over the expected one based on the prices at which the initial long and short positions were open because of the spread.

-The best way to close both the long and short position is to use the MODIFY TRADE-CLOSE BY and select the ticket of the opposite order manually in MT5 GUI. This has no additional costs

Do you know how to perform the manual MODIFY TRADE-CLOSE BY operation in MQL5-Python?

Thank you,

Eduardo