OrderModify changing all open orders reguardless of ticket#

 

Hello, I am working on an EA in MQL4 that can have multiple open orders.  When the EA creates a new order it then uses OrderModify to set TP & SL.  When that happens, all open tickets get changed.

Here is my code:


bool modok = OrderSelect(pTicket,SELECT_BY_TICKET);
if (!modok)
           {
              Alert("Modify order failed: ticket = ",pTicket);
              Print("Trade L 753 - ModifyOrder failed for ",pTicket);
              break;
           }

result = OrderModify(OrderTicket(), pPrice, pStop, pProfit, pExpiration, pArrow);


All open orders get changed at the same time!

I use ticket# and select it first then issue modify.  What's going on?


John

 
jvanwalleghen1: When that happens, all open tickets get changed.
  1. Your broker is doing that for FIFO rules. All open tickets get the same TP/SL so the first closes first as required by law rules.

    Since 2009, hedging is not permitted for US traders.
              NFA Enforces FIFO Rule, Bans Forex Hedging in US Forex Accounts - Trading Heroes
              FAQ: FIFO in the Forex Market - BabyPips.com

  2. In the presence of multiple orders (one EA multiple charts, multiple EAs, manual trading,) while you are waiting for the current operation (closing, deleting, modifying) to complete, any number of other operations on other orders could have concurrently happened and changed the position indexing:
    1. For non-FIFO (non-US brokers), (or the EA only opens one order per symbol,) you can simply count down, in a position loop, and you won't miss orders. Get in the habit of always counting down.
                Loops and Closing or Deleting Orders - MQL4 programming forum
      For In First Out (FIFO rules-US brokers,) and you (potentially) process multiple orders per symbol, you must find the earliest order, close it, and on a successful operation, reprocess all positions.
                CloseOrders by FIFO Rules - Strategy Tester - MQL4 programming forum - Page 2 #16
                MetaTrader 5 platform beta build 2155: MQL5 scope, global Strategy Tester and built-in Virtual Hosting updates - Best Expert Advisors - General - MQL5 programming forum #1 № 11 ACCOUNT_FIFO_CLOSE

    2. and check OrderSelect in case earlier positions were deleted.
                What are Function return values ? How do I use them ? - MQL4 programming forum
                Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    3. and if you (potentially) process multiple orders, must call RefreshRates() after server calls if you want to use, on the next order / server call, the Predefined Variables (Bid/Ask) or (be direction independent and use) OrderClosePrice().

 

Thank you.  I knew about FIFO opening and closing, but not that all orders have to have the same SL/TP.


JOhn

 
jvanwalleghen1: but not that all orders have to have the same SL/TP.

I didn't say anything about "have to have." Only that some brokers do.

 
jvanwalleghen1:

Hello, I am working on an EA in MQL4 that can have multiple open orders.  When the EA creates a new order it then uses OrderModify to set TP & SL.  When that happens, all open tickets get changed.

Here is my code:


bool modok = OrderSelect(pTicket,SELECT_BY_TICKET);
if (!modok)
           {
              Alert("Modify order failed: ticket = ",pTicket);
              Print("Trade L 753 - ModifyOrder failed for ",pTicket);
              break;
           }

result = OrderModify(OrderTicket(), pPrice, pStop, pProfit, pExpiration, pArrow);


All open orders get changed at the same time!

I use ticket# and select it first then issue modify.  What's going on?


John

Before sending the order modify request, you should check whether the order is the one you really want to modify. For instance evaluating if TP or SL are set to zero 

Reason: