Advertisement IC Markets

Holding an EA back for a few minutes after the terminal reconnects

Share, develop, and backtest custom MQL4/MQL5 Expert Advisors, Python data-scraping scripts, trading bots, and automated market alert systems.
Post Reply
Fairman
Posts: 6757
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

Holding an EA back for a few minutes after the terminal reconnects

Post by Fairman »

Holding an EA back for a few minutes after the terminal reconnects

If your terminal loses its connection to the server and then reconnects, the first few ticks that come through can be unreliable. Some brokers send a burst of stale prices, sometimes the spread is unusually wide, and occasionally the price jumps to catch up with where the market moved while you were disconnected.

An EA that runs on every tick will try to act on those prices. For a scalping system with tight entry rules, a sudden jump in price can look like a breakout or a signal, and the EA fires an order into a market it doesn't really understand yet.

What I do now is track the connection state. In MQL, TerminalInfoInteger with TERMINAL_CONNECTED tells you whether you're connected. When the EA sees it go from disconnected to connected, it records the time and refuses to open new trades for a set period afterwards, a couple of minutes in my case. It still manages existing positions, since you'd want exits to work.

This is a cheap safety measure. The worst case is you miss a signal in the first two minutes after a reconnect, which is rare. The best case is you avoid an order based on a price spike that was really just the feed catching up.

If you run on a VPS this matters less, since disconnects are rarer, but they still happen during broker maintenance.
It’s Fairman :geek:
Recommended broker for automated trading & scalping IC Markets
FXS HongKong Scalper
Posts: 406
Joined: Sat Oct 24, 2026 10:15 pm

Re: Holding an EA back for a few minutes after the terminal reconnects

Post by FXS HongKong Scalper »

Holding off after a reconnect is sensible. One detail that helps is to wait for a set number of normal ticks rather than a fixed time. After a reconnect at a busy time, a few seconds may be enough. In a quiet hour like the Asian afternoon, five minutes might pass with only a handful of ticks. Requiring, say, twenty ticks with a spread under the normal level before the EA is allowed to trade adapts to both cases. The OnTradeTransaction event can also be checked to make sure no orders were filled during the outage.
FXS Official Team | Hong Kong Session Desk
Fairman
Posts: 6757
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

Re: Holding an EA back for a few minutes after the terminal reconnects

Post by Fairman »

Indicators also need care after a reconnect. If the EA uses moving averages or ATR, those are calculated from the bars on the chart. If bars were missing during the disconnect, the platform may fill them in after reconnecting, and indicator values can change. Giving the EA a short delay lets the history update before it starts making decisions based on indicators. Calling the indicator functions after a short delay, rather than the moment the connection returns, gives the platform time to download the missing bars. You can also check that the latest bar time matches the current server time before letting the EA use any indicator values.
It’s Fairman :geek:
Fairman
Posts: 6757
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

Re: Holding an EA back for a few minutes after the terminal reconnects

Post by Fairman »

A simple log line with the disconnect and reconnect times helps a lot when reviewing problems later. If you notice odd trades, being able to check whether they happened right after a reconnect saves time. I write a line to the Experts log each time the connection state changes, with the time and the last known price, so I can match them to any unexpected trades. Include the spread at the moment of reconnection too. Wide spreads on the first ticks after a reconnect are common, and having that number in the log explains a lot of odd entries if they happen.
It’s Fairman :geek:
Fairman
Posts: 6757
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

Re: Holding an EA back for a few minutes after the terminal reconnects

Post by Fairman »

Some brokers do weekend maintenance that disconnects terminals for a while. If your EA starts trading the moment the Sunday open arrives, the first ticks can be particularly messy. I extend the delay after the weekend open, since spreads are typically wide and prices can gap. The same delay logic handles it if you treat the weekend open as another reconnect. A useful approach is to treat the first tick after any long gap in incoming ticks the same way as a reconnect. If no tick has arrived for several minutes, whatever the reason, the EA waits before opening trades. That covers the weekend, maintenance and some network problems with one rule.
It’s Fairman :geek:
gwhitlock64
Posts: 47
Joined: Tue Oct 20, 2026 11:01 pm

Re: Holding an EA back for a few minutes after the terminal reconnects

Post by gwhitlock64 »

Had a proper wobble with this a while back, mate. Left a scalper running over a weekend on a dodgy home connection, and the broker did some maintenance that I knew nothing about. Sunday night it reconnected, the spread was bloody massive, and the EA dived into a trade on the first jumpy tick. I woke up to a loss that was about the price of a decent round at my local... gutted, tbh. Wasnt a disaster but it was wierd looking at the log and seeing the entry time sat right on the reconnect, which is how I realised what had happened. Now it just sits on its hands for a good few minutes after the open, cheers to a very annoying Sunday for that.
Fairman
Posts: 6757
Joined: Tue Jul 21, 2026 7:11 am
Location: Abuja

Re: Holding an EA back for a few minutes after the terminal reconnects

Post by Fairman »

On the testing side, it's hard to simulate disconnects in the strategy tester. So this kind of logic usually only gets tested live or on demo. I'd run it on a demo account for a while and deliberately disconnect the terminal a few times to check that the EA pauses and resumes as expected. It's better to find a bug there than on a live account. Pulling the network cable or disabling the connection for a minute is enough to test it. Check that the EA logs the event, waits the correct time and resumes normally. Testing a few times in different situations gives confidence it will work when a real disconnect happens.
It’s Fairman :geek:
Post Reply