Repository navigation
Architecture
FXNews is a single-file MetaTrader 5 custom indicator. The implementation lives in FXNews.mq5 and runs in the chart window without indicator plots. It does not contain an application server, database, package manager, container, or separate service process. The tools/ folder holds the macOS build script, the dead-code census and the headless test harness; none of it ships with the indicator.
OnInit() resets every piece of run state (globals survive a re-initialisation that keeps the program instance), validates the inputs, warns about labels left by another instance, parses and resolves the symbol and timeframe lists, builds symbol/timeframe profiles, initializes calendar and history buffers, selects broker symbols, and starts the timer. In SELFTEST mode it skips symbols and buffers. Initialization fails cleanly when required inputs or profiles are invalid.
OnTimer() is the operational entrypoint. In Live mode it calls ScanAll(). In Validation or Autotune mode it runs the historical workflow once and then stays parked with the report. OnCalculate() intentionally returns rates_total; market scanning does not run on chart-calculation events. OnChartEvent() only notes a chart resize so the next scan re-fits the rows.
OnDeinit() stops the timer, removes the chart objects created by this indicator instance and redraws the chart.
MT5 timer
-> per profile: quote (against the trade-server clock), snapshots, spread ring,
per-window speed baselines, tick quality (once per quote), rates, context
(once per symbol, shared by its timeframes), range box (anchored while an
event is live), outside timers
-> basket currency strength with per-symbol contributions
-> per profile: shared components (execution, calendar, session, basket
agreement, tick deviations) once, then breakout, impulse, flow, regime
and the composer for each direction
-> signal lifecycle: candidate, confirmation, active, expiry, reversal, cooldown
-> correlation groups (bound at activation) and leader election
-> alert dispatch (per-profile spacing, sliding minute window, per-scan cap, retries)
-> status, diagnostics, and signal rows on the chart within the 63-character label budget
The work is bounded by the configured symbol/timeframe profile count and fixed in-memory history capacities. Scanning remains on the timer path so chart recalculation does not multiply the workload.
| Component | Main responsibilities | Important functions |
|---|---|---|
| Startup and profiles | Validate settings, parse and resolve symbols/timeframes, allocate state, reset run state |
OnInit, ResetRuntimeState, ValidateInputs, ParseSymbols, ResolveRequestedSymbol, ParseTimeframes, EnsureSymbolReady
|
| Market data | Read quotes and rates, calculate ATR/ranges, maintain snapshots, spread and speed baselines, assess tick quality |
UpdateMarketData, UpdateRatesData, BuildRangeBox, UpdateSnapshotRateStats, UpdateSpreadStatistics, UpdateTickQuality
|
| Basket | Currency strength with leave-one-out contributions and basket agreement |
CalculateCurrencyStrength, CalculateBasketAgreement
|
| Scoring | Evaluate the components with explicit availability, then blend and cap them |
EvaluateSharedComponents, BuildCompositeSignalScore, the Evaluate* functions, ComposeSignalScore
|
| Shared pure scoring | The composer, breakout structure, impulse blend, regime blend and execution blend used by both the live scanner and the historical modes |
ComposeSignalScore, ComputeBreakoutStructure, BlendImpulseScore, ComposeRegimeScore, BlendExecutionScore
|
| Signal lifecycle | Candidates, confirmation, active signals, expiry, reversals, cooldowns |
UpdateSignalState, StartCandidate, ActivateSignal, EndActiveSignal, EventAgeLimitSeconds
|
| Correlation groups | Bind a group at activation and elect a leader per scan |
UpdateAlertGroups, DominantCurrencyFlow
|
| Alerts | Dispatch opt-in sound and push notifications with spacing, limits and bounded retries |
DispatchPendingAlerts, SendOptionalAlert, AlertRateLimitAllows
|
| Dashboard | Render status, diagnostics, detailed rows and the recent-signal list inside the label budget |
UpdateDashboard, FormatDashboardSignalText, FormatSignalHistoryText, WrapLabelText, SetDashboardRow
|
| Recent-signal list | Record the best events and evict with a minimum dwell |
PushSignalHistory, UpdateSignalHistory, RefreshVisibleSignalHistory
|
| Historical modes | Aggregate M1 history by time, extract boundary features once for every candidate, score through the shared composer, evaluate spread-paying outcomes, report |
RunHistoricalBacktestSet, ProcessHistoricalProfile, BuildHistoricalBoundaryFeatures, ScoreHistoricalBoundary, EvaluateHistoricalOutcome, the report builders |
| Calendar context | Cache relevant events from MT5's built-in economic calendar |
RefreshCalendarCache, EvaluateCalendarContext
|
| Self-test | 117 assertions over the pure helpers, the composer, the historical engine and the recent-signal list |
RunSelfTest and the SelfTest* groups |
Each symbol/timeframe combination is a SymbolProfile. Profiles hold current market data with availability flags, per-scan caches (spread statistics, per-window speed baselines, tick quality stamped by quote time, the breakout buffer), component scores for both directions, signal state, cooldowns, the bound correlation group, and dashboard metadata. Snapshot, spread, session-baseline, calendar, and recent-signal data remain in memory for the current indicator session. Rates and ticks are copied into module-level buffers.
Output is limited to chart label objects, optional sound alerts, optional MT5 push notifications, and Journal lines for diagnostics or historical reports. Each attachment uses a distinct object namespace, and InstanceId can provide a stable one. Autotune changes no runtime setting; it reports an advisory recommendation.
The historical modes replay closed M1 history through the same composer as the live scanner. They cannot measure the currency basket, the calendar or any tick-level quantity, so those components are unavailable and their caps apply; the speed windows are minute-scale proxies with their own threshold. Differences between historical and Live output are expected and must be evaluated with manual forward observation. See Validation and Autotune.
- MetaTrader 5 and MetaEditor.
- Broker-provided symbols, quotes, tick history, and M1, M5, M15, and scan-timeframe history.
- MT5's built-in economic calendar when calendar context is enabled.
- Terminal notification configuration when push alerts are enabled.
The code does not use WebRequest, DLL imports, external feeds, file persistence, or trading APIs.