Scaling-Out in Mql5

 

What's the best way to scale-out of position in Mql5? I prefer entering through 1 order and then scale-out through multiple targets

For eg.

Entry, Buy_Stop 2 lots at 1.2627

SL: 1.2584

TP1: 1.2647 - Exit 1st lot

TP2: 1.2667 - Exit 2nd lot


I also tried scaling-in by entering two orders with entry 1.2627 and different tp but it seems like that it moves all the tp to 1.2890. Here's the log:

2010.08.27 14:12:26    Core 1    2010.08.24 17:04:40   order performed sell 0.20 at 1.2667 [#79 sell 0.20 EURUSD at 1.2667]
2010.08.27 14:12:26    Core 1    2010.08.24 17:04:40   deal performed [#55 sell 0.20 EURUSD at 1.2667]
2010.08.27 14:12:26    Core 1    2010.08.24 17:04:40   deal #55 sell 0.20 EURUSD at 1.2667 done (based on order #79)
2010.08.27 14:12:26    Core 1    2010.08.24 17:04:40   take profit triggered buy 0.20 EURUSD 1.2627 sl: 1.2584 tp: 1.2667 [#79 sell 0.20 EURUSD at 1.2667]
2010.08.27 14:12:26    Core 1    2010.08.24 16:36:20   order canceled [#78 sell stop 0.10 EURUSD at 1.2584]
2010.08.27 14:12:26    Core 1    2010.08.24 16:36:20   order canceled [#76 sell stop 0.10 EURUSD at 1.2584]
2010.08.27 14:12:26    Core 1    2010.08.24 16:36:20   order performed buy 0.10 at 1.2627 [#77 buy stop 0.10 EURUSD at 1.2627]
2010.08.27 14:12:26    Core 1    2010.08.24 16:36:20   deal performed [#54 buy 0.10 EURUSD at 1.2627]
2010.08.27 14:12:26    Core 1    2010.08.24 16:36:20   deal #54 buy 0.10 EURUSD at 1.2627 done (based on order #77)
2010.08.27 14:12:26    Core 1    2010.08.24 16:36:20   order [#77 buy stop 0.10 EURUSD at 1.2627] triggered
2010.08.27 14:12:26    Core 1    2010.08.24 16:36:20   order performed buy 0.10 at 1.2627 [#75 buy stop 0.10 EURUSD at 1.2627]
2010.08.27 14:12:26    Core 1    2010.08.24 16:36:20   deal performed [#53 buy 0.10 EURUSD at 1.2627]
2010.08.27 14:12:26    Core 1    2010.08.24 16:36:20   deal #53 buy 0.10 EURUSD at 1.2627 done (based on order #75)
2010.08.27 14:12:26    Core 1    2010.08.24 16:36:20   order [#75 buy stop 0.10 EURUSD at 1.2627] triggered
2010.08.27 14:12:26    Core 1    2010.08.24 16:00:00   sell stop 0.10 EURUSD at 1.2584 sl: 1.2627 tp: 1.2544 (1.2606 / 1.2608 / 1.2606)
2010.08.27 14:12:26    Core 1    2010.08.24 16:00:00   buy stop 0.10 EURUSD at 1.2627 sl: 1.2584 tp: 1.2667 (1.2606 / 1.2608 / 1.2606)
2010.08.27 14:12:26    Core 1    2010.08.24 16:00:00   sell stop 0.10 EURUSD at 1.2584 sl: 1.2627 tp: 1.2564 (1.2606 / 1.2608 / 1.2606)
2010.08.27 14:12:26    Core 1    2010.08.24 16:00:00   buy stop 0.10 EURUSD at 1.2627 sl: 1.2584 tp: 1.2647 (1.2606 / 1.2608 / 1.2606)
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Deal Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Deal Properties - Documentation on MQL5
 
Why "in MQL5"? I guess it doesn't depend on the programming language, but on the money management techniques that one uses.
 
I mean which method programatically using MtrTradeRequest or Trade.PositionClose. I currently use MtrTradeRequest which is not giving expected results as it moves all the tp to highest tp of 1.2667.

 
You should use method OrderOpen of class CTrade for placing pending orders instead of using multiple Take Profits. Don't forget to remove these ones if position closes.

Reason: