Forex Factory (
-   Platform Tech (
-   -   Dealing with "Invalid Price", "Requote", "Server Busy" in MT4 (

Pipologist Mar 6, 2016 9:14pm | Post# 1

Dealing with "Invalid Price", "Requote", "Server Busy" in MT4
In a live ea environment last week, I missed a couple entries at programmed time because of "Invalid Price" (error 129) which mostly came from the market moving away from my entry price beyond the slippage set.

The ea is programmed to trade only on condition and only within an allotted bar/minute, so it didn't resend the order to get a fill after the error 129.

How can I avoid this without accidentally getting more fills than intended?

The ea is programmed to send both a buy and sell at the same time. A few times, only one side got filled. I need it to fill both sides ALL THE TIME when a signal is generated.

Here is the basic buy side routine and changes I've made to resend an order upon error 129. (Sell side logic is the same).

I think it will work...HOWEVER, I am concerned that with this code there is a possibility that it could fill with 2 buys or 2 sells, instead of 1 each.

I understand that I can loop and look for a (OrderType() == OP_BUY), when I tried this, the original order was not sent or filled.

How can I get this to work as intended and always get filled with 1 buy and 1 sell upon error 129, and not accidentally get filled with 2 buys or 2 sells?

Code below:

void fBuy1()
{// RefreshRates();
while(IsTradeContextBusy()) Sleep(100);
int result = OrderSend(Trade,OP_BUY,Lots,Ask,MaxSlippage,0,0,"Open LONG 1B",Magic1B,0,Blue);
int check = GetLastError();
if(check != 0) { Print("Error Sending Order!!! Error code: ", check, " ", ErrorDescription(check)); if (((check == 129) || (check == 138) || (check == 4) || (check == 137)) && (OrdersTotal() < 2)) fBuy1();}
Print(NormalizeDouble(AccountMargin(),2), " MR", " // ", NormalizeDouble(AccountFreeMargin(),2), " FM Available", " // Approx AE: ", NormalizeDouble(AccountEquity(),2), " // M %: ", NormalizeDouble(AccountInfoDouble(ACCOUNT_MARGIN_LEVEL),2)," % " );

Pipologist Mar 7, 2016 6:01am | Post# 2

Of course the answer is "why don't you just test it and see what happens".

Yes. I understand the new code above is LIVE. However, the ea on a slow week only makes two entries and on a busy week maybe 8 or 12 entries. Also the errors are not genereated for every set of trades so it's difficult to know when it will happen next.

I was wondering if anyone has ideas for a valid workaround for those (types of) errors keeping in mind my parameters above.

Thanks in advance.

lukeb Jul 31, 2016 7:19pm | Post# 3

i'm guessing no real solution identified - the risk is always there that you cannot fill at the price desired.
I made an order cart and used the event timer to retry once a second up to maximum try count times before giving up - but, if the price moves, you must either move with it, or hope it moves back in maximum try count times tries (5 as coded).
You can see code here:
The EA uses events - unfortunately, MQ4 does not support events in the strategy tester.

Anyway, make two order carts, one for buy and one for sell, and once they are filled (individually) clear the filled order and hope they both get filled in max try attempts.

© Forex Factory