Problem with LIMIT orders (maybe not arriving to server?)

 

1.- OrderSend --> OP_BUYLIMIT (after certain conditions are met blah blah blah) EVERYTHING OK.

2.- Problem comes with OrderDelete() for this limit order, I discover huge flood of ERROR 3 (Invalid trade parameters) when it try to delete that limit order.

3.- I have "break" after print error so it goes out of the loop, but conditions are met again and it join in the loop over and over again flooding with ERROR 3.

4.- Nothing works, so I just try to remove it manually but I can't (timeout.wav sound).

5.- Also price (Ask) goes eventually under buylimit (it should be filled) but nothing happens.

6.- Well, lets close the terminal and open it again (also known as restart :huh:) and then... THERE IS NO LIMIT ORDER WHATSOEVER, NO ARROW ON CHART, NO REGISTRY ON ACCOUNT HISTORY, IT NEVER HAPPENED!!! and of course no error, so restart actually fix the problem  but such heavy fix huh)).


My conclusion is that limit order never arrived to server (mt4 server?, broker server?) so the terminal thinks that there's a limit order and when it try to do something with this order it returns error because there is no such order in the server.

I also tried RefreshRates() but I don't think is appropriate in this case (and obviously doesn't fix the problem)


Anyone experienced it? if so is there any solution? I found nothing about it, also I don't even know what to search for..

Thanks.

 
Show your code and somebody may be able to help you.
 

this is what I use to send order:

if (BUY conditions) { ticket = OrderSend(Symbol(), OP_BUYLIMIT, lot, Ask, 3, 0, 0, Text, Magic, 0, Lime); if (ticket <= 0) Print ("BUY ERROR ", GetLastError()); }


[...]


if ( SELL conditions) { ticket = OrderSend(Symbol(), OP_SELLLIMIT, lot, Bid, 3, 0, 0, Text, Magic, 0, Red); if (ticket <= 0) Print("SELL ERROR ", GetLastError()); }


[...]


then, if no executed and conditions are no longer needed I delete the pending order,

but first I count limit orders (I need this for other stuff too), note it counts only pending orders, once they are executed they become OP_BUY, or OP_SELL (no longer OP_BUYLIMIT, or OP_SELLLIMIT)

   for ( i = OrdersTotal()-1; i >= 0; i-- )
     {
       if ( !OrderSelect (i, SELECT_BY_POS )) continue;
       if ( OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && ( OrderType() == OP_BUYLIMIT || OrderType() == OP_SELLLIMIT )) countlimit++;
     }



now how I delete limit order:

   if (countlimit > 0) //--> once limit orders are counted, in order to process delete code, it need to be at least one pending order active


      for ( i = OrdersTotal()-1; i >= 0; i-- )
        {
         //RefreshRates(); //this is what I explained in OP, no longer used it was just a test
         if ( !OrderSelect( i, SELECT_BY_POS )) continue;
         if ( OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && blah blah ) && ( OrderType() == OP_BUYLIMIT || OrderType() == OP_SELLLIMIT ))
           {
            if ( !OrderDelete(OrderTicket())) Print("Delete pending ERROR ", GetLastError()); break;
           }
        }

 
if (BUY conditions) { ticket = OrderSend(Symbol(), OP_BUYLIMIT, lot, Ask, 3, 0, 0, Text, Magic, 0, Lime);
 if (ticket <= 0)
 Print ("BUY ERROR ", GetLastError()); }

How can you expect a BuyLimit order to be filled at Ask ??

 
GumRai:

How can you expect a BuyLimit order to be filled at Ask ??

I know it must be minor than Ask, I did also have (Ask-n*Point), but it send the limit orders anyway, and works most of the time, problem comes when it try to delete a sent order.

 
mindundi24:

I know it must be minor than Ask, I did also have (Ask-n*Point), but it send the limit orders anyway, and works most of the time, problem is when it try to delete the sent order.

Maybe you are trying to delete it after it has triggered, in which case you must close it, not delete it.
 

