Whale Order Spoof Trap
- Experts
- Versione: 1.0
Overview
Anti-Spoofing Strategy (v1.0) is a live-market Expert Advisor designed to detect and counter high-frequency DOM (Depth of Market) spoofing manipulations in ECN/STP environments.
The system monitors real-time Level-2 order book changes via MarketBookGet() and identifies large fake orders that appear and vanish within milliseconds — a hallmark of spoofing.
Once such manipulations are detected, the algorithm opens a counter trade in the opposite direction of the spoof, anticipating the true market intent after liquidity manipulation is withdrawn.
For MQL5 Market validation purposes (where DOM data isn’t supported), the EA includes a Validation Mode that substitutes the real spoofing logic with a simple Moving Average crossover system to pass compilation and validation.
How the Strategy Works
1. Spoofing Detection
-
The EA subscribes to live Market Depth using MarketBookAdd(_Symbol) .
-
For each book update, it scans top DOMBookDepth levels.
-
When a large order (≥ SpoofMinVolume) is detected (either on the ASK or BID side), it’s recorded with timestamp and volume.
-
If that large order disappears within SpoofDetectionTime milliseconds, it is flagged as a spoofing event.
2. Spoofing Confirmation
-
Each detected spoof entry (ASK = fake sell, BID = fake buy) is monitored.
-
If price breaks through the spoof level in the opposite direction (e.g., after a fake sell wall disappears, price breaks upward), it confirms manipulation.
-
At this moment, the EA prepares to open a counter trade.
3. Counter Trade Logic
Spoof type:
-
ASK (Fake Sell) → Expect breakout upward → Open BUY
-
BID (Fake Buy) → Expect breakout downward → Open SELL
Once confirmed:
-
Stop Loss (SL) = StopLossPips × 10 × Point from spoof level.
-
Take Profit (TP) = TPMultiplier × SL distance.
-
Trade volume is normalized ( GetNormalizedLot() ) and checked against margin using OrderCalcMargin() .
-
Each position uses a unique MagicNumber to isolate EA trades.
4. Spread & Session Filters
Before entering any trade:
-
Spread Check: If current spread exceeds MaxSpread , trade is skipped.
-
Session Filter: Only trades during active liquidity hours:
-
London Session: 08:00–17:00 GMT
-
New York Session: 13:00–22:00 GMT
These can be toggled independently.
-
5. Validation Mode (For MQL5 Market)
When EnableValidationMode = true :
-
The EA disables all DOM logic and uses two SMAs ( 10 and 30 periods).
-
A BUY occurs when Fast MA crosses above Slow MA; SELL when the reverse happens.
-
Trades are spaced by ValidationTradeFrequency bars.
-
This mode ensures smooth validation while preserving the internal structure.
6. Timeout & Safety
-
Old spoof detections (older than 60 seconds) are ignored.
-
If insufficient margin or invalid SL/TP distances are detected, trade execution is aborted safely.
-
The EA auto-releases all indicators and DOM subscriptions on deinit.
Explanation of Input Parameters
Spoofing Detection (Real Trading Only)
-
SpoofMinVolume: Minimum order book volume (in lots) to be considered potential spoof.
-
SpoofDetectionTime: Time threshold (ms) — if a large order vanishes faster, it’s flagged.
-
DOMBookDepth: Number of depth levels analyzed from the order book.
Risk Management
-
StopLossPips: Stop-Loss distance in pips.
-
TPMultiplier: Take-Profit multiplier (e.g., 2.0 means 2×SL distance).
-
MaxSpread: Maximum allowed spread in pips before blocking entry.
Trade Settings
-
LotSize: Trade volume per position.
-
InpMagicNumber: Unique ID for position tracking.
Session Filter
-
TradeInLondonSession: Enable trades during London session hours.
-
TradeInNYSession: Enable trades during New York session hours.
Validation Mode (Testing Only)
-
EnableValidationMode: If true, switches to MA crossover for validation.
-
ValidationTradeFrequency: Interval between trades (in bars) in validation mode.
Practical Notes & Tuning
-
Execution Mode: Works only on live or demo accounts with full Level-2 (DOM) support.
Not functional in Strategy Tester (MQL5 doesn’t emulate DOM). -
Validation Compatibility: Default mode passes MQL5 Market checks using standard indicators.
-
Broker Dependence: Requires ECN/STP brokers providing Market Depth — many retail brokers hide Level-2 data.
-
Spoof Timing Sensitivity:
-
Too short ( <500ms ) may miss manipulations.
-
Too long ( >3000ms ) risks including real orders.
-
-
Volume Calibration: Adjust SpoofMinVolume per symbol (indices/crypto require larger thresholds).
-
Spread Control: Recommended to keep MaxSpread conservative for high-volatility pairs.
-
DOM Refresh Rate: Frequent book updates may cause CPU load — consider depth = 10–15 levels.
Important Risk Disclosure
Automated trading and DOM-based algorithms involve significant market risk.
-
Capital Risk: You can lose all or part of your invested capital.
-
Latency & Data Feed: DOM updates are broker-dependent; slow or delayed feeds can trigger false detections.
-
Liquidity Shifts: Sudden news or low-volume periods amplify spoof false positives.
-
Execution Delay: High-frequency conditions may cause slippage on spoof breakouts.
-
Testing Limitation: DOM logic cannot be realistically backtested in MetaTrader; forward-demo testing is essential.
-
Broker Variation: Tick size, min stop levels, and commission structures directly affect results.
Trade only on trusted brokers with verified Market Depth infrastructure and risk-tested parameters.
