The Data Pipeline Behind Reliable MT5 AI Models

The Data Pipeline Behind Reliable MT5 AI Models

25 August 2026, 01:40
Michael Prescott Burney
0
34
The Data Pipeline Behind Reliable MT5 AI Models

Most model failures begin before training. A reliable MetaTrader 5 AI system needs a data contract that defines where prices come from, how bars are formed, when a feature becomes available, which timestamp is authoritative, and how the same feature logic is reproduced in research and live execution.

A model cannot compensate for bad, stale, misaligned, revised, or leaked data. If a training dataset uses information that was not available at the decision time, historical results can look impressive while live behavior fails. If live features are generated differently from training features, even a valid model can produce meaningless outputs.

This article is an educational software-architecture guide for MQL5 developers and systematic traders. It is not financial or investment advice. Data quality, broker feeds, historical records, and execution conditions vary by broker, symbol, account type, session, and market conditions. Test every pipeline in controlled environments before any live use.

The Core Principle

The design rule is:

No model should receive unchecked values. When market data, feature data, or time alignment is uncertain, stop producing new trade proposals.

Data quality is a risk-control problem, not only a data-science problem. A broken feed, changed symbol specification, stale quote, duplicate bar, or misaligned higher-timeframe feature can create false model confidence. The safe response is not to guess. It is to reject the input, record the fault, and wait for reliable state.

What a Data Pipeline Does

A trading data pipeline transforms raw market observations into validated, point-in-time-correct features that can be used consistently in training, evaluation, and live inference.

A practical flow is:

RAW OBSERVATIONS → INGESTION VALIDATION → NORMALIZED MARKET DATA → BAR CONSTRUCTION → FEATURE GENERATION → FEATURE VALIDATION → MODEL INPUT → AUDIT AND MONITORING

Each stage should have an explicit contract. A downstream stage should not silently repair unknown data quality problems introduced upstream.

Pipeline Stage Primary Responsibility Failure-Safe Behavior
Raw observations Capture broker quotes, ticks, bars, symbol metadata, and account-independent market facts. Preserve source data and mark missing or uncertain fields; do not fabricate values.
Ingestion validation Check timestamps, sequence, duplicates, gaps, staleness, and source identity. Quarantine or reject invalid observations and emit data-quality alerts.
Normalization Standardize symbol mapping, time representation, units, schema, and metadata. Reject unknown symbols, unsupported precision, or incompatible specifications.
Bar construction Build or retrieve time-aligned bars with explicit completion rules. Do not treat a forming bar as closed unless the strategy explicitly supports it.
Feature generation Calculate point-in-time features from data available at the decision timestamp. Reject vectors with insufficient history, missing inputs, or leakage risk.
Feature validation Check schema, range, finiteness, freshness, and compatibility with the model release. Return no-trade or no-proposal state when validation fails.
Monitoring and audit Track data drift, feed health, versions, lineage, and model-input quality. Escalate to reduced or blocked state when quality deteriorates.

Start With a Data Contract

A data contract is a written specification of what each dataset or message contains, where it came from, how it is timestamped, which fields are required, and what quality rules apply. It prevents training, research, and live execution from silently using different definitions of the same input.

For each market-data source, define:

  • Source system or broker identity.
  • Broker legal entity or server identifier where relevant.
  • Raw symbol name and normalized instrument identifier.
  • Asset class and contract specification version.
  • Quote fields: bid, ask, last, volume, tick volume, spread, and any depth fields used.
  • UTC timestamp, broker-server timestamp, and ingestion timestamp.
  • Time-zone policy and daylight-saving handling.
  • Bar timeframe, bar-open time, bar-close time, and completion status.
  • Missing-data, duplicate-data, and revision policy.
  • Data schema version and ingestion pipeline version.
  • Quality status, validation results, and reason codes.

A data contract should be versioned. If a broker changes a symbol suffix, contract size, quote precision, session, or feed behavior, the change should be visible rather than silently merged into historical assumptions.

Broker Feeds Are Not Identical

Two brokers can offer symbols with similar names while providing different quotes, sessions, spreads, contract specifications, trading breaks, historical depth, and rollover behavior. Even the same broker can change conditions across account types or server environments.

Common differences include:

  • Symbol suffixes or prefixes, such as broker-specific names for the same underlying market.
  • Different digits, point sizes, tick sizes, and tick values.
  • Different contract sizes and margin calculations.
  • Different daily trading breaks, rollover times, and session schedules.
  • Different spread behavior by account type or liquidity condition.
  • Different historical data depth and bar construction behavior.
  • Different treatment of holidays, weekend gaps, and market closures.
  • Different volume fields, including tick volume versus real volume availability.

Do not assume data trained on one broker is automatically interchangeable with a live system on another. At a minimum, record broker and symbol metadata, evaluate feature distribution differences, and test the live pipeline before relying on the model.

Normalize Symbol Identity

Use both a normalized instrument identifier and the exact broker symbol name. The normalized identifier helps research systems group comparable instruments. The broker symbol remains necessary for execution and accurate contract specification lookup.

For example:

{ "normalized_instrument": "EURUSD", "broker_symbol": "EURUSD.a", "broker_server": "BrokerServerName", "asset_class": "FX", "symbol_mapping_version": "symbol_map_v4", "contract_specification_version": "spec_EURUSD_a_2026_08" }

Never map symbols only by stripping suffixes and assuming all contract details match. The mapping must preserve broker-specific metadata that affects spread, tick value, volume, stops, and margin.

Store Raw Observations Separately

Store raw observations separately from derived bars, features, labels, and model inputs. This provides lineage: when a dataset is rebuilt, the same transformation version can produce the same features from the same raw source data.

A useful storage model separates:

  • Raw layer: original ticks, quotes, broker bars, metadata, source timestamps, and ingestion records.
  • Normalized layer: standardized field names, UTC timestamps, symbol mapping, and validated data types.
  • Derived bar layer: explicitly constructed or validated OHLCV bars with completion status.
  • Feature layer: versioned features and transformations generated from point-in-time data.
  • Label layer: future outcome labels used only for training and evaluation, kept separate from live features.
  • Model-input layer: ordered, normalized tensors or feature vectors tied to a model version.
  • Audit layer: hashes, versions, validation status, and lineage references.

Do not overwrite raw observations with corrected features. Preserve raw inputs and record how each derived output was produced.

Raw Data Example

{
  "observation_id": "tick_2026-08-24_000001",
  "source": {
    "broker_server": "BrokerServerName",
    "broker_symbol": "EURUSD.a",
    "ingestion_version": "feed_ingest_v2"
  },
  "time": {
    "event_time_utc": "2026-08-24T23:00:01.125Z",
    "broker_time": "2026-08-24T23:00:01",
    "ingested_at_utc": "2026-08-24T23:00:01.180Z"
  },
  "quote": {
    "bid": 1.08000,
    "ask": 1.08012,
    "last": null,
    "spread_points": 12,
    "tick_volume": 1
  },
  "metadata": {
    "digits": 5,
    "point": 0.00001,
    "tick_size": 0.00001,
    "contract_specification_version": "spec_EURUSD_a_2026_08"
  },
  "quality": {
    "status": "VALID",
    "checks": ["timestamp_valid", "bid_lte_ask", "symbol_known"]
  }
} 

The exact storage format can differ, but the key elements are source identity, time lineage, quote values, metadata, and quality status.

Use Explicit Timestamps

Time is one of the most important fields in a trading data pipeline. A feature can only be used if you know when its inputs were available. Store multiple timestamps when necessary rather than relying on one ambiguous time field.

Useful Time Fields

  • Event time: when the market observation or source event occurred.
  • Broker-server time: time reported by the broker or terminal.
  • Ingestion time: when your pipeline received the observation.
  • Processing time: when a bar or feature was calculated.
  • Feature availability time: earliest time the completed feature could be used.
  • Decision time: the timestamp at which the model or strategy is allowed to consume the feature vector.
  • Publication time: for external releases such as economic data or statements.
  • Revision time: when an external value was later corrected or revised.

Use UTC for cross-system records. Record broker-server time separately when it is important for chart alignment, session logic, or platform reconciliation. Do not rely only on local computer time, especially across daylight-saving changes.

Authoritative Time Must Be Defined

For each use case, specify which timestamp is authoritative. For example:

  • For a tick-based feature, event time may be authoritative.
  • For an MT5 bar-close strategy, bar completion time may be authoritative.
  • For a scheduled economic release, publication time and actual availability time may both matter.
  • For a risk agent, broker-reported account state time may be authoritative.
  • For model input freshness, feature availability time may be authoritative.

If the system cannot determine authoritative time, it should not create a trade proposal. Uncertain time means uncertain information availability.

Point-in-Time Correctness

Point-in-time correctness means that every feature used for a decision could have been known at the exact decision time. It is the primary defense against look-ahead bias and data leakage.

In simple terms: a live system cannot use information from the future. A historical test must obey the same rule.

Examples of leakage include:

  • Using the final daily high before the daily bar has closed.
  • Using the final close of a higher-timeframe bar in a lower-timeframe decision made before that close.
  • Using a revised economic value as if it was available at the original release time.
  • Normalizing a historical feature using statistics calculated from the full future dataset.
  • Labeling data in a way that leaks future price movement into current features.
  • Including a current forming bar in a close-based model without training the model for intrabar behavior.

A model trained with leaked features can appear highly accurate in backtests and fail immediately when deployed. No amount of model complexity fixes an invalid timeline.

Higher-Timeframe Leakage

Higher-timeframe indicators are a common source of accidental leakage. Suppose an M15 strategy uses a daily moving average, daily high, or daily close. At 10:30, the current daily bar has not closed. The final daily close is not yet known.

A point-in-time-correct M15 decision can use:

  • Completed prior daily bars.
  • The current daily bar’s values only as they existed at 10:30, if the strategy explicitly supports intraday updating.
  • Features derived from lower-timeframe data available at the M15 decision time.

It cannot use the daily close that occurs hours later. Define this rule in both training and live feature generation.

External Data Revisions

Economic releases, earnings data, macro series, and other external sources can be revised. A revised value may be useful for later research, but it was not available to a strategy at the original release time.

Store separate fields for:

  • Original publication value.
  • Original publication timestamp.
  • Revision value.
  • Revision timestamp.
  • Source document version or content hash.
  • Availability time in your pipeline.

Training data should use the original known value for a historical decision unless the strategy is specifically modeling revisions at the time they became available. Do not replace historical original values silently with revised data.

Bar Construction and Completion

Bars are derived objects. Different feeds, platforms, and sessions can create different bars around gaps, illiquid periods, rollover, and market boundaries. Document whether your pipeline uses broker-provided bars or builds bars from raw ticks.

For each bar, record:

  • Symbol and timeframe.
  • Bar open time and intended close time.
  • Open, high, low, close, volume, and spread fields used.
  • Bar completion status.
  • Source-data coverage and gap status.
  • Construction method and version.
  • Revision or correction status.

For close-based strategies, consume completed bars only. If your system deliberately uses a forming bar, treat it as a separate feature policy and validate it separately. Do not accidentally mix the two.

Detect Gaps, Duplicates, and Stale Ticks

Data validation must detect abnormal feed behavior before features are created. A missing bar or stale quote can create an indicator value that looks valid but is based on incomplete information.

Gaps

A gap can mean a legitimate market closure, a holiday, a thin-liquidity interval, a connection interruption, or missing data. Your policy should distinguish expected gaps from unexpected ones.

Check:

  • Expected timestamp spacing for the symbol and timeframe.
  • Known market session breaks and holidays.
  • Number of missing bars or missing ticks.
  • Whether the gap exceeds a strategy-defined tolerance.
  • Whether features requiring continuous history remain valid after the gap.

Duplicates

Duplicate ticks, duplicate bars, repeated messages, or repeated file ingestion can distort volume, returns, and rolling indicators. Use unique observation IDs, source sequence data where available, and deduplication rules.

Stale Ticks

A stale tick is a quote that has not updated within the maximum allowed age for the symbol and trading session. A stale price should not be used for a new order decision.

Record:

  • Time since last valid bid and ask update.
  • Time since last tradeable quote.
  • Time since last completed bar update.
  • Current terminal and broker connection state.

If quote freshness is uncertain, block new trade proposals. Do not use the last known price as a substitute for current market state.

Detect Symbol Specification Changes

Symbol specifications can affect every risk and feature calculation. A change in digits, point size, tick value, contract size, margin rate, trading session, minimum volume, or stops level can make old assumptions invalid.

Monitor and version:

  • Digits and point size.
  • Tick size and tick value.
  • Contract size.
  • Minimum, maximum, and step volume.
  • Margin calculation and leverage rules.
  • Swap or financing settings where relevant.
  • Stops level and freeze level.
  • Trading mode and trading sessions.
  • Broker symbol name and mapping.

If a critical specification changes, mark the data pipeline and live trading process as needing revalidation. A model feature may remain valid while the position-sizing or execution policy becomes unsafe.

Feature Engineering Must Be Reproducible

A feature is not just a column name. It is a versioned transformation with a data source, formula, bar policy, lookback, normalization method, missing-value policy, and availability rule.

For every feature, document:

  • Feature name and feature-schema version.
  • Source fields and source timeframes.
  • Formula and any indicator parameters.
  • Lookback length and warmup requirement.
  • Bar alignment and ordering.
  • Completion policy: completed bars only or explicit intrabar behavior.
  • Missing-value and gap policy.
  • Outlier clipping or winsorization rule.
  • Normalization or scaling method.
  • Feature availability timestamp.
  • Expected range and validation rules.

If a dataset is rebuilt, the same raw input and same transformation version should produce the same feature vector. If not, you do not have a reproducible model input pipeline.

Shared Feature Definitions

Generate training and live features from shared definitions whenever possible. This reduces the chance that Python research code and MQL5 live code diverge over time.

Possible approaches include:

  • A machine-readable feature manifest consumed by both environments.
  • Generated MQL5 and Python code from one controlled feature specification.
  • Reference validation vectors that both environments must reproduce.
  • Shared test cases with timestamped raw bars and expected output features.
  • Versioned transformation artifacts with checksums and release notes.

Even when exact shared code is not practical, shared definitions and parity tests are essential. A Python feature named  normalized_atr  is not guaranteed to match an MQL5 feature with the same name unless formula, timing, scaling, and inputs are verified.

Feature Manifest Example

{ "feature_schema_id": "mt5_features_v3", "symbol_scope": "EURUSD", "decision_timeframe": "M15", "bar_policy": "completed_bars_only_oldest_to_newest", "features": [ { "index": 0, "name": "return_1", "source": "M15.close", "formula": "close[t] / close[t-1] - 1", "lookback": 2, "available_at": "close_of_bar_t", "missing_policy": "reject", "normalization": "zscore:return_1_mean:return_1_std" }, { "index": 1, "name": "atr_14_normalized", "source": "M15.ohlc", "formula": "ATR(14) / close[t]", "lookback": 15, "available_at": "close_of_bar_t", "missing_policy": "reject", "normalization": "zscore:atr_mean:atr_std" }, { "index": 2, "name": "spread_points", "source": "latest_valid_quote", "formula": "(ask - bid) / point", "lookback": 1, "available_at": "quote_timestamp", "missing_policy": "reject", "normalization": "zscore:spread_mean:spread_std" } ] }

The manifest should be versioned, tested, and linked to the model release. If one feature changes, the feature schema changes.

Normalization Parameters Must Be Versioned

Normalization is part of the model input contract. If a model was trained using a specific mean, standard deviation, min-max range, median, interquartile range, or clipping threshold, the live feature pipeline must use the same versioned parameters.

Do not silently recompute training normalization from a changing live sample unless the model was explicitly trained and validated with that rolling transformation.

Store:

  • Normalization method.
  • Training or reference parameters for every feature.
  • Parameter-generation dataset and date range.
  • Feature-schema version.
  • Artifact version and checksum.
  • Expected input range after normalization.

A model trained on standardized returns can behave unpredictably if the live system supplies raw returns, raw prices, or values scaled with a different distribution.

Labels Must Be Separate From Features

Training labels often use future information by design: future return, future drawdown, whether a stop or target was reached, or future realized volatility. That is acceptable for labels, but labels must remain separate from the live feature pipeline.

Common mistakes include:

  • Accidentally merging a future-return label into the feature table.
  • Using an outcome-dependent filter during historical feature selection.
  • Computing normalization statistics using both training and future test periods.
  • Creating features that use a future bar close without realizing it.
  • Using revised macro data in the historical feature set without version control.

Keep a clear boundary: features represent information available at decision time; labels represent information available after the decision time.

Data Quality Checks Before Model Input

No model should receive unchecked values. Create a feature-validation gate that returns either a valid model input or a no-proposal result with reason codes.

Check:

  • Required history length is available.
  • All bars and ticks used are within the expected time sequence.
  • No duplicate observations distort the lookback window.
  • Current quote and spread are fresh.
  • Required symbol metadata matches the active configuration.
  • All features are finite: no NaN, infinity, or undefined values.
  • Feature values are within hard plausibility bounds.
  • Normalized values are within expected monitoring bounds.
  • Feature schema and normalization version match the loaded model.
  • Decision timestamp and feature availability timestamp align.
  • Data source and broker context are allowed for the model release.

If validation fails, do not replace missing values with arbitrary defaults. Return no trade proposal, log the failure, and let the next valid snapshot start a new decision cycle.

Feature Validation Pseudocode

function BuildValidatedFeatureVector(snapshot, feature_manifest, normalization):
    if !SnapshotIsFresh(snapshot):
        return Reject("STALE_MARKET_SNAPSHOT")

    if !SymbolMetadataMatches(snapshot, feature_manifest):
        return Reject("SYMBOL_SPECIFICATION_MISMATCH")

    if !HasRequiredCompletedBars(snapshot, feature_manifest.lookback):
        return Reject("INSUFFICIENT_HISTORY")

    if HasUnexpectedGapsOrDuplicates(snapshot):
        return Reject("BAR_OR_TICK_QUALITY_FAILURE")

    features = CalculateFeaturesPointInTime(snapshot, feature_manifest)

    if !AllValuesFinite(features):
        return Reject("NON_FINITE_FEATURE")

    if !FeaturesWithinHardBounds(features, feature_manifest):
        return Reject("FEATURE_OUT_OF_RANGE")

    normalized = ApplyVersionedNormalization(features, normalization)

    if !NormalizedValuesValid(normalized):
        return Reject("INVALID_NORMALIZED_FEATURES")

    return Accept(normalized) 

The feature builder should not create an order. It should only return validated data or an explicit reason to stop.

Monitor Data Drift Separately From Model Drift

Data drift and model drift are related but different. Data drift means the input distribution, feed behavior, or data quality characteristics have changed. Model drift means the relationship between inputs and the target or model performance has changed.

A sudden change in spread, missing-volume frequency, quote timing, symbol specification, or feature range may indicate a feed or pipeline problem rather than a new market regime. If you treat every data change as market information, the model may adapt to a broken input instead of alerting you.

Type What Changed Example Initial Response
Data drift Input distribution, source behavior, schema, or data quality. Spread percentile jumps, tick volume becomes missing, or feature range changes after broker migration. Validate feed and pipeline; reduce or stop proposals until data quality is understood.
Model drift Relationship between features and expected outcome changes. Feature values remain normal, but out-of-sample model performance deteriorates across a meaningful sample. Review model validity, regime fit, retraining policy, and risk caps.
Execution drift Difference between assumed and realized fill quality changes. Slippage and rejection rate increase while market features remain similar. Review broker conditions, execution policy, session restrictions, and strategy net edge.

Data Drift Metrics

Monitor input quality and distribution over time. The right metrics depend on your data and strategy, but useful checks include:

  • Missing-value frequency by field and symbol.
  • Duplicate-tick or duplicate-bar frequency.
  • Stale-tick frequency and quote-age distribution.
  • Expected versus actual bar count by session.
  • Spread median, percentile, and outlier frequency.
  • Tick volume or real volume missingness and distribution.
  • Feature mean, standard deviation, percentile, and out-of-range frequency.
  • Normalized feature range and clipping frequency.
  • Symbol specification change events.
  • Time-zone, session, or server-time shifts.
  • Ingestion latency and processing-latency distribution.

Data drift does not always mean the market is broken. It means the system should determine whether the input still matches the model and policy assumptions before creating new proposals.

Use Data-Quality States

A compact data-quality state machine helps convert observations into enforceable behavior.

Data Quality State Typical Condition Action
HEALTHY Data is fresh, complete, schema-compatible, and within expected ranges. Permit feature generation and normal proposal flow.
DEGRADED Soft drift, elevated spread, minor gaps, or unusual but still valid values. Apply conservative policy, enhanced logging, or reduce allowed activity if tested.
BLOCKED Stale data, required-field failure, hard range violation, unknown symbol specification, or critical gap. Stop new feature vectors and new trade proposals.
UNCERTAIN Source identity, time alignment, revision status, or pipeline state cannot be verified. Stop new proposals until state is reconciled.

The fastest safe response to broken data is to stop producing new trade proposals. Existing positions should remain governed by independent deterministic management and risk controls.

Version Transformations and Artifacts

Every transformation that can affect a model input should be versioned. This includes feature formulas, bar-construction policy, normalization parameters, missing-value handling, clipping thresholds, symbol mapping, and data-source configuration.

Version at least:

  • Ingestion pipeline and parser.
  • Raw-data schema.
  • Symbol mapping and contract-specification snapshot.
  • Bar construction policy and timeframe mapping.
  • Feature manifest and formula definitions.
  • Normalization and scaling parameters.
  • Missing-data and outlier policy.
  • Label-generation policy for training datasets.
  • Data-quality thresholds and drift-monitoring configuration.
  • Model input schema and model release.
  • MQL5 EA build and Python or research environment build.

A feature named the same thing under a different transformation is a different feature. Treat it as a new version.

Reproducibility and Data Lineage

A reliable system should be able to answer: which raw data, transformations, normalization artifact, model version, and symbol configuration produced this decision?

For every model input or proposal, store references to:

  • Raw observation range or source IDs.
  • Bar-construction version.
  • Feature-schema version and feature-vector hash.
  • Normalization artifact version and hash.
  • Data-quality status and validation reason codes.
  • Symbol metadata and contract-specification version.
  • Model version and input-contract version.
  • Decision timestamp and feature availability timestamp.

Without lineage, it is difficult to determine whether a poor result came from the model, the data feed, a feature bug, a broker change, or an execution issue.

Training, Validation, and Live Data Splits

Data pipeline discipline applies to model evaluation as well as live operation. Training, validation, and test periods should preserve time order. Do not randomly shuffle time-series data in a way that lets future conditions influence past evaluation.

Use a process that respects chronology:

  • Train on an earlier period.
  • Validate on a later separate period.
  • Evaluate on a further out-of-sample period.
  • Use walk-forward or rolling evaluation where appropriate.
  • Keep preprocessing and normalization fit only on the training portion unless a rolling method is explicitly designed.
  • Apply the same point-in-time feature rules at every stage.

The purpose is not to produce the highest historical score. It is to estimate whether the full data and model process remains stable when faced with information it did not see during development.

Data Pipeline Testing

Test the data pipeline like production code. A model can be mathematically correct while receiving the wrong input because of a parsing, time-zone, bar-order, or normalization mistake.

Test Area What to Verify
Ingestion Source identity, timestamp parsing, bid/ask validity, duplicate handling, gap detection, and reconnect behavior.
Symbol normalization Broker symbol mapping, suffixes, metadata, digits, contract specifications, and session configuration.
Bar construction Open and close timing, completed-bar logic, gaps, ordering, timezone alignment, and holiday behavior.
Feature generation Formula correctness, lookback, missing-value policy, point-in-time availability, and higher-timeframe alignment.
Normalization Correct artifact version, parameter values, clipping rules, and parity between research and MQL5 implementations.
Feature validation Finite values, expected range, schema compatibility, stale data, and hard failure behavior.
Drift monitoring Alerts for spread changes, missing volume, feature shifts, symbol-spec changes, and quote-age anomalies.

Build fixed timestamped validation cases with raw input records and expected bars, features, normalized values, and quality status. Run them after every code or configuration change.

Python and MQL5 Feature Parity

If models are trained in Python and evaluated in MQL5, use the same feature definitions and fixed validation vectors in both environments. This is essential whether inference happens through an external bridge or directly through ONNX in the terminal.

For each validation case, compare:

  • Raw bar and quote inputs.
  • Bar ordering and completed-bar selection.
  • Feature values before normalization.
  • Normalization parameters and normalized values.
  • Tensor shape and feature order.
  • Final model input hash.
  • Model output and final policy decision, if applicable.

Small numeric differences may be acceptable depending on the transformation and model, but directional, threshold, class-label, or action changes require investigation. Do not assume matching feature names prove matching feature behavior.

Data-Pipeline Monitoring Dashboard

A data dashboard should show operational quality, not only model predictions or account performance. Useful panels include:

  • Last valid quote time by symbol.
  • Current quote age and stale-data alerts.
  • Missing bar and duplicate observation count.
  • Current spread versus baseline percentiles.
  • Feature availability and validation pass rate.
  • Feature out-of-range and clipping frequency.
  • Current feature-schema and normalization artifact versions.
  • Symbol specification changes and broker-session status.
  • Data drift score and model drift score as separate indicators.
  • Number of proposals blocked because of data quality.

If a dashboard reports healthy model confidence while quote age is stale or feature validation is failing, data quality must take precedence. The system should not trade because the model looks confident on invalid input.

MQL5 Component Layout

Keep data validation and feature generation separate from strategy, risk, and execution logic. A modular structure makes the pipeline easier to test and audit.

/MT5DataPipeline /Core RawObservation.mqh MarketDataSnapshot.mqh SymbolMetadata.mqh BarValidator.mqh FeatureManifest.mqh FeatureBuilder.mqh Normalization.mqh FeatureValidator.mqh DataQualityState.mqh DriftMonitor.mqh DataLineage.mqh AuditLogger.mqh /Infrastructure TimeUtils.mqh SymbolUtils.mqh Serialization.mqh ChecksumUtils.mqh /Config SymbolMap.mqh DataQualityConfig.mqh FeatureReleaseConfig.mqh DataPipelineEA.mq5

The system that consumes features should receive a validated, versioned feature vector or an explicit no-proposal reason. It should not have to guess whether a data field is current or complete.

Conceptual MQL5 Data Flow

OnTimer():
    snapshot = MarketDataCollector.BuildSnapshot()

    quality = DataQualityValidator.Evaluate(snapshot)
    if quality.state == BLOCKED || quality.state == UNCERTAIN:
        Audit.LogNoProposal(snapshot, quality.reason_code)
        return

    features = FeatureBuilder.Create(snapshot, FeatureManifest.Current())
    validation = FeatureValidator.Evaluate(features, Normalization.Current())

    if !validation.ok:
        Audit.LogNoProposal(snapshot, validation.reason_code)
        return

    lineage = DataLineage.Build(snapshot, features, validation)
    ProposalEngine.Evaluate(validation.normalized_vector, lineage) 

