Download MetaTrader 5

MT4 scalping problems

To add comments, please log in or register
How to earn at MQL5.community? Come and find out!
HammerJack
97
HammerJack 2013.06.14 07:40 

Hello,

For an automated system I'm working with stop and limit orders. Often these orders seem to get stuck. In the MT4 terminal where the EA is running the order appears as a pending order, but the EA can't touch them anymore (yellow color, if tried to modify you get error "trade is disabled"). If you open another terminal from the same account, you can see that the order actually got filled, but just appears to be stuck in the MT4 terminal where you have the EA running. In the end those stuck orders mess up your whole strategy..


Does anyone have a solution for this one?


Thanks!example

Alain Verleyen
Moderator
30721
Alain Verleyen 2013.06.14 17:05  
HammerJack:

Hello,

For an automated system I'm working with stop and limit orders. Often these orders seem to get stuck. In the MT4 terminal where the EA is running the order appears as a pending order, but the EA can't touch them anymore (yellow color, if tried to modify you get error "trade is disabled"). If you open another terminal from the same account, you can see that the order actually got filled, but just appears to be stuck in the MT4 terminal where you have the EA running. In the end those stuck orders mess up your whole strategy..


Does anyone have a solution for this one?


Thanks!

What your broker said about that ?
HammerJack
97
HammerJack 2013.06.14 20:11  

Their first response was that there were no connection problems at their side for the time I was trading, total not relevant in my opinion. Then they came up with the idea to restart the terminal every once in a while. Well I really can't babysit it all the time. I had contact with two persons at the broker but I don't feel that A) they understand the issue and B) take it serious. That's why I came here.

Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2013.06.14 21:17  
HammerJack:

Their first response was that there were no connection problems at their side for the time I was trading, total not relevant in my opinion. Then they came up with the idea to restart the terminal every once in a while. Well I really can't babysit it all the time. I had contact with two persons at the broker but I don't feel that A) they understand the issue and B) take it serious. That's why I came here.

Typical Broker type response that is similar to what I have experienced.  

When these orders appear stuck what kind of CPU activity is the terminal showing in the task manager ?  and how many cores/hyperthreading virtual cores do you have ?

HammerJack
97
HammerJack 2013.06.14 21:24  
CPU activity is around 20-30% on a 2 cores CNS VPS. You think this has anything to do with that? It happens both with limit and stop-orders. Once an order gets stuck there is nothing you can do with them , not manual, not by EA (orderdelete/ordermodify). Also if the price goes back to where the order actually got filled (but didn't show) then it stays "untouchable. If you open another terminal for the same account you see the order filled. And a restart of the "problem terminal" lets you see the order in proper state. I've seen it with 2 brokers now. I think it might have something to do with MT4. Any ideas are welcome..
Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2013.06.14 21:39  
HammerJack:
CPU activity is around 20-30% on a 2 cores CNS VPS. You think this has anything to do with that? It happens both with limit and stop-orders. Once an order gets stuck there is nothing you can do with them , not manual, not by EA (orderdelete/ordermodify). Also if the price goes back to where the order actually got filled (but didn't show) then it stays "untouchable. If you open another terminal for the same account you see the order filled. And a restart of the "problem terminal" lets you see the order in proper state. I've seen it with 2 brokers now. I think it might have something to do with MT4. Any ideas are welcome..
I wondered if the EA was working MT4 so hard that it wasn't able to update it's order pool correctly . . .  have you tried stopping the EA for a few seconds and then letting it run again ?  if it is tieing up MT4 this should let MT4 update it's order pool.
HammerJack
97
HammerJack 2013.06.14 21:57  

Well, I tried also this:

1. Run MT4 + the EA

2. Wait for one or more orders to get stuck

3. Stop the EA but keep the MT4 terminal running

4. delete/close the stuck order(s) by hand

But step 4 didn't work.

I see no other possibility to do anything with those stuck orders.

Paule Panke
123
Paule Panke 2013.06.14 22:51  

This is a common error with scalping strategies ie. tight limit/stop orders. I'm surprised you didn't yet get any useful answers. Probably the only thing you can do is changing the broker for those strategies.

The error goes like this:

1) The terminal sends a tight stop/limit order via OrderSend() and is waiting for a response from the trade server. This usually takes a few ms, let's say 200.

2) Now, before the trade server sends back an answer the stop is already triggered and the info about that opened position is sent back to the terminal. Communication works via a FIX like dialect, it's possible to send and receive multiple messages at the same time.

3) The message about the opened position arrives at the terminal, with a ticket # attached.

4) The terminal is still waiting for an answer to the OrderSend-call, it doesn't know the newly arrived ticket belongs to the OrderSend-call (because OrderSend didn't yet return) and stores the ticket under "open position".

5) A few ms later the answer to OrderSend is coming in and, surprise-surprise, the attached ticket is a ticket the terminal is now already managing under "open positions".

6) Now the terminal "thinks" an open position somehow changed back to a pending order. This of course is impossible and for that reason the terminal doesn't know what to do and blocks the ticket. Something is wrong here.

7) After terminal restart everything is ok again because all open/pending tickets are re-read from the trade server.

Summary:

It happens if a fill message arrives earlier then the OrderSend causing that fill. One could argue it's a bug in the terminal but on the other hand the behaviour of the terminal is reasonable. The real cause is a bad network connection or slow back office at the broker side but of course, the broker will never agree to this. Your connection is fine, the quick arrival of the fill message proofes it.

Most brokers run a bridge between MT4 trade server and liquidity provider. It's unbalanced latency in this bridge and the connected back office software that's causing the error. Hundreds of users get queued for back-office processing of orders and need to wait, the fills itself on the other hand are reported very quickly and go straight through. Not much you can do other then widen your stop/limit or change the broker.

Paule Panke
123
Paule Panke 2013.06.14 23:21  

because widening the stop is counter productive i was thinking about another solution. workaround idea:

place your orders in two steps. this costs you another 200-300 ms execution time but prevents the error.

1) first stop/limit let's say 10 pips away (far enough to not trigger the error).

2) immediately after it send an OrderModify() with the real tight stop. now all that can happen is an ERR_INVALID_PRICE but the real ticket is already known to the terminal and correctly managed under "pending orders".

HammerJack
97
HammerJack 2013.06.15 08:17  
That's some good info there Pauepanke, thanks a lot! I can see the logic from it and will test it out next week. Curious how overall performance will chance because of this. Eager to test it. Thanks again!
Paule Panke
123
Paule Panke 2013.06.15 09:16  

a second approach saving the execution cost of the additional first order:

if your strategy starts up you always put one buy pending/limit and one sell pending/limit order in the market, very far away, say 1000 pips. these two orders always rest there. if your entry condition is met you only modify one of those two orders, aiming for an immediate fill without slippage. after the fill you have plenty of time to place a new resting order far away from the market.

this way you move the additional overhead of another order "after" the placement of the real/critical one.

12
To add comments, please log in or register