OrderDelete() returning "invalid parameters", MT4 bug? - page 2

 

I just encountered the same problem, and it is destroying the logic of my EA.

 I've been running an EA with a local broker for 3 months with no issues.  I added the EA to a broker i'm using internationally, and this problem is repeatedly occuring.  The bad part, is the logic in my EA will add a trade when the "fake" condition occurs, sometimes causing me to have an 3-4 more trades than I intend.  I can't hope that they fix this bug asap. 

 
Freedom787:

I just encountered the same problem, and it is destroying the logic of my EA.

 I've been running an EA with a local broker for 3 months with no issues.  I added the EA to a broker i'm using internationally, and this problem is repeatedly occuring.  The bad part, is the logic in my EA will add a trade when the "fake" condition occurs, sometimes causing me to have an 3-4 more trades than I intend.  I can't hope that they fix this bug asap. 

According to  geektrader   this issue should be fixed by now,  see below.  Have you tried build 445 ?  make sure you backup your previous build before updating to 445 . . .

geektrader:
Thanks for your help Raptor, I will consider this for the code, however, that this is a unsync bug that can happen during fast market movements (this is where my EA trades) was just confirmed by Metaquotes after given them the log of MT4 Terminal against the MT4 Server log. They say, it´s clear that MT4 Server had opened the order while MT4 Terminal still was in the assumption that it is a pending "buy stop" order since the ticket numbers also did exactly match, otherwise MT4 Terminal wouldn´t have returned "buy stop" for that ticketnumber which was already opened 8 seconds ago at the broker. And it will be fixed in the next release;) Thank you anyway.
 

You can NOT delete pending order when the market is closer to open price than MarketInfo(chart.symbol, MODE_STOPLEVEL)*Point

You can NOT close open orders when the market is closer to TP or SL than stop level

You can NOT set stops closer then stop level from the market

 
Lorenz Vauck:

Hi,

In rare cases I am getting a "invalid parameters" error for OrderDelete() which only needs the orderticket to do it´s job. This is for OP_BUYSTOP or OP_SELLSTOP order types. Before each run for OrderDelete(), I am browsing through OrdersTotal(), check them for OrderType() (only processing OP_BUYSTOP and OP_SELLSTOP types), get the ticket and then run OrderDelete(ticket). Still I get:


03:36:42 'XXXX': delete pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407

03:36:42 'XXXX': deleting of pending order #7720748 buy stop 0.65 EURJPY at 102.907 sl: 102.867 tp: 103.407 failed [Invalid parameters]


Now one of the reasons could be that the BUYSTOP order got active directly at the time the EA tries to delete it, but, the EA checks that on the next run (above mentioned loop) and then tried to delete this order again because according to OrderTotal() it was still a pending BUY_STOP order. It again got a Invalid Parameters error. However, I´ve checked with the broker and he sent me the MT4 Server log for this order. Interesting is: at the time the EA tries to delete the order, it was already opened at the MT4 server, and so all subsequent tries to delete it of course failed, but still MT4 client was reporting that this order is still a pending OP_BUYSTOP order, for over 20 seconds (in which the EA tried to delete the order all the time, but always getting invalid parameters error).

So to me this looks like a unsync bug between MT4 Terminal and MT4 Server, since OrdersTotal() was still returning that this ticket is a OP_BUYSTOP and not an open BUY Order, while at the broker server it was a buy order already for over 20 seconds. And the OrderDelete() function in my EA works fine in 99% of the cases, but then, a few times, the above described error happens and MT4 Terminal simply doesn´t get told by the MT4 Server that the order is already active.

Anyone else experienced that? How can I report it to Metaquotes?

Sorry for not looking real close, but looked like you are going from low index number (first=0) to high index number (orders total).  As a suggestion, always go from most to 0 as in: for(int idx=(OrdersTotal()-1); idx>-1; idx--).  If going the other way, the idx referencing a particular order changes after a delete - you can reach the end of the list of orders without looking at all your orders.

 
LukeB: As a suggestion, always go from most to 0 as in: for(int idx=(OrdersTotal()-1); idx>-1; idx--).  If going the other way, the idx referencing a particular order changes after a delete - you can reach the end of the list of orders without looking at all your orders.

Correct except for US brokers (FIFO)

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
  2. For In First Out (FIFO rules — US brokers), and you (potentially) process multiple orders per symbol, you must find the earliest order (count up), 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

  3. and check OrderSelect in case later 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
  4. 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 instead, be direction independent and just use OrderClosePrice().
Reason: