Ghost Trades with Webhooks: Why They Happen & How to Fix Them

Ghost trades webhook debugging code matrix

Ghost trades from webhooks haunt MT5 automation. You check your MT5 account in the morning. There are 3 open positions you did not place. Or worse — your strategy should have closed a trade at TP1, but the position is still running in the opposite direction. These are ghost trades, and they haunt webhook-based trading systems.

A recent Reddit thread in r/algotrading described this exact scenario: "I wake up to ghost trades — phantom orders that my strategy never signaled." The post got 200+ comments, most from traders dealing with the same problem. Here is why it happens and how to fix it.

What Are Ghost Trades?

Ghost trades are unwanted positions on your MT5 account that result from webhook automation errors. They come in three forms:

Cause 1: TradingView Webhook Retries

This is the most common cause. When TradingView sends a webhook, it expects an HTTP 200 response within a few seconds. If your server (or copier) is slow to respond — maybe it is busy executing a previous trade — TradingView assumes the delivery failed and resends the exact same webhook.

Your copier processes both requests. Two identical trades open.

The Fix: Idempotent Signal Processing

Your copier EA must deduplicate incoming signals. The approach:

  1. Generate a hash of each incoming signal (action + symbol + timestamp)
  2. Check if this hash was processed in the last 5–10 seconds
  3. If duplicate, respond with 200 but skip execution
  4. If new, execute and store the hash

TradingView Copier Pro handles this automatically with built-in deduplication. Every incoming webhook is hashed and compared against a sliding window of recent signals.

Cause 2: Race Conditions

When copying to multiple MT5 accounts, a race condition occurs when two EA instances try to process the same signal simultaneously. If the EA does not have proper concurrency handling, both instances may pass the "is this a duplicate?" check before either records it.

The Fix: Atomic Signal Locking

The EA should use a mutex or file lock to ensure only one instance processes a given signal at a time. This is particularly important on VPS setups where multiple terminals share the same data directory.

Cause 3: Failed Close Signals

Your strategy sends a close signal, but it arrives when the market is closed, the terminal is disconnected, or the symbol is different (broker suffix mismatch). The close fails silently. The position stays open. Your next entry signal fires, and now you have two positions where you should have zero.

The Fix: Close Confirmation Loop

Cause 4: TradingView Alert Misconfiguration

Some ghost trades come from the alerts themselves:

MisconfigurationResultFix
Alert set to "Once Per Bar" on 1-min chartFires every minute if condition persistsUse "Once Per Bar Close" or "Only Once"
Multiple alerts on same symbolEach fires independentlyConsolidate into one alert per symbol
Strategy alert without proper exit logicEntries fire but exits do notAdd strategy.close() calls to Pine Script
Invalid JSON in alert messageEA rejects close but opens next entryValidate JSON format

Cause 5: Network Interruption During Execution

Your VPS loses internet for 2 seconds. During that window:

  1. TradingView sends a close webhook → your server is unreachable → TradingView retries later
  2. TradingView sends a new entry webhook → this one gets through
  3. The close retry finally arrives → but now it closes your new position instead of the old one

The Fix: Order-Linked Close Signals

Use magic numbers or trade comments to link close signals to specific orders. When your close signal says "close the trade opened at 10:00", the EA knows exactly which position to target — not just "close all EURUSD."

Pro tip: Always include a magic number or comment field in your webhook JSON to uniquely identify each trade cycle. This prevents close signals from affecting the wrong positions.

Prevention Checklist

CheckAction
Signal deduplicationEA must ignore duplicate signals within 5–10 second window
Fast webhook responseEA must respond HTTP 200 within 1 second to prevent retries
Symbol remappingVerify broker symbol names match your copier config
Alert frequencyUse "Once Per Bar Close" not "Once Per Bar" for strategy alerts
Close confirmationEA verifies positions are actually closed after processing close signals
Magic numbersUse unique trade identifiers to link entries and exits
VPS uptimeMonitor VPS uptime — 99.9% means 8.7 hours of downtime per year
Webhook monitoringLog all incoming webhooks with timestamps for debugging

Zero Ghost Trades. Built-In Deduplication.

TradingView Copier Pro automatically deduplicates signals, confirms close execution, and handles symbol remapping. No phantom orders.

Get TradingView Copier Pro →