How to cancel order if it takes too long to open
-
Hi!
I am running my EA on my real account. The EA opens orders (buys or sells) at market price, using a simple "Buy Now" and "Sell Now" block.
Sometimes the trade takes too long to open, I believe the delay happens because of the broker. Here are some examples:
2019.09.03 12:19:39.188 xxxxx Operation details: Speed 78 ms | Slippage 0.0 pips
2019.09.03 12:29:43.792 xxxxx Operation details: Speed 3204 ms | Slippage 0.0 pips
2019.09.03 15:30:14.486 xxxxx Operation details: Speed 4875 ms | Slippage 0.0 pips
2019.09.03 15:56:25.387 xxxxx Operation details: Speed 3390 ms | Slippage 10.0 pips
2019.09.03 15:56:25.387 xxxxx Correcting stops because of slippage...
2019.09.03 15:57:44.715 xxxxx Operation details: Speed 5062 ms | Slippage -15.0 pips
2019.09.03 15:57:44.715 xxxxx Correcting stops because of slippage...
2019.09.03 15:59:39.500 xxxxx Operation details: Speed 2266 ms | Slippage 10.0 pips
2019.09.03 15:59:39.500 xxxxx Correcting stops because of slippage...
2019.09.03 16:02:32.633 xxxxx Operation details: Speed 2953 ms | Slippage 0.0 pips
2019.09.03 16:03:36.914 xxxxx Operation details: Speed 4250 ms | Slippage 0.0 pips
2019.09.03 16:05:52.391 xxxxx Operation details: Speed 43797 ms | Slippage -65.0 pips
2019.09.03 16:05:52.391 xxxxx Correcting stops because of slippage...
2019.09.03 16:07:08.739 xxxxx BuildOrdersList() - Error #4754
2019.09.03 16:07:49.001 xxxxx Operation details: Speed 2468 ms | Slippage 0.0 pips
2019.09.04 09:05:34.767 xxxxx Operation details: Speed 2578 ms | Slippage -10.0 pips
2019.09.04 09:05:34.767 xxxxx Correcting stops because of slippage...
2019.09.04 09:06:11.204 xxxxx Operation details: Speed 4937 ms | Slippage 5.0 pips
2019.09.04 09:06:11.204 xxxxx Correcting stops because of slippage...
2019.09.04 09:07:57.682 xxxxx Operation details: Speed 53890 ms | Slippage -25.0 pips
2019.09.04 09:07:57.682 xxxxx Correcting stops because of slippage...
2019.09.04 09:20:04.115 xxxxx Operation details: Speed 1235 ms | Slippage 0.0 pips
2019.09.04 09:34:10.400 xxxxx Operation details: Speed 31 ms | Slippage 0.0 pipsMy ping to the broker is at 3 or 4 ms. While a few trades are opened very fast (less than one second), a couple trades takes almost one minute!
I want to know if it's possible to cancel orders that takes more than 10 seconds to open. Is there a block (or code) that monitors how long a trade is taking to open, and cancel it if it takes too long?
Thanks.
Rafael -
@rafaelgrecco I'm not aware of any max ordersend time value. However, you may control the price difference with the slipage settings instead. Or does it matter if you get the same price 10 seconds later?
By the way, which broker are you using? Times appear very long to me. -
@trader-philipps actually time does not matter as long as price remains the same.
But I see that by default, the Slippage is set to "4" pips on the Buy and Sell Now blocks. I am getting slippages a lot bigger than that... should I change or add something else to make it work?
About the broker, it is a "futures" broker in Brazil, it is not Forex. It is actually the best national broker here in Brazil, it ususally has very tigh spreads and fast execution times, but there are days that it gets bad for no apparent reason.
Thank you for your help.
EDIT: By the way, tick size is 5 on the symbol I trade. Usually the slippage is 0.0, but I would be ok with slippage up to 10 pips.
On the examples I posted, there is a trade where slippage is 65 pips

-
Is the open price very close to Ask/Bid? Probably your broker needs a wider distance between them.
-
@l-andorrà I am using "Buy Now" and "Sell Now" blocks. The trade opens at current Ask/Bid price, there is no distance. Just use the available price quotes.
The problem is that sometimes the trade is executed in less than a second (which is normal) and another time it is executed in 20... 30.. 40 seconds!
I wanted to cancel the execution if it took that long.
-
@rafaelgrecco the ordersend function has a time parameter, but I think that is only valid for pending orders and determining the point in time the pending order expires.
int OrderSend(
string symbol, // symbol
int cmd, // operation
double volume, // volume
double price, // price
int slippage, // slippage
double stoploss, // stop loss
double takeprofit, // take profit
string comment=NULL, // comment
int magic=0, // magic number
datetime expiration=0, // pending order expiration
color arrow_color=clrNONE // color
);Same say the order blocks buy and sell.

Are you trading low liquid assets? Otherwise I'd take the order times and get in contact with broker's support and let them explain you the reason. On order open that may not be an issue if you get the price you want (or could use limit order), but for closing the order that can cost you a lot of money!
-
@trader-philipps thanks for the tips.
I don't think "expiration" field will help. The lowest value possible is 1 minute. I would have to use something like 10 or 15 seconds (which is already a looong time for a trade to be executed).
The asset I am trading is the most liquid asset in Brazil. I'll contact my broker's support to see their explanation.
-
Did you check your LAN/WAN connection? You may have connection issues. For example, I had similar issues with WLAN.
-
@paragorundu said in How to cancel order if it takes too long to open:
Did you check your LAN/WAN connection? You may have connection issues. For example, I had similar issues with WLAN
@rafaelgrecco Good Point. I'm always using VPS with good connection to the broker. Didn't think about someone could run EAs from home :))
-
LOL @trader-philipps you may have to bro, believe me LOL
-
@paragorundu There is free VPS for one year at Google, and Amazon as well.
-
@cpxiom Thank you

-
@paragorundu
search on youtube "mt4 VPS" , and you will find instructions and everything.
Make sure you limit the mt4 to 5000 history, and 5000 bars, or even 1000, otherwise it consumes a lot of CPU and has problems with the free versions of setups available.
So also check out on youtube "sluggish mt4", speed up mt4... etc.
-
Dear @cpxiom,
I really thank you so much for sharing such valuable information with us. It will be very helpful.
Regards.
-
Hey, just to be clear I am using a VPS with a ping of 3 ms to the broker.
My VPS is actually on the same data center that the broker uses. Connection is not an issue.
Today all trades are getting executed in 30-40 ms.
My problem is that eventually the broker messes something up and trades takes several seconds (sometimes up to 40 or 50 seconds) to execute the trade, and I wanted a way to prevent the trade from being executed when that happens.
-
@paragorundu
glad I was of help. -
@rafaelgrecco I understand.
Maybe this tool can be useful for you to test broker execution time and see if there is really a problem with execution of market orders in time?
-
@paragorundu I don't think that that might help as it only places stop orders, which doesn't cause an order that has to be filled. I'd say it's absolutely a broker issue.
-
@trader-philipps Yeah, I've talked to other people that also uses my current Broker (or any Broker in Brazil) and it seems it is a common problem.
Unfortunately there's nothing I can do, like changing brokers... all I wanted was a way to cancel the trade if it took too long to be executed, but I don't think that's possible
