Algorithmic trading app latency: a practical calculation guide
An algorithmic trading app can show a 2 ms ping to a broker and still produce a 40 ms tick-to-trade path. Ping measures an ICMP round trip.
Evan Hayes·Updated: July 30, 2026·13 min read

It does not include tick decoding, strategy evaluation, order construction, terminal queues, broker risk checks, or matching.
The relevant metric is tick-to-trade latency. It starts when a market-data event reaches the system and ends when the corresponding order message leaves it. For a retail forex Expert Advisor, this interval determines whether a signal is acted on at the observed quote or after the microstructure has moved.
A controlled comparison across 120 trades recorded cumulative slippage of +0.20 pips at 1 ms latency and -1.50 pips at 75 ms. The difference was 1.70 pips. It is not a return forecast. It is an execution-cost observation. The result depends on spread, quote frequency, order type, symbol, broker routing, and strategy turnover.
Deconstructing the tick-to-trade latency formula
Latency is a sum of components, not one network number:
\[
L = P + N + S + I + AP
\]
Where:
- P — propagation time. The time required for the signal to travel through fiber or another physical medium.
- N — network packet processing. NIC processing, kernel networking, routing, and switch handling.
- S — serialization time. The time needed to place packet bits on a link.
- I — interrupt handling. The delay between packet arrival and CPU-level processing.
- AP — application processing. Tick parsing, indicator recalculation, risk logic, order construction, and transmission.
For an automated trading application, the useful measurement is:
\[
T2T = T_{\text{outbound order}} - T_{\text{inbound tick}}
\]
The timestamps must represent the same clock domain. If the tick is timestamped by a broker server and the order is timestamped by a local VPS clock, subtraction is invalid unless those clocks are synchronized.
One-way latency uses the same rule:
\[
L_{\text{one-way}} = T_B - T_A
\]
This requires clock synchronization at nanosecond or near-nanosecond precision. Precision Time Protocol, GPS-synchronized network interface cards, and hardware timestamping exist for this purpose. Most retail stacks do not expose this level of instrumentation. Their measurements should therefore separate local processing time from network round-trip time rather than claim a precise one-way value.
A low ping is a network proxy. Tick-to-trade is an execution measurement.
The distinction changes how an EA or Python process should be audited. A system may receive quotes with low network delay but lose time in the application layer through repeated indicator calls, synchronous logging, memory allocation, locking, or a blocked trade context.
Define the timestamps before measuring
A usable latency log needs fixed event definitions. Without them, a backtest, terminal journal, and packet capture will describe different intervals.
| Timestamp | Event | What it measures |
|---|---|---|
t0 | Tick enters the network interface | Inbound packet arrival |
t1 | Terminal or application receives decoded tick | Network stack and parser delay |
t2 | Strategy creates an order decision | Signal-processing delay |
t3 | Order request leaves the application | Local tick-to-trade latency |
t4 | Broker acknowledges receipt | Network path plus broker gateway delay |
t5 | Fill report arrives | End-to-end execution round trip |
The core metrics then become:
\[
L_{\text{application}} = t3 - t1
\]
\[
L_{\text{network+gateway}} = t4 - t3
\]
\[
L_{\text{fill RTT}} = t5 - t3
\]
A MetaTrader terminal cannot always expose all six timestamps at packet precision. That does not invalidate measurement. It limits the claim. An MT4 or MT5 journal timestamp can identify broad delays. Packet capture and a FIX connection can measure transport events more directly.
The system should not combine a broker fill timestamp with a terminal tick timestamp and label the result “network latency.” That interval includes unknown broker-side processing. Major market makers and tier-1 banks do not publish their internal routing and risk-control latency profiles. Retail brokers also do not provide a uniform breakdown of gateway, risk, liquidity-provider, and bridge delays.
Physical constraints: fiber optics and network hop delays
Physical distance sets a lower bound. Data in fiber propagates at roughly 5 microseconds per kilometer. A 100 km route therefore has about 500 microseconds of propagation delay in one direction before packet handling, switching, and application processing.
This calculation is simple:
\[
P_{\text{fiber}} \approx 5 \ \mu s \times \text{distance in km}
\]
The route length is not the map distance. Fiber follows network paths, building entries, carrier handoffs, and cable routes. The physical cable path can materially exceed the straight-line distance.
A switch hop adds roughly 100 nanoseconds under the stated reference conditions. That number is small relative to retail execution, but it is not zero. In systems targeting microseconds, every hop, cable segment, and queue enters the budget. An additional 200 meters of cabling in each direction adds approximately 1 microsecond of delay.
Retail forex is not a sub-microsecond environment. An optimized C++ stack can reach roughly 8 to 11 microseconds of tick-to-trade latency in specialized conditions. FPGA systems can operate below one microsecond. Those figures require hardware architecture, direct data feeds, controlled network paths, and execution access not available to a standard retail terminal.
An Expert Advisor on a VPS should use a different benchmark. The objective is not to imitate an FPGA. It is to reduce variance and remove avoidable delays from an automated execution system.
The latency budget for a retail forex EA
A practical budget separates components that can be controlled from components that cannot.
| Component | Typical source of delay | Control level |
|---|---|---|
| Broker-to-VPS network path | Geographic distance, carrier routing | Partial |
| VPS-to-terminal delivery | Virtual NIC, host contention, OS network stack | Partial |
| Tick handling | Terminal event queue, custom code | High |
| Signal calculation | Indicators, loops, data copies | High |
| Order construction | Validation, normalization, logging | High |
| Broker gateway | Risk checks, bridge routing, liquidity-provider path | Low |
| Fill and confirmation | Market depth, order type, liquidity state | Low |
The controllable interval is generally t3 - t1: tick reception to outbound order transmission. It should be measured separately from fill time. A strategy can reduce its own processing from 30 ms to 2 ms and still encounter a broker-side delay. The improvement remains real. It should not be overstated as a full execution-path reduction.
Measuring software latency: from tcpdump to Wireshark
The cleanest practical method is packet capture. It records inbound market-data packets and outbound order packets at the network interface. The analyst then calculates timestamp differences rather than inferring latency from terminal logs.
For a FIX-based algo trading app, capture the inbound market-data stream and outbound FIX order messages. For terminal-based systems, the available network protocol may be encrypted or abstracted by the platform. The measurement may then require a combination of packet capture, application logs, and broker acknowledgments.
The procedure is sequential.
1. Select a stable measurement host. Run the application on the VPS or server used for execution. Do not measure from a desktop if the live system runs elsewhere. The test must include the production operating system, terminal build, VPS plan, and network path.
2. Synchronize the clock. Use an NTP source at minimum. Use PTP or hardware timestamping where the stack supports it. Record clock offset during the test. Unsynchronized clocks can create negative or inflated one-way measurements.
3. Capture traffic during a defined session. tcpdump can capture inbound UDP market-data packets and outbound TCP or FIX order packets. The capture window should include liquid and non-liquid periods. A sample drawn only during one quiet interval has limited explanatory value.
4. Identify matching events. In Wireshark, locate the market-data packet that generated the signal and the corresponding order message. The strategy must provide a trace ID, order ID, or timestamp correlation field. Without an event key, matching becomes manual and error-prone.
5. Calculate distributions, not one readings. Report median, 95th percentile, 99th percentile, standard deviation, maximum, and sample count. A 1 ms median with 120 ms spikes is not a 1 ms system.
6. Separate data by condition. Segment by symbol, trading session, spread regime, order direction, order type, and CPU load. EUR/USD during a liquid overlap and an exotic pair during a rollover window do not share the same execution distribution.
A minimal application log should include the following fields:
- UTC timestamp at tick receipt.
- Symbol and bid/ask values.
- Strategy decision state.
- UTC timestamp at order creation.
- Order identifier.
- UTC timestamp at socket send or terminal request submission.
- Broker acknowledgment timestamp, where available.
- Fill timestamp and fill price.
- Requested price, permitted deviation, and spread at decision time.
This structure also improves forex trading app backtesting. Backtests usually process historical bars or ticks without the queueing, network delay, and requote mechanics of live execution. A backtest that assumes immediate fills is a model of signal generation, not a model of deployed performance.
The code path is often slower than the network
MQL4 and MQL5 code can create latency through repeated work rather than through one costly operation. Common sources include recalculating the same indicators on every tick, scanning all historical bars for each event, writing synchronous file logs, querying account state repeatedly, and sending duplicate order-modification requests.
The system rules should be explicit:
- Calculate indicators only when a new bar is required by the strategy. Do not recalculate a 500-bar indicator chain on every quote if the entry logic operates on closed bars.
- Cache symbol properties, point value, digits, and normalized volume constraints.
- Use a single order-state machine. It should distinguish pending submission, accepted, rejected, partially filled, filled, and cancelled states.
- Prevent duplicate orders with a signal timestamp or sequence identifier.
- Record processing duration around each major function: tick intake, signal calculation, risk validation, and order submission.
- Remove synchronous diagnostic logging from the execution path during live measurement. Store counters in memory and flush outside high-frequency events.
- Test terminal CPU use and VPS host contention. A low-latency network path does not offset a process paused by CPU scheduling.
A Python system has additional failure modes. Garbage collection, dataframe operations inside a tick handler, interpreter overhead, blocking REST calls, and global locks can create tail latency. The remediation is architectural: event queues, preallocated structures where possible, asynchronous I/O, bounded logging, and a separation between market-data handling and research code.
Median latency describes the routine path. Tail latency describes the failure path.
The financial impact of latency on retail forex execution
Latency matters only through the mechanism of the strategy. A daily trend system may enter once after a bar close and hold for days. A 50 ms reduction has limited economic weight. A short-horizon mean-reversion EA that trades transient quote changes can have a materially different outcome because its expected move per trade is small.
The relevant comparison is not “fast versus slow.” It is expected execution loss relative to the strategy’s edge.
A simple decomposition is:
\[
E_{\text{net}} = E_{\text{signal}} - C_{\text{spread}} - C_{\text{commission}} - C_{\text{slippage}} - C_{\text{latency}}
\]
Latency cost overlaps with slippage but is not identical to it. Slippage can result from market movement, liquidity depletion, broker routing, queue position, order type, or stop execution. Latency increases exposure to some of those effects by extending the interval between observation and action.
The 1 ms versus 75 ms comparison is useful because it puts the problem into pip terms. Across 120 trades, the measured difference was 1.70 pips of cumulative slippage. That is approximately 0.014 pips per trade:
\[
\frac{1.70}{120} = 0.0142 \text{ pips per trade}
\]
The figure is small in isolation. It is not small if a strategy’s backtested gross edge is only a few hundredths of a pip per trade before costs. Conversely, a system targeting a multi-day move is unlikely to fail because of a 74 ms difference.
Latency analysis should therefore be tied to turnover and expected holding period:
| Strategy type | Typical sensitivity to latency | Main execution concern |
|---|---|---|
| Bar-close trend system | Low | Spread, stop handling, weekend gaps |
| Intraday breakout EA | Moderate | Tick timing, spread expansion, stop-entry behavior |
| Mean-reversion scalper | High | Quote movement, rejection rate, fill variance |
| News-driven automation | High | Queueing, spread discontinuity, broker execution rules |
| Mobile algo trading control layer | Low for control, high if it executes locally | Connectivity loss, background-process limits |
Mobile algo trading requires a separate constraint. A phone should not be treated as a deterministic execution host. Mobile operating systems suspend processes, prioritize battery management, change networks, and lose connectivity. A mobile app can monitor positions, alter parameters, or trigger a server-side process. The order logic should remain on a VPS or dedicated server.
The same separation appears in other metric-driven industries: India’s retail giants are diverging on customer acquisition strategies because one aggregate metric can conceal different operating mechanisms. In execution analysis, a single “latency” number can conceal separate data, application, gateway, and fill processes.
Infrastructure optimization: VPS co-location versus home PC
A VPS located near a broker’s server commonly records network latency of 1 to 5 ms. A retail home PC commonly records 20 to 100 ms. These are network ranges, not guarantees of total trade execution time.
The operational difference is larger than raw distance. A home connection has variable routing, consumer-grade hardware, local Wi-Fi, operating-system interruptions, and power dependency. A VPS removes some of these variables. It also introduces virtualization and host-resource risk, so the selection process should test the specific node rather than rely on a provider’s regional label.
A VPS evaluation should measure:
- Median and percentile RTT to the broker endpoint across several sessions.
- Packet loss and jitter during liquid hours and rollover periods.
- CPU steal time or equivalent host-contention indicators.
- Memory pressure and swap activity during terminal operation.
- Terminal restart time after disconnects.
- Clock synchronization drift.
- Consistency after platform updates and VPS maintenance events.
A latency range of 100 to 300 ms can be operationally acceptable for many retail forex and equity workflows. It is not suitable as a blanket target for every strategy. The target must derive from the strategy’s expected signal half-life and cost budget.
Co-location also has limits. Moving a VPS closer to a broker gateway reduces part of P, the propagation term. It does not remove AP, broker risk checks, liquidity-provider routing, or matching delays. It does not repair a strategy that generates unstable signals. It does not turn a bar-based EA into a high-frequency system.
Optimization sequence
The optimization order should follow measurement evidence.
1. Remove local code delays first. A 25 ms indicator loop is a known defect. Fix it before moving infrastructure.
2. Measure the live network path. Test the execution VPS, not a public latency test page.
3. Replace unstable hosting if tail latency persists. Median latency alone is insufficient. Inspect the 95th and 99th percentiles.
4. Reduce distance only after the application path is stable. Co-location has a measurable physical effect, but only on the network component.
5. Re-run forward tests after each change. Preserve order-level data. Compare spread, rejection rate, slippage distribution, and drawdown, not only latency.
6. Keep backtest assumptions conservative. Apply spread, commissions, delay assumptions, and adverse fill conditions. Historical ticks do not reconstruct broker queues or routing behavior.
The final calculation is not a speed contest. It is a cost-control exercise. Tick-to-trade latency should be logged as a distribution, decomposed into application and transport components, and compared with the strategy’s per-trade edge. A VPS can reduce the network interval from a home-PC range of 20–100 ms toward 1–5 ms. It cannot establish profitability. Backtests remain incomplete because they cannot fully reproduce live routing, spread changes, queue position, and broker-side processing.