backtest_condition
What happened AFTER a condition in the past, on one symbol and timeframe — "how did BTC do after RSI dropped below 30 on 4h", "is a golden cross on ETH daily actually bullish", "what usually follows a −5% day on SOL". Runs an event study over the whole stored tape (up to 1000 candles: ~41 days on 1h, ~166 days on 4h, ~3 years on 1d): occurrences, average / median forward return, win rate, average best and worst excursion per horizon, the unconditional baseline over the same tape and the EDGE the condition adds over it, the last five episodes, and whether the condition is active on the latest bar. Same condition vocabulary as screen_symbols. Quote the edge and the sample size together — a 3-sample stat is an anecdote.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Trading pair, e.g. BTCUSDT (a bare "BTC" is read as its USDT perpetual) | |
| horizons | No | Bars ahead to measure returns over (≤ 4). Default per interval ≈ 4h / 1d / 3d: 1h → [4, 24, 72], 4h → [6, 18, 42], 1d → [1, 3, 7]. | |
| interval | No | Candle timeframe | 4h |
| conditions | Yes | Up to 3 conditions, AND-ed. Examples: RSI oversold = {"metric":"rsi","op":"lt","value":30}; above the 200 EMA = {"metric":"priceVsEma","op":"gt","value":0,"period":200}; golden cross = {"metric":"emaSpread","op":"crossAbove","value":0,"period":50,"period2":200}; MACD bullish cross = {"metric":"macdHistogram","op":"crossAbove","value":0}; dumped 5% in a day = {"metric":"changePct","op":"lt","value":-5,"period":24}. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| to | No | ||
| bars | No | Candles the study ran on (the whole stored tape) | |
| from | No | ||
| recent | No | Newest episodes first: { openTime, barsAgo, price, returnsPct { "<bars>": pct } } | |
| symbol | No | ||
| horizons | No | Per look-ahead: { bars, samples, avgReturnPct, medianReturnPct, winRatePct, avgMaxUpPct, avgMaxDownPct, bestPct, worstPct, baselineAvgReturnPct, edgePct } — edge = avg − unconditional baseline | |
| interval | No | ||
| warnings | No | ||
| activeNow | No | Conditions hold on the latest closed bar | |
| conditions | No | ||
| occurrences | No | Episodes — the FIRST bar of each run where the conditions held | |
| horizonHours | No | ||
| coverageHours | No | ||
| currentValues | No | Latest value of every metric involved | |
| evaluableBars | No | ||
| lastOccurrence | No | { openTime, barsAgo, price } |