The proposal engine is reached only after data and features are validated. If data is broken, no new proposal is created.

Common Data Pipeline Mistakes

Training on Data With Future Leakage

Using a completed higher-timeframe bar, future normalization statistic, revised release value, or future close before it was available creates unrealistic backtests.

Mixing Raw and Derived Data

Overwriting raw observations with corrected or transformed values breaks lineage. Store raw data separately and version every transformation.

Ignoring Broker Differences

Symbols, sessions, spread behavior, and contract specifications differ. Record broker context and validate the live pipeline before applying a model trained elsewhere.

Using Current Forming Bars by Accident

A close-based feature pipeline should use completed bars only. Including a changing current bar makes live inputs unstable and may not match training.

Recomputing Normalization From Live Data

Live recalculation can silently change model input scale. Use versioned training parameters unless a rolling transformation was explicitly part of model design.

Not Detecting Stale Quotes

A last-known price is not a current tradable price. Block new proposals when quote freshness or connection state is uncertain.

Confusing Data Drift With Model Drift

A changed spread or missing-volume rate may be a feed problem, not a market regime. Investigate input quality before modifying the model.

Allowing Unchecked Features Into the Model

NaN, infinity, out-of-range values, schema mismatches, and missing history should result in no proposal, not a default prediction.

Implementation Checklist

Use this checklist when building a reliable MT5 AI data pipeline:

  • Define a versioned data contract for every raw market-data source and derived dataset.
  • Record source identity, broker symbol, normalized instrument, UTC time, broker time, ingestion time, and metadata.
  • Store raw observations separately from normalized bars, features, labels, and model inputs.
  • Use explicit authoritative timestamps and feature availability times.
  • Enforce point-in-time correctness in training, evaluation, and live inference.
  • Prevent higher-timeframe, revised-data, future-normalization, and forming-bar leakage.
  • Detect gaps, duplicates, stale ticks, missing history, quote-age failures, and symbol specification changes.
  • Version bar construction, feature formulas, ordering, transformations, normalization, missing-value policy, and symbol mapping.
  • Generate training and live features from shared definitions whenever possible.
  • Use fixed validation vectors to compare Python, MQL5, and ONNX feature pipelines.
  • Validate every feature vector for freshness, completeness, finiteness, range, schema, and model compatibility before inference.
  • Monitor data drift separately from model drift and execution drift.
  • Use explicit healthy, degraded, blocked, and uncertain data-quality states.
  • Stop producing new trade proposals when data quality is broken or uncertain.
  • Log lineage, versions, validation outcomes, drift metrics, and all no-proposal reasons.

Final Thoughts

Reliable MT5 AI models begin with reliable data contracts, not model selection. You need to know where every price came from, when each feature became available, how bars were formed, how symbols and sessions differ, and whether the live pipeline still matches the assumptions used in training.

Store raw data separately, enforce point-in-time feature logic, version every transformation, validate every input, and monitor feed quality independently from model performance. When data is stale, incomplete, misaligned, or incompatible, the correct action is simple: stop producing new trade proposals until the pipeline is reliable again.

Risk disclaimer: Automated trading, artificial intelligence, machine learning, data pipelines, Expert Advisors, foreign exchange, CFDs, commodities, indices, stocks, cryptocurrencies, and other leveraged products involve substantial risk and may not be suitable for all investors. This article is for educational and software-architecture purposes only and does not constitute financial, investment, legal, tax, cybersecurity, or regulatory advice. Market data can be delayed, incomplete, revised, inconsistent, or broker-specific. Past performance, backtests, forward tests, and demo results do not guarantee future results. Test all data pipelines and trading systems carefully, verify broker-specific behavior, and use robust independent risk controls before considering live deployment.