partial TP, partial trailing SL

 

Trying to convert my MQL4 code to MQL5. I have done some rudimentary coding in MQL5.

My MQL4 code is an EA that takes a position sliced into 4 parts. All start out with the same SL. 3 have fixed TP.  When first postion reaches TP the rest has

its SL placed at break even. The 4:th will not have a TP. Instead it will have a trailing SL after it has got a break even SL.

This is fairly simple in MQL4, its just 4 separate trades that I can keep track on by comments.

Can someone give me an overview on how to accomplish this in MQL5 or point to an article(s)

Tried to search this site but did not find it

 
Hint:
To partially close some trade lots open the reverse type order with the desired amount of lots you want to close.
There's no OrderClose.
 
ingvar_e:

Trying to convert my MQL4 code to MQL5. I have done some rudimentary coding in MQL5.

My MQL4 code is an EA that takes a position sliced into 4 parts. All start out with the same SL. 3 have fixed TP.  When first postion reaches TP the rest has

its SL placed at break even. The 4:th will not have a TP. Instead it will have a trailing SL after it has got a break even SL.

This is fairly simple in MQL4, its just 4 separate trades that I can keep track on by comments.

Can someone give me an overview on how to accomplish this in MQL5 or point to an article(s)

Tried to search this site but did not find it

MT5 is position based trading. it mean that there will be only one position with open price averaged. Try this : open buy EURUSD, 5 pips later open again and you will see now that there is only one opened position with open price averaged and the lot size is increased.

Another thing, in MT5, TP and SL is not executed, so instead using Sl and TP you should use, Limit pending for SL and Stop pending for TP, both pending type are opposite to the type of opened position. For example, if you have open buy, then use Sell Limit for TP and use Sell Stop for SL 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
 

Thanks codersguru and phi.nuts. I get it.
 

This of course leads to a follow up question. This difference in the MT5 compared to MT4 must in some way be implemented on the broker side.

Running this method on a broker that allows hedging will not yield the correct results. If I understand it correctly There is the FIFO rule, the nonhedging rule

and possibly other. And also consequental rules like forcing the same SL if you have more than one position running.


Is there a good description of the rules and what part is implemented in MT5 and what is implemented at the broker server side somewhere. And what

the consequences are. One obvious problem would be to implement "mirroring" between different brokers that apply the rules differently.

It also leads to forking the code in an EA depending on how the rules are implemented.

 
ingvar_e:

This of course leads to a follow up question. This difference in the MT5 compared to MT4 must in some way be implemented on the broker side.

Running this method on a broker that allows hedging will not yield the correct results. If I understand it correctly There is the FIFO rule, the nonhedging rule

and possibly other. And also consequental rules like forcing the same SL if you have more than one position running.


Is there a good description of the rules and what part is implemented in MT5 and what is implemented at the broker server side somewhere. And what

the consequences are. One obvious problem would be to implement "mirroring" between different brokers that apply the rules differently.

It also leads to forking the code in an EA depending on how the rules are implemented.

Hate to say this : ask the broker and play their demo.