Backtest a trading rule
run_backtestBacktest a simple trading rule on one connected account's own broker candles. Read-only: it replays past bars and never places or changes a broker order. Write the rule from the user's plain words: one exact broker symbol, a timeframe (M1, M5, M15, H1, H4 or D1), a UTC from and to range of at most 50000 bars, one entry per side with an optional exit condition, a stop, an optional target, the risk per trade and an initialBalance. A condition compares two series with above, below, crossesAbove or crossesBelow; join 2 to 8 of them with {kind: "all" | "any", conditions: [...]}. A series is {kind: "price", field: "close"}, {kind: "constant", value: 70}, or an indicator with a period: sma, ema, rsi, atr, highest or lowest. Example for "buy gold on H1 when the close crosses above the 50 EMA, stop 1.5 ATR, target 2R, risk 1%": {symbol: "XAUUSD", timeframe: "H1", from: "2026-01-01T00:00:00Z", to: "2026-11-01T00:00:00Z", entries: [{side: "long", when: {kind: "crossesAbove", left: {kind: "price", field: "close"}, right: {kind: "ema", period: 50}}}], stop: {kind: "atr", period: 14, multiple: 1.5}, target: {kind: "riskMultiple", value: 2}, risk: {kind: "percentOfBalance", value: 1}, initialBalance: 10000}. A condition is read when a bar closes and the order fills at the next bar's open. The result has the trade count, net result in the account currency, maximum drawdown, win rate, profit factor, costs paid, an equity curve of at most 50 points and the assumptions. Report the dates the bars actually cover, from metadata.firstBarTime and lastBarTime, not the dates asked for; when the broker's history is shorter than the range, the first assumption says so. Tell the user the assumptions that shape the numbers: historical spread is approximated from one value per bar, today's swap rates and tick value are applied to the whole period, the account's headline leverage is used for every symbol, and commission is counted only when costs.commissionPerLotRoundTrip is supplied. When the user has set a prop-firm program for the account, propOverlay estimates from bar data whether the run would have touched the daily or maximum loss floor or reached the first target; set initialBalance to the challenge size for that. Present it as an estimate and never as a pass or a fail: a backtest that stays inside the limits can still fail live, and propOverlay.limits lists what it cannot see. A backtest describes the past and does not predict future results. On insufficient_history widen the range or lower the timeframe; on symbol_not_found use details.suggestions; on backtest_unsupported the symbol cannot be priced, so say so and do not estimate; on invalid_request fix the named field and call again.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"rule": "<rule>",
"accountId": "<accountId>"
},
"name": "run_backtest"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rule | Yes | ||
| costs | No | ||
| accountId | Yes | ||
| includeTrades | No | Return the first 500 trades as well as the summary. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| login | Yes | ||
| server | Yes | ||
| source | Yes | Live MT5 source data the run read: the account currency and leverage, and the symbol's current contract, swap and tick-value facts. The candles themselves are not returned. | |
| accountId | Yes | ||
| calculated | Yes | FiveSocket-calculated values. A backtest is a simulation over past bars, not a forecast. | |
| propOverlay | Yes | Present when the user has set a prop-firm program for the account: an estimate, from bar data, of how the same run would have fared against that program's daily-loss, maximum-loss and profit-target rules. A run that stays inside the limits here can still fail live. |