FreqAI puts do_predict and DI_values on the strategy dataframe, not on the trade. A repeatable experiment snapshots both at entry fill and at exit fill with order_filled and trade.set_custom_data, then classifies each closed trade with the official meanings (1 is trustworthy; 2 means the model expired). A labeled offline fixture, not a FreqAI run, joins six stated trades to ten stated 1h candles: two entries have do_predict == 1, T4's 12:17 entry rounds to the 12:00 candle, and an exit-only join mis-attributes five of the six entry states. No prices or performance figures are claimed.
Calculation and worked example. AI-assisted drafting. Educational information; no individual financial advice.
These two columns sit on the dataframe, not on the trade
FreqAI writes do_predict and DI_values onto the strategy dataframe. The official configuration page (checked 15 November 2026) lists both under "Important dataframe key patterns". They are not, by themselves, fields on a closed trade. If you want them on each closed trade for a later experiment, you have to snapshot them when the trade opens and when it closes, and keep those snapshots with the trade.
This article is that logging method, plus a labeled offline fixture that applies the official field semantics to a stated closed-trade log. FreqAI was not trained or run here, and there are no prices or performance figures. It is not a general FreqAI explainer, and it is not a check of train_period_days against backtest_period_days. That window-leakage method is in the 14 November article.
What the official integers and the Dissimilarity Index mean
The configuration page says df['do_predict'] is an integer between -2 and 2, and that it tells you whether the prediction is trustworthy. The documented cases are:
do_predict | Official meaning (configuration page) |
|---|---|
1 | The prediction is trustworthy. |
0 | One of the Dissimilarity Index (DI) or the SVM treated the point as an outlier (each subtracts 1 from do_predict). |
-1 | Both the DI and the SVM treated the point as an outlier. |
-2 | The SVM and DBSCAN are both active and both identified a point that was already above the DI threshold. |
2 | A particular case: the model has expired due to exceeding expired_hours. |
The same page's subtract-1 rule is what produces those integers: a DI value above the configured threshold subtracts 1, then use_SVM_to_remove_outliers and use_DBSCAN_to_remove_outliers may each subtract 1 as well. -2 is the explicit all-three case.
That integer is not a unique fingerprint of which detector fired. A result of 0 is documented for a DI-only flag and for an SVM-only flag, and the subtract-1 rule can also produce 0 or -1 from combinations the page does not exemplify (for example DBSCAN alone). The fixture records those as a limit and only uses the documented, exemplified cases in the trade log. The docs do not say how do_predict == 2 composes with outlier flags, so the method treats expiration as its own case.
df['DI_values'] is a float Dissimilarity Index. The configuration page says a lower DI means the prediction is closer to the training data (higher prediction confidence). The feature-engineering page defines \(DI_k = d_k / \overline{d}\), the point's minimum distance to the training set divided by a characteristic training distance. DI_threshold is active when set greater than 0. The feature-engineering example is "DI_threshold": 1; the parameter table describes a positive float, typically less than 1. The fixture uses that example value as a label only, not as a recommended setting.
One naming tension is left as the docs write it. The configuration page's do_predict == 2 cell says expired_hours. The parameter table, and the running page's "Defining model expirations" section, use expiration_hours (default 0, models never expire). The running-page introduction also writes expired_hours. This article does not invent a second parameter.
Snapshot the values at fill time and store them on the trade
The official pages do not provide a built-in "log do_predict and DI_values on each closed trade" command. They do provide the pieces of a repeatable method.
confirm_trade_entry() cannot hold the snapshot: its documented signature has no trade object, and the advanced strategies page says trade.set_custom_data() can only be used in callbacks that also provide a trade object.
The order_filled callback is the hook that fits. It is called right after an order fills, for all order types, including entry and exit. The official example already loads the analyzed dataframe with self.dp.get_analyzed_dataframe(), takes the last candle, and, on the first successful entry fill, stores a candle field with trade.set_custom_data(). The same hook can store do_predict and DI_values (and the candle date) under keys such as entry_do_predict and entry_DI_values, and again on an exit fill as exit_do_predict and exit_DI_values. The advanced page recommends simple JSON-serializable types (int, float, str) and small values. confirm_trade_exit() does receive a trade object, but the callbacks page warns that it may be called multiple times in one iteration for the same trade if several exit reasons apply, so it is a poorer place to freeze the exit snapshot.
Two lookup rules from the advanced page matter in dry-run or live use. Do not use current_time to look up the latest candle; it points at the current incomplete candle, whose data is not available. dataframe.iloc[-1] is documented for get_analyzed_dataframe() because that helper only returns candles backtesting is allowed to see. A dry-run or live trade open date will not match the candle open date, so it must be rounded with timeframe_to_prev_date. The looked-up trade_candle may be empty for a trade that has just opened, because that candle is still incomplete.
After the trade has closed, read the stored keys back with trade.get_custom_data(). That is the experiment log: entry and exit integers, entry and exit DI values, and the candle dates they came from. Classify each row with the documented meanings above, and count how many closed trades opened with do_predict == 1 versus any other official value. Those counts are a log of prediction state, not a performance result.
Why not only join a final dataframe to a trades export at the end? FreqAI retrains, and the official docs do not state whether a later model may overwrite earlier candles' do_predict and DI_values in a saved frame. Snapshotting at fill time, and persisting the snapshot on the trade, does not depend on that unstated behaviour.
A labeled offline fixture, not a FreqAI run
The batch fixture (evidence/fx/closed_trade_do_predict_di_log.py) is an offline join. It does not start FreqAI. The pair ETH/USDT, the 1h timeframe, and the 2026-01-03 UTC timestamps are labels only. Ten stated candles carry official do_predict values and stated DI_values, with generating flags that match the documented cases. Six stated closed trades are joined to those candles. There are no prices.
The subtract-1 rule reproduces every documented combination: 1, 0 (DI only), 0 (SVM only), -1 (DI and SVM), -2 (all three), and 2 (expired). Decimal comparisons against the example threshold of 1 are consistent with the stated DI flags (0.40 is not above the threshold; 1.20 is).
The closed-trade log then records both ends of each trade:
| Trade | Entry candle | Entry do_predict / DI | Exit candle | Exit do_predict / DI |
|---|---|---|---|---|
| T1 | 08:00 | 1 / 0.40 | 09:00 | 1 / 0.55 |
| T2 | 08:00 | 1 / 0.40 | 16:00 | 0 / 1.10 |
| T3 | 10:00 | 0 / 1.20 | 15:00 | 1 / 0.45 |
| T4 | 12:00 (entry time 12:17) | -1 / 1.40 | 15:00 | 1 / 0.45 |
| T5 | 13:00 | -2 / 1.80 | 17:00 | 1 / 0.50 |
| T6 | 14:00 | 2 / 0.30 | 17:00 | 1 / 0.50 |
T4 is the official rounding case: an entry time of 12:17 UTC on a 1h timeframe is joined to the 12:00 candle, so the stored entry state is -1 and 1.40. Of the six stated entries, two have do_predict == 1 and four do not.
T1 keeps do_predict == 1 from entry to exit, with DI moving from 0.40 to 0.55. T2 also enters at 1 / 0.40, but exits on a candle whose stated DI of 1.10 is above the example threshold, so the exit integer is 0. If the log had been built only from the exit candle, five of the six trades would have had their entry state mis-attributed, including T2, T4, and T6 (expired at entry, trustworthy at exit). The method is to keep both snapshots.
The bot evaluation guide and the backtest statistics tool still need a window you can trust. This log does not replace a hyperopt in-sample and out-of-sample split. It only records whether each closed trade, in this stated set, opened and closed under a documented prediction state.
Limits
FreqAI was not run. The candles and trades are fixture inputs, not a bot result. The integer classification follows the configuration page and is not a unique map back to a detector. Expiration is not mixed with outlier flags, because that composition is not documented. DI_threshold = 1 is the official example, not a setting chosen for a model. The expired_hours / expiration_hours wording is quoted as the pages write it. This article does not cite developer/freqai, which returned HTTP 404 on the 15 November 2026 morning re-fetch.
Sources & method
What this article adds
A fill-time logging method for official FreqAI do_predict and DI_values on each closed trade: snapshot both columns in order_filled with trade.set_custom_data, because confirm_trade_entry has no trade object and confirm_trade_exit may fire more than once. It restates the documented do_predict meanings, notes that the integer is not a unique detector fingerprint, and quotes the expired_hours / expiration_hours wording without inventing a second parameter. A labeled offline fixture (FreqAI not run) joins six stated trades to ten stated 1h candles, checks the official subtract-1 cases, applies 1h rounding (12:17 to 12:00), and shows that an exit-only join would mis-attribute five of the six entry states.
How it was prepared
Official FreqAI and strategy pages were fetched from freqtrade.io (stable) on the morning of 2026-11-15 (Asia/Shanghai). freqai-configuration, freqai, freqai-running, freqai-feature-engineering, freqai-parameter-table, strategy-callbacks and strategy-advanced all returned HTTP 200, with Last-Modified Thu, 12 Nov 2026 05:44:20 GMT. https://www.freqtrade.io/en/stable/developer/freqai/ returned HTTP 404 and is not cited. The closed-trade log (evidence/fx/closed_trade_do_predict_di_log.py) is a labeled offline fixture: stated 1h candles and stated trades, official field semantics, Decimal comparisons against the documented example DI_threshold of 1, and no prices. FreqAI was not trained or run, and no backtest, dry-run or live result is claimed. expired_hours (configuration page; also the running-page introduction) and expiration_hours (parameter table and the running page's expirations section) are quoted as written and are not treated as two parameters. Combinations the subtract-1 rule can produce, but the configuration page does not exemplify, are labeled as such and are not used in the trade log.
- Freqtrade docs: FreqAI configuration (do_predict and DI_values key patterns) Checked 2026-11-15
- Freqtrade docs: FreqAI feature engineering (Dissimilarity Index and DI_threshold) Checked 2026-11-15
- Freqtrade docs: Strategy callbacks (order_filled and set_custom_data example) Checked 2026-11-15
- Freqtrade docs: Advanced strategies (persistent custom trade data and dataframe lookup) Checked 2026-11-15
- Freqtrade docs: Running FreqAI (expired_hours / expiration_hours wording) Checked 2026-11-15
- Freqtrade docs: FreqAI parameter table (DI_threshold, SVM/DBSCAN flags, expiration_hours) Checked 2026-11-15
- Freqtrade docs: FreqAI introduction Checked 2026-11-15
Configuration supports the Important dataframe key patterns for do_predict (integer -2 to 2, trustworthy at 1, subtract-1 by DI / SVM / DBSCAN, explicit 0 / -1 / -2 cases, and do_predict == 2 from exceeding expired_hours) and for DI_values (lower is closer to the training data). Feature engineering supports the DI formula, DI_threshold example of 1, and the SVM / DBSCAN config flags. The parameter table supports DI_threshold (active when > 0; positive float, typically < 1), use_SVM_to_remove_outliers, use_DBSCAN_to_remove_outliers, and expiration_hours (default 0). Running FreqAI supports expired_hours in the introduction and expiration_hours in Defining model expirations. Strategy callbacks support order_filled (all order types, get_analyzed_dataframe, set_custom_data on first entry fill) and the warning that confirm_trade_exit may be called more than once. Advanced strategies support persistent custom data (set_custom_data / get_custom_data, trade object required, simple JSON-serializable types) and dataframe lookup (iloc[-1], timeframe_to_prev_date, possibly empty trade_candle).
For corrections, contact the publisher. Editorial policy · Affiliate disclosure