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).
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".
int Magic = 12345, total = 0;
total = PositionsTotal();
total = OrdersTotal();
for ( int cnt= 0; cnt<total; cnt++)
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;
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;
/* do something */
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)