Most EAs reduce the market to a single decision: buy, sell, or wait. A time-series foundation model can supply a different input to that decision: a distribution of possible future closing prices. This guide documents how we integrated Mistral AI's Timestral into MetaTrader 5 using its native ONNX runtime, without turning the forecast itself into an order.

What Timestral actually predicts

Mistral released Timestral on 15 October 2026. The family has four parameter counts: 5M, 28M, 123M and 209M. The upstream model supports up to 32,768 historical steps, multiple series and covariates, and returns 21 forecast quantiles per future step. Our current MT5 integration uses only one target series: completed closing prices. It exposes P10, P50 and P90 for a chosen forecast horizon.

For example, with 128 completed H1 bars and an eight-bar horizon, the forecast is for the closing price of the eighth future H1 bar. If an illustrative forecast is P10 = 2,380, P50 = 2,400 and P90 = 2,425, the model's central 80% predictive interval is 2,380–2,425. These are invented numbers, not a market forecast. An actual interval can be miscalibrated. P10 and P90 are not predictions of the low and high reached along the way, and do not tell you which of a stop loss or take profit is hit first.

Why run ONNX inside MetaTrader?

The native path uses the terminal's ONNX session rather than calling an HTTP service. The same inference mechanism can therefore be used in a chart or in Strategy Tester. Once the model file is installed, the path does not need a Python process, a DLL supplied by us, an API key or a network request. The original local Python bridge is a separate option; HTTP requests are not available in Strategy Tester, so that path requires timestamp-aligned, precomputed forecasts for historical testing.

Choose the smallest model that satisfies your measured needs. A larger model can require more memory and CPU time, and vendor forecasting benchmarks do not establish which size is best for a trading strategy. Download size is not runtime RAM usage.

Install a model and check the graph

  1. Choose one community ONNX export matching the six-input contract below. Start with 5M. Read the model license before downloading or redistributing weights.
  2. In MT5 select File → Open Data Folder. Place the downloaded graph in MQL5/Files/Timestral-5M.onnx. The filename in the EA must match. The 5M export's downloadable file is named timestral-5m.onnx; it can be renamed locally.
  3. Compile the following small non-trading EA in MetaEditor. Its only purpose is to check model loading and the number of inputs and outputs. It is an illustrative diagnostic, not a separately compiled or backtested example.
#property tester_file "Timestral-5M.onnx"
long handle = INVALID_HANDLE;

int OnInit()
{
   handle = OnnxCreate("Timestral-5M.onnx", 0);
   if(handle == INVALID_HANDLE)
   {
      Print("ONNX load failed: ", GetLastError());
      return INIT_FAILED;
   }
   if(OnnxGetInputCount(handle) != 6 ||
      OnnxGetOutputCount(handle) != 2)
   {
      OnnxRelease(handle);
      handle = INVALID_HANDLE;
      return INIT_FAILED;
   }
   Print("Timestral graph loaded; check tensor names next.");
   return INIT_SUCCEEDED;
}

void OnTick() {} // No orders and no forecasts yet.

void OnDeinit(const int reason)
{
   if(handle != INVALID_HANDLE) OnnxRelease(handle);
}

The tester_file directive identifies the file that the testing agent needs. Verify it is actually staged in the agent sandbox; selecting a different runtime model does not automatically package that file. A successful load is not evidence that the forecasts are correct. Check the input and output names, types, shapes, then execute and validate the output.

The inference contract: 128 bars in, eight bars ahead

For the particular community export we use, the model accepts padded history and horizon lengths in multiples of 32. We pass two independent rows: the completed close sequence and its negative. This example has 128 historical steps, a 32-step decode for the requested eight-step horizon, and no covariates. Other ONNX exports can use different tensor contracts.

InputTypeShape
xfloat32[2, 128]
obsbool[2, 128]
group_idsint64[2]
role_idsint64[2]
known_futurefloat32[2, 32]
known_future_maskbool[2, 32]

