MQL5 Positions with multi stop loss targets

To add comments, please log in or register
BoredMember
117
BoredMember  

Hi,

I just switched from MT4 to MT5 and what a pain converting from MQL4 to MQL5.

A major problem I cannot solve is how to have several orders (MT4) in the same symbol each with a different stop loss (SL).

E.g.

Order 1, buy opened at 1.22, SL 1.20

Order 2, buy opened at 1.25, SL 1.22

Order 3, buy opened at 1.28, SL 1.23

The problem with MQL5 is that all the orders get lumped into one "position" with the same SL!

How can I send orders in MQL5 each in the same symbol but preserve the unique SL on each??

Furthermore, how can I then "ordermodify" each open "order" in the position to dynamically change the SL?

Should be obvious, but like so much in MQL5,isn't.

Having looked into this more I realize it's the difference between a "hedging" and "netting" account. However, if it's a netting account I still need to work out how in MQL5 to modify each "order" within a "position". 

Thanks!

Basic Principles - Trading Operations - MetaTrader 5
Basic Principles - Trading Operations - MetaTrader 5
  • www.metatrader5.com
is an instruction given to a broker to buy or sell a financial instrument. There are two main types of orders: Market and Pending. In addition, there are special Take Profit and Stop Loss levels. is the commercial exchange (buying or selling) of a financial security. Buying is executed at the demand price (Ask), and Sell is performed at the...
Konstantin Nikitin
8053
Konstantin Nikitin  
     int Magic = 12345, total = 0;
   #ifdef  __MQL5__
     total = PositionsTotal();
   #else
      total = OrdersTotal();
   #endif
      for ( int cnt= 0; cnt<total; cnt++)
     {
         #ifdef  __MQL5__
           if ( _Symbol != PositionGetSymbol(cnt) ) continue;
           if ( PositionGetInteger( POSITION_MAGIC ) != Magic ) continue;
           if ( PositionGetInteger( POSITION_TYPE )!= ORDER_TYPE_BUY && PositionGetInteger( POSITION_TYPE )!= ORDER_TYPE_SELL ) continue;
         #else
           if ( !OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES ) ) continue;
           if ( OrderSymbol() != _Symbol ) continue;
           if ( OrderMagicNumber() != Magic ) continue;
           if ( OrderType()!= ORDER_TYPE_BUY && OrderType()!= ORDER_TYPE_SELL ) continue;
         #endif
           /*   do something  */
     }
Enrique Dangeroux
683
Enrique Dangeroux  
With netting account you can have only 1 position per direction. Therefor only 1 SL and TP per direction. Either you have to create logic that deals with 1 position,or switch to hedging account. Ask your broker to switch the account type or create another hedging account.
BoredMember
117
BoredMember  

ok that's clear now.

However, if it's an hedging account, will it be the case that every order in the same symbol (e.g. GBPUSD) converts into a different position?

E.g. I place three orders for GBPUSD and do I end up with three positions each in GBPUSD with their own SL?

If so, then how do I access each of those positions? Presumably by cycling through the positions and using identifying numbers? Or by cycling through the deals? But can the deal SL be modified given it's historical? (seems unlikely)

Thanks!

To add comments, please log in or register