Individual Trade Management in MT5

 

Hi there,

I understand that things work a little different in MT5...

Here is my understanding: An order results in a deal. A deal effects the net position. StopLoss (SL) and TakeProfit (TP) are on position level.

What I need is that, as in MT4, I can set SL and TP based on deal level. Having an open position, when I add to the position, I need the two separte "operations" to be managed individually. 

I can do this by opening Stop and Limit orders, which reflect the individual SL and TP and delete the second pending order once the first one has been filled. I have created a small library for myself, which does exactly that (which I am willing to share). 

I am just wondering, whether this is not an issue that everyone of us has. I would assume that this is an already solved issue. However searching articles and code base, I did not find much.

What I did find are the following two related promiding articles, which provide a framework for individual trade management incl. hedging: 

However, considering the limited number of comments and the date of the articles it feels as if this is not the common way how to deal with this challenge. 

So my question to you is: 

If you write an EA which is supposed to handle SL and TP individually per order/deal, how do you go about it? 

Do you use an existing framework and if you do, which one?

Thanks,

Matt

Bi-Directional Trading and Hedging of Positions in MetaTrader 5 Using the HedgeTerminal Panel, Part 1
Bi-Directional Trading and Hedging of Positions in MetaTrader 5 Using the HedgeTerminal Panel, Part 1
  • www.mql5.com
Within the last 18 months MetaQuotes have conducted extensive work on consolidating the MetaTrader 4 and MetaTrader 5 platforms into a unified trading ecosystem. Now both platforms share a common market of program solutions - Market, offering different products from external developers. The compilers for both platforms were united as well. As a...
 
 
fxmatte:

Hi there,

I understand that things work a little different in MT5...

Here is my understanding: An order results in a deal. A deal effects the net position. StopLoss (SL) and TakeProfit (TP) are on position level.

What I need is that, as in MT4, I can set SL and TP based on deal level. Having an open position, when I add to the position, I need the two separte "operations" to be managed individually

I can do this by opening Stop and Limit orders, which reflect the individual SL and TP and delete the second pending order once the first one has been filled. I have created a small library for myself, which does exactly that (which I am willing to share). 

I am just wondering, whether this is not an issue that everyone of us has. I would assume that this is an already solved issue. However searching articles and code base, I did not find much.

What I did find are the following two related promiding articles, which provide a framework for individual trade management incl. hedging: 

However, considering the limited number of comments and the date of the articles it feels as if this is not the common way how to deal with this challenge. 

So my question to you is: 

If you write an EA which is supposed to handle SL and TP individually per order/deal, how do you go about it? 

Do you use an existing framework and if you do, which one?

Thanks,

Matt

the two-step operation isn't a strict requirement. (my assumption was as your after reading that old-dated articles :| )

so send your orders in one or two steps (as your brokers permits so).

 

My eplaination must have been incomplete. Therefore, I retry by using following scenario.

Scenario:

Trade 1:

Current Price is at 1.15500. I enter a 1 lot long. 
I want SL and TP to be 50 pips away. 
Therefore I put TP at 1.16000 and SL at 1.15000.


Trade 2:

Price moves 20 pips up to 1.15700. I enter another 1 lot long. 
Again, I want SL and TP to be 50 pips away, but the previous entered lot with its SL and TP should be not affected. Therefore the previous lot TP and SL should remain at 1.16000 and 1.15000. 
The newly entered lot should have a TP at 1.16200 and SL at 1.15200.

As with MT5 (with netting) SL and TP are on the position, I can only have one SL and one TP, which goes for the entire position. Therefore, the requirement decribed is not easily fulfilled in MT5.


Current Solution:

The way I currently cover the requirement is the following:
In the above szenario I would have entered:
  • for the first trade: 1 market order at 1.15500, a SellLimit at 1.16000 as TP and a SellStop at 1.15000 as SL.
  • for the second trade: 1 market order at 1.15700, a SellLimit at 1.16200 as TP and a SellStop at 1.15200 as SL.
  • for the first trade: Once either the SellLimit at 1.16000 or the SellStop at 1.15000 is hit, I delete the other one. (same goes for the second trade with its respective levels)

I should also mention that my broker (FxPro) uses ACCOUNT_MARGIN_MODE_RETAIL_NETTING. Therefore, only one position per symbol is allowed. That is why PositionSelect() does not do the trick.

I have just not yet found a decent broker with ACCOUNT_MARGIN_MODE_RETAIL_HEDGING. This would probaly address my issue as well. (Suggestions on this would also be appreciated.)

Again, as most brokers use netting, and coming from MT4 manys are used to individual trade management, I would assume that the above described challenge has already been solved by an existing library or script.

 
fxmatte:

My eplaination must have been incomplete. Therefore, I retry by using following scenario.

Scenario:

Trade 1:

Current Price is at 1.15500. I enter a 1 lot long. 
I want SL and TP to be 50 pips away. 
Therefore I put TP at 1.16000 and SL at 1.15000.


Trade 2:

Price moves 20 pips up to 1.15700. I enter another 1 lot long. 
Again, I want SL and TP to be 50 pips away, but the previous entered lot with its SL and TP should be not affected. Therefore the previous lot TP and SL should remain at 1.16000 and 1.15000. 
The newly entered lot should have a TP at 1.16200 and SL at 1.15200.

As with MT5 (with netting) SL and TP are on the position, I can only have one SL and one TP, which goes for the entire position. Therefore, the requirement decribed is not easily fulfilled in MT5.


Current Solution:

The way I currently cover the requirement is the following:
In the above szenario I would have entered:
  • for the first trade: 1 market order at 1.15500, a SellLimit at 1.16000 as TP and a SellStop at 1.15000 as SL.
  • for the second trade: 1 market order at 1.15700, a SellLimit at 1.16200 as TP and a SellStop at 1.15200 as SL.
  • for the first trade: Once either the SellLimit at 1.16000 or the SellStop at 1.15000 is hit, I delete the other one. (same goes for the second trade with its respective levels)

I should also mention that my broker (FxPro) uses ACCOUNT_MARGIN_MODE_RETAIL_NETTING. Therefore, only one position per symbol is allowed. That is why PositionSelect() does not do the trick.

I have just not yet found a decent broker with ACCOUNT_MARGIN_MODE_RETAIL_HEDGING. This would probaly address my issue as well. (Suggestions on this would also be appreciated.)

Again, as most brokers use netting, and coming from MT4 manys are used to individual trade management, I would assume that the above described challenge has already been solved by an existing library or script.

I know exactly what you are asking for and to the best of my knowledge there is no open-source framework for linking stop-orders, limit-orders, and resulting positions to individual deals. Just off the top of my head... you could try opening the pending orders using the deal ticket number as the pending order magic number in order to create a link that would persist across terminals. 

 
fxmatte:

My eplaination must have been incomplete. Therefore, I retry by using following scenario.

Scenario:

Trade 1:

Current Price is at 1.15500. I enter a 1 lot long. 
I want SL and TP to be 50 pips away. 
Therefore I put TP at 1.16000 and SL at 1.15000.


Trade 2:

Price moves 20 pips up to 1.15700. I enter another 1 lot long. 
Again, I want SL and TP to be 50 pips away, but the previous entered lot with its SL and TP should be not affected. Therefore the previous lot TP and SL should remain at 1.16000 and 1.15000. 
The newly entered lot should have a TP at 1.16200 and SL at 1.15200.

As with MT5 (with netting) SL and TP are on the position, I can only have one SL and one TP, which goes for the entire position. Therefore, the requirement decribed is not easily fulfilled in MT5.


Current Solution:

The way I currently cover the requirement is the following:
In the above szenario I would have entered:
  • for the first trade: 1 market order at 1.15500, a SellLimit at 1.16000 as TP and a SellStop at 1.15000 as SL.
  • for the second trade: 1 market order at 1.15700, a SellLimit at 1.16200 as TP and a SellStop at 1.15200 as SL.
  • for the first trade: Once either the SellLimit at 1.16000 or the SellStop at 1.15000 is hit, I delete the other one. (same goes for the second trade with its respective levels)

I should also mention that my broker (FxPro) uses ACCOUNT_MARGIN_MODE_RETAIL_NETTING. Therefore, only one position per symbol is allowed. That is why PositionSelect() does not do the trick.

I have just not yet found a decent broker with ACCOUNT_MARGIN_MODE_RETAIL_HEDGING. This would probaly address my issue as well. (Suggestions on this would also be appreciated.)

Again, as most brokers use netting, and coming from MT4 manys are used to individual trade management, I would assume that the above described challenge has already been solved by an existing library or script.

An hedging account is really a must for what you want. Did you talk to FxPro ? I have heard you can have an hedging account if you request one, you should ask to their support.

Otherwise there is an old library to manage "virtual" trade on a netting account.

 

Thank you so much for your inputs.

By now, I also think it is best to open a hedging account. I probably needed that "public reflection" of my thoughts. Thanks.
I'll check with FX Pro and otherwise will switch broker for that purpose.