Backtest Configuration and Saving
The backtest configuration on the "Backtest" tab (time range, exchanges, fees, ...) and the strategy parameters can be saved with the strategy and are loaded again the next time the strategy is opened.
Saving
- Click "Save Backtest Settings": the configuration and strategy parameters are written as a comment block (the
backtestblock) at the top of the strategy source. - Click "Save Strategy": the platform also records the current backtest configuration and strategy parameters.
Loading
- When the strategy editor is opened or refreshed, the configuration in the source's
backtestblock is loaded first. - If the source has no
backtestblock, the configuration recorded by the last "Save Strategy" is loaded. - After editing the
backtestblock by hand, click the "Backtest Settings" button above the block to apply the change to the backtest form.
Block format
The word backtest follows the language's block-comment opener directly, then one key: value per line:
javascript
/*backtest
start: 2024-01-01 00:00:00
end: 2024-03-01 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Binance","currency":"BTC_USDT","balance":10000,"stocks":0,"fee":[0.1,0.1]}]
args: [["fast",5],["slow",20]]
*/
Comment syntax per language: JavaScript, TypeScript, Rust and PINE use /*backtest ... */; Python uses '''backtest ... '''; MyLanguage uses (*backtest ... *).
| Key | Format | Description |
|---|---|---|
| start, end | YYYY-MM-DD HH:mm:ss | Start and end time, parsed in the browser's time zone. |
| period | 1m, 1h, 1d etc., or seconds | Strategy K-line period. |
| basePeriod | same | Base K-line period; defaults to period; ignored in real-tick mode. |
| mode | 1 | Real-tick mode; omit for simulated-tick mode. |
| exchanges | JSON array | One element per exchange object, fields below. |
| args | JSON array | Strategy parameters, [["name", value], ...]; a third element with a template ID sets that template's parameter: ["name", value, templateId]. |
Fields of an exchanges element; everything except eid and currency is optional:
| Field | Description |
|---|---|
| eid | Exchange ID, e.g. Binance, Futures_OKX. |
| currency | Trading pair, e.g. BTC_USDT. |
| balance, stocks | Initial quote-currency and base-currency balances. |
| fee | [maker rate, taker rate] in percent. |
| feeMin | Minimum fee per fill; only applies to some markets. |
| depthDeep, depthAmount | Depth levels and the amount on each simulated level. |
| tradesMode | Whether trade prints are replayed in real-tick mode: "0" replay, "1" do not. |
| feeder | Custom data source URL, see Backtesting System → Custom Data Source. |
"Save Backtest Settings" also writes some keys starting with bt (e.g. btSlipPoint slippage, btNetDelay network delay, btFaultTolerant failure probability, btMaxBarLen max K-line bars) that record the other options of the backtest form; editing them by hand is not recommended. The local backtest engines read the same block, see Backtesting System → Local Backtesting Engine.