Outputs are quantiles (float32 [2, 32, 21]) and last_scale (float32 [2]). Assign distinct group IDs, mark both rows as targets, and set future covariate values and masks to zero/false. For shorter non-aligned histories, pad on the left and mark padding unobserved. Use OnnxSetInputShape, OnnxSetOutputShape and OnnxRun with matching tensor types.

The graph does not perform all of the upstream forecaster's postprocessing. For this export we cap extreme outputs using the context range and scale, combine each forward quantile with the negative of the complementary quantile of the mirrored row, and apply non-negative clipping for positive closing-price inputs. At zero-based step 7, ranks 2, 10 and 18 correspond to P10, P50 and P90. Check that the resulting values are finite and ordered. Loading the graph alone is not equivalent to running the full reference forecaster.

The reusable MQL5 client API

Our standalone client consists of two headers, TimestralClient.mqh and TimestralOnnxRuntime.mqh, installed together in MQL5/Include. The fifth argument to Setup selects the native model. The public graph is available from the source below; the Quanition headers are not currently publicly distributed. This example documents the existing integration interface, not a complete standalone download.

#include <TimestralClient.mqh>
input ENUM_TIMESTRAL_MODEL InpModel = TIMESTRAL_5M;
CTimestralClient forecast;

int OnInit()
{
   return forecast.Setup(_Symbol, PERIOD_H1, 128, 8, InpModel)
          ? INIT_SUCCEEDED : INIT_FAILED;
}
void OnTick()
{
   STimestralForecast f;
   if(!forecast.Forecast(f)) return;
   // f.p10, f.p50, f.p90: forecast of the eighth future close.
   // No trade request here.
}

Available model enum values are TIMESTRAL_5M, TIMESTRAL_28M, TIMESTRAL_123M and TIMESTRAL_209M. The client loads only the selected model, accepts lookbacks of 32–32,768 steps and horizons of 1–1,024 steps, and does not silently fall back to another model or a service.

Connect a forecast to an EA without introducing look-ahead

Read completed bars (start at shift 1, not shift 0), arrange them oldest to newest, and associate the forecast with the latest completed bar. Cache it for that bar. The horizon is counted in bars, not wall-clock hours; market closures can interrupt the clock. On missing history, invalid output or a model error, return an explicit unavailable result rather than reusing an older prediction.

One candidate rule is to allow a buy only when P50 is above the planned Ask, or a sell only when P50 is below the planned Bid. Another candidate is to compare the P90−P10 interval width with current volatility, or examine uncertainty before adding grid exposure. These are testable hypotheses, not recommendations to trade. Existing exits, position sizing, stops and margin controls must remain independent of model availability.

What our MT5 tests established

On 21 November 2026 we exercised the 5M integration in an XAUUSD H1 development EA using October 2026 real-tick history. With 128 completed bars and an eight-bar horizon, the fixed median-filter run recorded 25 forecast requests, 10 permitted entries, 15 blocked entries and zero inference errors. The filter-off ledger matched the pre-change baseline on all 44 recorded orders and 44 deals. This is an integration check, not a claim of forecasting accuracy or live profitability.

Separate research runs also executed the 28M, 123M and 209M exports inside MT5. They are not interchangeable performance upgrades. In a retrospective comparison over 2025–2026 real ticks, the larger models changed the trade population and loss distribution; lower drawdown or fewer consecutive losses did not always coincide with smaller loss amounts or greater net profit. We have not established a universally superior model size.

For your own evaluation, compare a forecast-off baseline and a forecast-on variant under the same data, cost, delay and risk settings. Evaluate forecast calibration and error against a persistence baseline separately from strategy profit, equity drawdown, worst loss sequence and execution costs. Hold an untouched evaluation period outside parameter selection.

Licensing and availability

The upstream implementation uses Apache-2.0; Mistral's model weights and the community exports are subject to a separate Modified MIT license with additional restrictions. Read the exact license before commercial use or distribution. The Quanition integration described here is currently development documentation, not a public SDK download or an announcement of a released Market feature. No weights are distributed with this article.

AI-assisted editorial preparation. The technical description follows the implementation and recorded development tests. Trading involves risk; historical results do not guarantee future outcomes.

Technical references