PROJECT SPECIFICATION — MT4 Indicator: Execution & Broker Monitor 1. Objective Develop an MT4 Indicator (not an EA) that monitors account-wide execution quality and platform health in real time and produces: * On-screen text display (fixed-width font) * Persistent log files * Real-time alerts (popup + optional email) The indicator reads all trade and broker-communication activity generated by: * Manual trades * Expert Advisors * Script activity * Internal MT4 trade processing The indicator does not place, modify, or manage trades. What a Indicator must track falls into two buckets Bucket 1 — Trade-Level Recorded Data (Section 4) Only data that applies to a specific order ticket goes here: * Ticket * Symbol * Order Type * Lots * Broker Timestamp * Spread at execution * Slippage at open * Slippage at close * Latency at open * Latency at close * Commission * Swap * P/L * Magic Number This is per-trade reporting. ________________ Bucket 2 — Platform/Broker Health Monitoring (Section 9) This is continuous system-level monitoring, independent of any single trade: * Clock Drift Detection * Server Disconnection Tracking * Ping Monitoring & Ping Volatility * Execution Variance Detection * Swap/Commission Change Detection * Contract Spec Change Detection * Spread Manipulation Pattern Detection * Requote / Rejection Pattern Tracking This is trade environment health. ________________ 2. Scope Applies Account-Wide To: * All symbols * All trades (manual + EA) * All order types * All outbound broker messages Platform MetaTrader 4 (MQL4) ________________ 3. Terminology Clarification Message Count: Every outbound instruction to broker (trades, closes, modifications, cancellations, etc.). Latency: Time between order send and broker fill confirmation. Slippage: Difference between requested price and executed price. Queue vs Stack Alerts (Your Decision): You confirmed alerts should simply fire as they occur with normal popup behavior. No deferring or bundling. ________________ 4. Monitoring & Data Collection (Two Categories) 4.1 Trade-Level Execution Data (Recorded Per Ticket) For every order open and close, the indicator shall record: 1. Ticket Number 2. Symbol 3. Order Type (Buy/Sell) 4. Lot Size 5. Broker Timestamp 6. Spread at Execution (points) 7. Slippage-Open (points) 8. Slippage-Close (points) 9. Latency-Open (milliseconds) 10. Latency-Close (milliseconds) 11. Commission 12. Swap 13. Profit / Loss 14. Magic Number (if any) This data shall appear both on-screen and in the text log file. ________________ 4.2 Platform & Broker Health Monitoring (Continuous — Account-Wide) The indicator shall also continuously monitor, display, log, and alert on the following: Clock Drift Detection * Measure difference between TimeCurrent() (broker time) and TimeLocal() (PC time) * Log drift value continuously * Trigger alert when drift exceeds ClockDriftAlertSeconds Server Disconnection Monitoring * Detect connection losses and reconnections * Count disconnection events per day * Track total time disconnected * Trigger alert if disconnected longer than DisconnectionAlertSeconds Ping & Latency Health Monitoring * Track average ping * Track maximum ping * Track ping volatility * Trigger alert if ping > PingAlertMS * Trigger alert if ping volatility exceeds threshold Execution Variance Detection * Maintain rolling slippage & latency statistics for last 5 / 20 / 100 trades * Compute mean & standard deviation * Trigger alert when current values exceed: Mean + (StdDevMultiplier * StdDev) Spread Manipulation Pattern Detection * Track average spread * Track maximum spread * Track spread volatility * Trigger alert if current spread is abnormal versus baseline Swap & Commission Change Monitoring * Detect and log any change to swap settings or commission rate * Trigger alert when detected Contract Specification Change Monitoring * Detect changes to contract parameters * Log and alert when detected Requote / Rejection Pattern Monitoring * Track frequency and time-of-day clustering of execution errors * Alert if frequency exceeds user-defined thresholds All monitored values shall be displayed in the on-screen panel and written to the daily log file. ________________ 5. Broker Message Activity Counter (Account-Wide) Track all outbound broker messages in real-time. Behavior * Message counter resets at broker midnight * Count increments on all trade-related communications Inputs MessageAlertLevels = 10000,11000,12000,13000,14000 Alerts * Popup + optional email at each threshold ________________ 6. Real-Time On-Screen Display The indicator displays text only using a fixed monospaced font. Top Section — Health Summary Example format: Account Balance: 10,000.00 Equity: 9,320.00 Drawdown %: 6.8% Messages Today: 12,438 Avg Slippage: 21 pts Avg Latency: 152 ms Max Slippage Today: 84 pts Max Latency Today: 612 ms Ping Avg: 23 ms Clock Drift: 1.4 sec Disconnections Today: 2 Trade Log Section (Last N Trades, Default 20) Ticket | Type | Lots | Symbol | Spread | SlipOpen | SlipClose | LatO(ms) | LatC(ms) | Time User-configurable row count. ________________ 7. Logging Requirements Everything logged to text files in MQL4/Files/. * Append-only * Never overwrite * Include timestamps (broker time) * One file per day OR continuous — coder may choose, but must be consistent User must be able to download logs later. ________________ 8. Guardrail Monitoring & Alerts A. Slippage Threshold Alert Trigger if |slippage| > SlippageAlertPoints B. Latency Threshold Alert Trigger if latency > LatencyAlertMS C. Spread Threshold Alert Trigger if spread > SpreadAlertPoints D. Drawdown Alert Trigger if equity drawdown > DrawdownAlertPercent E. Broker Message Count Alerts (alert at configured thresholds as above) F. Trade Failure Alert Trigger on errors such as: * Requotes * Rejected orders * Trade context busy * No connection * Retry loops Log the MT4 error code. ________________ 9. Advanced Monitoring Modules 9.1 Clock Drift Detection Compare: * TimeCurrent() (broker time) * TimeLocal() (PC time) Trigger alert if: Drift > ClockDriftAlertSeconds Also store maximum drift today. ________________ 9.2 Server Disconnection Monitoring Monitor: * Connection loss * Reconnection events * Total time disconnected * Count of disconnect events Trigger alert when: Disconnected > DisconnectionAlertSeconds ________________ 9.3 Ping Monitoring & Volatility Tracking Collect ping samples at intervals. Store: * Average ping * Maximum ping * Ping standard deviation Trigger alert when: * Ping > PingAlertMS * Ping volatility rises above threshold ________________ 9.4 Execution Variance Monitor Maintain rolling stats: * Last 5 trades * Last 20 trades * Last 100 trades For slippage & latency. Trigger alert when: Current value > Mean + X * StdDev Value X user-configurable. ________________ 9.5 Swap & Commission Change Alerts Alert if broker changes: * Swap value pattern * Commission per lot ________________ 9.6 Contract Specification Change Alert Monitor symbol contract details. Alert if any change detected. ________________ 9.7 Spread Manipulation Pattern Detection Track: * Avg spread * Max spread * Spread standard deviation Trigger alert when spread becomes abnormal vs baseline. ________________ 9.8 Requote / Rejection Pattern Monitor Track: * Requote count per day * Rejection count per day * Most common error codes * Time-of-day clustering Trigger alert when patterns rise above threshold. ________________ 10. Drawdown & Margin Monitoring Monitor in real-time: * Account equity * Margin level * % exposure Alert on: Drawdown > DrawdownAlertPercent MarginLevel < MarginLevelAlertPercent ________________ 12. Alert Channels User-configurable: * Popup * Email (use MT4 email settings) * Sound optional Include parameter: EnablePopupAlerts = true/false EnableEmailAlerts = true/false EnableSoundAlerts = true/false MinAlertIntervalSeconds = 30 This prevents alert spam. Include Mute Alerts Toggle in inputs. ________________ 13. Indicator Inputs (Summary) Developer should implement user-editable inputs including: * MessageAlertLevels * SlippageAlertPoints * LatencyAlertMS * SpreadAlertPoints * DrawdownAlertPercent * MarginLevelAlertPercent * ClockDriftAlertSeconds * DisconnectionAlertSeconds * PingAlertMS * PingVolatilityAlertPercent * RollingStatStdDevMultiplier * MaxRowsDisplayed * Enable/Disable-per-Module Toggles * Alert Channel Toggles * Alert Mute Toggle * MinAlertIntervalSeconds ________________ 14. Performance Requirements * Must not freeze charts * Must handle high-frequency environments * Efficient memory handling * Safe logging ________________ 15. Visual Requirements * No graphics — text-only * Fixed monospaced font * Clear columns * White text on transparent background preferred ________________ 16. What The Indicator Will NOT Do * Will not open or modify trades * Will not toggle AutoTrading * Will not load templates * Will not control EAs Monitoring only. ________________ DEVELOPER ACCEPTANCE CRITERIA The project is complete when: 1. All modules run reliably in live trading 2. All alerts trigger per spec 3. Logs persist correctly and are readable 4. No noticeable platform performance issues 5. Tested on XAUUSD M1 but works account-wide 6. Indicator continues working after MT4 restart