Buy Limit Pending Orders have to be placed below the Ask Price and Sell Limit Orders have to be placed above the Bid Price: Requirements and Limitations in Making Trades (Also read the following post: https://www.mql5.com/en/forum/159983).

If you place pending orders too close to current prices they could be filled very quickly and thus can no longer be deleted (only closed). So, if a Delete fails, check the order to see if it has not just been triggered and converted into a market order.

EDIT Correction: FREEZE-LEVEL condition is required when deleting Pending orders when the Open Price is within the freeze level, so you must check the brokers freeze level:

Market information identifiers

MODE_FREEZELEVEL : Order freeze level in points. If the execution price lies within the range defined by the freeze level, the order cannot be modified, cancelled or closed (see also Requirements and Limitations in Making Trades).

My apologies for this post being changed so many times in a short time span!

 
GumRai:
Maybe you are trying to delete it after it has triggered, in which case you must close it, not delete it.
If order gets triggered, then it is no longer OP_BUYLIMIT, but OP_BUY, and the delete code won't even be processed.
Also when I restart terminal there is no such order in account history, or even the arrow is not in the chart, is like if order never arrived to server but terminal thinks it did (I know it sounds weird.)
 
FMIC:

Buy Limit Pending Orders have to be placed below the Ask Price and Sell Limit Orders have to be placed above the Bid Price: Requirements and Limitations in Making Trades (Also read the following post: https://www.mql5.com/en/forum/159983).

If you place pending orders too close to current prices they could be filled very quickly and thus can no longer be deleted (only closed). So, if a Delete fails, check the order to see if it has not just been triggered and converted into a market order.

EDIT Correction: FREEZE-LEVEL condition is required when deleting Pending orders when the Open Price is within the freeze level, so you must check the brokers freeze level:

My apologies for this post being changed so many times in a short time span!



I know, it makes total sense, but I had it like that in the past but the error also happened, and some orders didn't even get touched by the price, so I ended up using just (Ask) because it gives me better results.

if order gets filled, OrderDelete code doesn't even get triggered (check the code I posted).

Problem is they appear like pending order, even if price goes way below the OP_BUYLIMIT (refer to my answer to user GumRai)

Didn't know about FREEZELEVEL, thanks! will check it out as soon as there is new ticks, but to be honest I'm skeptic because if there is any limitation then the rest of limit orders shouldn't be deleted either, I even tested deleting very quickly after opening, and very close to the price (very aggressive) and it works fine, thats why I don't know about the problem, I mean I can't find a pattern, I think I need something like RefreshRates but instead for predefined variables, for server data?

 
mindundi24:



I know, it makes total sense, but I had it like that in the past but the error also happened, and some orders didn't even get touched by the price, so I ended up using just (Ask) because it gives me better results.

if order gets filled, OrderDelete code doesn't even get triggered (check the code I posted).

Problem is they appear like pending order, even if price goes way below the OP_BUYLIMIT (refer to my answer to user GumRai)

Didn't know about FREEZELEVEL, thanks! will check it out as soon as there is new ticks, but to be honest I'm skeptic because if there is any limitation then the rest of limit orders shouldn't be deleted either, I even tested deleting very quickly after opening, and very close to the price (very aggressive) and it works fine, thats why I don't know about the problem, I mean I can't find a pattern, I think I need something like RefreshRates but instead for predefined variables, for server data?

You missing the point about what I and GumRai both stated!  Just because the OrderType() still says it is an Pending order, does not negate the fact that it has been triggered in the span of time once it was selected. Once a OrderSelect() is applied, the results of the other supporting functions are static and RefreshRates() has no effect on this. You have to re-select the order, with OrderSelect() in order to see the new updated values.

Also, you cannot use "Ask" for a Buy Limit Pending Order! PERIOD! You have just been lucky that the price is accepted, because the current market conditions have changed in your favor once the order goes in (due to some natural latency delay) but it will not always be the case.

Anyway, with pending orders so close to market prices, you should not even be using Pending Orders in the first place. Use Market orders when the required conditions are met. Code your EA to store the Price limits you want and then execute a Market Order when the price is reached. Pending Orders is not the answer! Do it right and stop messing about with the wrong tools for the job!

 
FMIC:

You missing the point about what I and GumRai both stated!  Just because the OrderType() still says it is an Pending order, does not negate the fact that it has been triggered in the span of time once it was selected. Once a OrderSelect() is applied, the results of the other supporting functions are static and RefreshRates() has no effect on this. You have to re-select the order, with OrderSelect() in order to see the new updated values.

<<does not negate the fact that it has been triggered in the span of time once it was selected>>


I don't really understand, you mean order is filled right after it is selected? if so, shouldn't be any registry about the "buy" in account history? (there is not, order is a ghost)

Also, how do I re-orderselect then? I thought "break" after error make it jumps out of the loop, so my understand was if it goes back to the loop is because conditions are met again (is still Limit Order) (?)



FMIC:

Also, you cannot use "Ask" for a Buy Limit Pending Order! PERIOD! You have just been lucky that the price is accepted, because the current market conditions have changed in your favor once the order goes in (due to some natural latency delay) but it will not always be the case.

You are right, and sometimes it returns obvious error but if any error it tries again and order is finally sent at the second try (95% are actually sent at the first try), but you are right I probably should go back to "Ask-n*Point" for buylimit and "Bid+n*Point" for selllimits.



FMIC:

Anyway, with pending orders so close to market prices, you should not even be using Pending Orders in the first place. Use Market orders when the required conditions are met. Code your EA to store the Price limits you want and then execute a Market Order when the price is reached. Pending Orders is not the answer! Do it right and stop messing about with the wrong tools for the job!

I've been working with market orders until now, I'm porting now to limit system because obvious inefficiencies experienced in real account (demo account have perfect execution), I would save a lot of energy and time (and yours too, sorry about that) if I stuck to market orders, but it need to be limit.

Reason: