Bots & Automation

Making Trading Bots Reliable: Restarts, Disconnects and Duplicate Orders

The technical failures that hurt trading bots most - restarts, lost connections, rejected and duplicate orders, missing stops - and the design patterns that keep a bot safe when things go wrong.

By AlgoXP3 min readUpdated

Reliable order flow with retries with backoff and an error queue so failures are never silent

A trading bot’s logic can be perfect and still lose money through technical failures: it restarts and forgets its positions, the connection drops during an order, an order is rejected and never retried, or retried too often. Reliability is the unglamorous part of algorithmic trading that decides whether live results look anything like the backtest.

Failure 1: restarts that forget the state

Bots restart more often than you think: platform updates, server maintenance, VPS reboots, manual restarts after a parameter change. A bot that assumes it starts with no positions will happily open a second one.

Pattern: reconstruct state on start.

  • Give every position a label that identifies the bot and the symbol.
  • In the start event, find existing positions and pending orders with that label and continue managing them.
  • Store anything else you need (daily P/L reference, last signal time) where it survives a restart, or recompute it from history.

Failure 2: duplicate orders

A signal is evaluated twice, or an order request times out and the bot sends it again - and both fill.

Pattern: idempotent actions.

  • Decide once per bar (on bar close), not on every tick.
  • Before sending, check whether a position or order for this signal already exists.
  • After a timeout, check the account state before retrying; the first request may have succeeded.

Failure 3: rejected orders

Brokers reject orders for many reasons: volume below the minimum or not a multiple of the volume step, stop too close to price, market closed, not enough margin.

Pattern: validate, then classify errors.

  • Validate before sending: round volume to the symbol’s step, respect minimum and maximum volume, check stop and target distances, check trading hours.
  • Classify failures: temporary (server busy, connection) can be retried a few times with increasing delay; permanent (invalid parameters, not enough money) cannot - log and alert.
  • Cap retries so a persistent problem does not turn into a flood of requests.

Failure 4: positions without protection

A position opened, but setting the stop loss failed. Now the bot holds unlimited risk.

Pattern: protect at entry and verify.

  • Send stop loss and take profit with the order whenever the platform allows it.
  • After any fill, verify that the position has a stop. If not, set it - and if that fails, close the position and alert.

Failure 5: disconnections and gaps

During a disconnection, the bot misses ticks and bars. When it reconnects, conditions may have changed: a stop level passed, a session ended, a signal is stale.

Pattern: re-evaluate after reconnecting.

  • Treat signals as valid only for a limited time; do not enter on a signal from three bars ago.
  • Re-check open positions and pending orders.
  • Log every disconnection and its duration.

Failure 6: silent crashes

An unhandled exception stops the bot; nothing alerts you until you notice a missing trade days later.

Pattern: handle exceptions and send heartbeats.

  • Catch and log exceptions in the bot’s event handlers rather than letting one bad value stop everything.
  • Send a regular heartbeat and alert on its absence - see monitoring trading bots.

Failure 7: running on the wrong machine

Laptops sleep, update and lose Wi-Fi. A bot is only as reliable as the computer it runs on.

Options:

  • Cloud instances provided by the platform: always on, no maintenance, but sometimes with restrictions (for example on outgoing internet requests).
  • VPS or dedicated server: full control and network access; you are responsible for updates and monitoring. cTrader also offers a command-line version that can run cBots on a server or in Docker.
  • Home computer: fine for testing, risky for live trading.

Test failures before they happen

Reliability can be tested on a demo account:

  • Stop and restart the bot with an open position. Does it continue managing it?
  • Disconnect the network for a few minutes. What happens on reconnect?
  • Set an invalid volume on purpose. Is the error handled and reported?
  • Run over a weekend. Does it behave correctly at the Monday open?

Key takeaways

  • Reconstruct state on start; identify the bot’s positions by label.
  • Make actions idempotent and check account state before retrying.
  • Validate orders, classify errors, cap retries.
  • Protect every position at entry and verify the stop exists.
  • Run live bots on always-on infrastructure and monitor their heartbeat.

FAQ

Why does my bot open a second position after a restart?

Because it does not reconstruct its state on start. A reliable bot identifies its own positions (for example by a label) when it starts and continues from there instead of assuming a clean slate.

Should the bot retry rejected orders?

Only for temporary reasons and only a limited number of times. For permanent reasons such as invalid volume or stop distance, retrying just repeats the error; log it and alert instead.

Where should a bot run to be reliable?

On a machine that is always on and connected: a cloud instance, a VPS or a dedicated server. A home laptop that sleeps or loses Wi-Fi is the most common cause of missed trades.

Sources and further reading

  1. cTrader Help: cBot lifecycle - help.ctrader.com
  2. cTrader Help: cBot operations with cTrader CLI (VPS and Docker) - help.ctrader.com