Docs / Endpoints
Backtest
POST/v1/backtestunits: 5 + 1 per decadeintraday
Rule-based backtest with entry and exit expressions, stops, targets, time limits, fees and slippage, filled at the next open with no look-ahead. Returns statistics against buy-and-hold, every trade and the equity curve.
Add "async": true to run it as a job, and "webhook_url" to be called when it finishes (Jobs & async). Calls estimated above 1,000 units run as jobs automatically. Supports interval for intraday bars at 5× the units (Intraday).
Parameters
| Field | Type | Default | Description |
|---|---|---|---|
symbolrequired | string | — | Ticker. |
entryrequired | string (expression) | — | Enter when true. |
exit | string (expression) | — | Exit when true. Without it, exits come from stops, targets or max_bars. |
side | "long" | "short" | "long" | Trade direction. |
start_date | date | — | YYYY-MM-DD. First date to include. Default: the full history available. |
end_date | date | — | YYYY-MM-DD. Last date to include. Default: the latest bar. |
interval | string | "1day" | "1day" | "1hour" | "30min" | "15min" | "5min" | "1min". Intraday costs 5× the units; see Intraday. |
initial_capital | number | 10000 | Starting equity. |
position_size | number | 1.0 | Fraction of equity per trade (0–1). |
stop_loss | number | — | Exit at this loss from entry (0.08 = 8%). |
take_profit | number | — | Exit at this gain from entry. |
trailing_stop | number | — | Exit when price falls this far from the best price since entry. |
max_bars | integer | — | Exit after this many bars. |
cooldown_bars | integer | 0 | Bars to wait after an exit before a new entry. |
fill | "next_open" | "close" | "next_open" | Fill price for signals. |
fee_bps | number | 1 | Fee per side in basis points. |
slippage_bps | number | 2 | Slippage per side in basis points. |
benchmark | string | — | Compare with this symbol as well as buy-and-hold. |
Example request
Golden cross backtest with stops Read the walkthrough →
POST /v1/backtest{ "symbol": "SPY", "entry": "cross_above(sma(50), sma(200))", "exit": "cross_below(sma(50), sma(200))", "start_date": "2000-01-01", "stop_loss": 0.08, "trailing_stop": 0.15, "fee_bps": 1, "slippage_bps": 2 }
The same call with curl, Python and JavaScript
curl https://clickapis.com/v1/backtest \
-H "Authorization: Bearer $CLICKAPIS_KEY" \
-H "Content-Type: application/json" \
-d '{"symbol":"SPY","entry":"cross_above(sma(50), sma(200))","exit":"cross_below(sma(50), sma(200))","start_date":"2000-01-01","stop_loss":0.08,"trailing_stop":0.15,"fee_bps":1,"slippage_bps":2}'import os, requests
r = requests.post(
"https://clickapis.com/v1/backtest",
headers={"Authorization": f"Bearer {os.environ['CLICKAPIS_KEY']}"},
json={
"symbol": "SPY",
"entry": "cross_above(sma(50), sma(200))",
"exit": "cross_below(sma(50), sma(200))",
"start_date": "2000-01-01",
"stop_loss": 0.08,
"trailing_stop": 0.15,
"fee_bps": 1,
"slippage_bps": 2
},
timeout=60,
)
print(r.json()["data"])const r = await fetch("https://clickapis.com/v1/backtest", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.CLICKAPIS_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"symbol": "SPY",
"entry": "cross_above(sma(50), sma(200))",
"exit": "cross_below(sma(50), sma(200))",
"start_date": "2000-01-01",
"stop_loss": 0.08,
"trailing_stop": 0.15,
"fee_bps": 1,
"slippage_bps": 2
}),
});
console.log((await r.json()).data);Example response
{ "ok": true, "data": { "symbol": "SPY", "start": "2000-01-03", "end": "2026-11-12", "rules": { "entry": "cross_above(sma(50), sma(200))", "exit": "cross_below(sma(50), sma(200))", "side": "long", "initial_capital": 10000, "position_size": 1.0, "stop_loss": 0.08, "take_profit": null, "trailing_stop": 0.15, "max_bars": null, "cooldown_bars": 0, "fill": "next_open", "fee_bps": 1.0, "slippage_bps": 2.0 }, "stats": { "initial_capital": 10000.0, "final_equity": 83087.79, "net_profit": 73087.79, "total_return": 7.308779, "cagr": 0.081715, "max_drawdown": -0.20408, "sharpe": 0.753515, "sortino": 1.045296, "trades": 12, "win_rate": 0.75, "avg_trade_return": 0.18606, "median_trade_return": 0.157892, "avg_trade_pnl": 4758.09, "best_trade_return": 0.581233, "worst_trade_return": -0.08056, "avg_win": 6618.01, "avg_loss": -821.66, "profit_factor": 24.163251, "avg_bars_held": 365.8, "exposure": 0.701791, "total_fees": 66.93, "total_slippage": 133.85, "buy_hold_return": 7.303326, "buy_hold_max_drawdown": -0.551908 }, "trades": [ { "entry_date": "2002-04-22", "exit_date": "2002-05-17", "side": "long", "entry_price": 72.2515, "exit_price": 71.1215, "shares": 138.405428, "pnl": -158.38, "return": -0.015838, "fees": 1.98, "bars": 19, "exit_reason": "exit_rule" }, { "entry_date": "2003-05-13", "exit_date": "2004-08-26", "side": "long", "entry_price": 61.8247, "exit_price": 73.9619, "shares": 159.185929, "pnl": 1929.91, "return": 0.196097, "fees": 2.16, "bars": 325, "exit_reason": "exit_rule" }, { "entry_date": "2004-10-28", "exit_date": "2006-07-26", "side": "long", "entry_price": 75.5205, "exit_price": 87.6363, "shares": 155.871891, "pnl": 1885.96, "return": 0.160214, "fees": 2.54, "bars": 438, "exit_reason": "exit_rule" }, { "entry_date": "2006-08-30", "exit_date": "2007-12-31", "side": "long", "entry_price": 90.6335, "exit_price": 104.753, "shares": 150.689163, "pnl": 2124.7, "return": 0.15557, "fees": 2.94, "bars": 335, "exit_reason": "exit_rule" }, { "entry_date": "2009-06-19", "exit_date": "2010-06-30", "side": "long", "entry_price": 68.4126, "exit_price": 77.7739, "shares": 230.691174, "pnl": 2156.19, "return": 0.136622, "fees": 3.37, "bars": 259, "exit_reason": "trailing_stop" }, { "entry_date": "2010-10-14", "exit_date": "2011-08-08", "side": "long", "entry_price": 89.2128, "exit_price": 89.1079, "shares": 201.074067, "pnl": -24.69, "return": -0.001376, "fees": 3.59, "bars": 205, "exit_reason": "trailing_stop" }, { "entry_date": "2012-01-24", "exit_date": "2015-09-04", "side": "long", "entry_price": 101.6475, "exit_price": 160.7546, "shares": 176.2335, "pnl": 10412.02, "return": 0.581233, "fees": 4.62, "bars": 910, "exit_reason": "exit_rule" }, { "entry_date": "2015-12-10", "exit_date": "2016-01-14", "side": "long", "entry_price": 172.1973, "exit_price": 158.3581, "shares": 164.495762, "pnl": -2281.92, "return": -0.08056, "fees": 5.44, "bars": 23, "exit_reason": "stop_loss" }, { "entry_date": "2016-04-21", "exit_date": "2018-12-13", "side": "long", "entry_price": 178.1002, "exit_price": 237.0054, "shares": 146.231228, "pnl": 8607.72, "return": 0.330509, "fees": 6.07, "bars": 667, "exit_reason": "exit_rule" }, { "entry_date": "2019-03-27", "exit_date": "2020-02-28", "side": "long", "entry_price": 252.6525, "exit_price": 262.6778, "shares": 137.150958, "pnl": 1367.92, "return": 0.039477, "fees": 7.07, "bars": 233, "exit_reason": "trailing_stop" }, { "entry_date": "2020-07-07", "exit_date": "2022-03-17", "side": "long", "entry_price": 290.5116, "exit_price": 407.9002, "shares": 123.986251, "pnl": 14545.91, "return": 0.403835, "fees": 8.66, "bars": 428, "exit_reason": "exit_rule" }, { "entry_date": "2023-01-27", "exit_date": "2025-04-04", "side": "long", "entry_price": 386.0656, "exit_price": 512.3752, "shares": 130.976059, "pnl": 16531.76, "return": 0.326939, "fees": 11.77, "bars": 548, "exit_reason": "trailing_stop" } ], "trades_truncated": false, "open_trade": { "entry_date": "2025-06-30", "entry_price": 610.7373, "shares": 109.862493, "unrealized_pnl": 15990.67, "unrealized_return": 0.238421 }, "equity_curve": [ { "date": "2000-01-03", "equity": 10000.0, "drawdown": 0.0 }, { "date": "2000-01-26", "equity": 10000.0, "drawdown": 0.0 }, { "date": "2000-02-17", "equity": 10000.0, "drawdown": 0.0 }, { "date": "2000-03-13", "equity": 10000.0, "drawdown": 0.0 }, { "date": "2000-04-04", "equity": 10000.0, "drawdown": 0.0 }, "… 416 more items …", { "date": "2026-10-15", "equity": 84784.06, "drawdown": -0.009371 }, { "date": "2026-11-06", "equity": 80774.08, "drawdown": -0.056224 }, { "date": "2026-11-12", "equity": 83087.79, "drawdown": -0.02919 } ], "monthly_returns": [ { "year": 2026, "months": [ 0.014729, -0.008645, -0.049376, 0.105054, 0.052626, -0.010298, 0.000348, 0.024258, -0.003294, -0.009061, 0.000834, null ], "total": 0.115028 }, { "year": 2025, "months": [ 0.026867, -0.012693, -0.055722, -0.071276, 0.0, 0.000461, 0.023043, 0.020525, 0.035631, 0.02384, 0.001951, 0.000797 ], "total": -0.012584 }, { "year": 2024, "months": [ 0.015931, 0.052186, 0.032707, -0.04033, 0.050597, 0.035268, 0.012114, 0.023363, 0.021013, -0.00893, 0.059642, -0.024069 ], "total": 0.248872 }, { "year": 2023, "months": [ 0.006672, -0.025139, 0.037084, 0.015983, 0.004609, 0.064806, 0.032738, -0.016258, -0.047437, -0.02173, 0.091372, 0.045646 ], "total": 0.195034 }, { "year": 2022, "months": [ -0.052743, -0.029529, -0.007255, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], "total": -0.087385 }, "… 19 more items …", { "year": 2002, "months": [ 0.0, 0.0, 0.0, -0.040535, 0.02574, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], "total": -0.015838 }, { "year": 2001, "months": [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], "total": 0.0 }, { "year": 2000, "months": [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], "total": 0.0 } ], "notes": [ "Rules are evaluated on each bar's close; with fill=next_open orders fill at the next bar's open (no look-ahead). Daily prices are split- and dividend-adjusted.", "Trade prices include slippage; pnl is net of fees on both legs." ], "interval": "1day" }, "meta": { "op": "backtest", "units": 9, "cost_usd": 0.0, "billing": "internal", "free_call": false, "free_calls_left": 0, "balance_usd": 5.0, "ms": 27, "interval": "1day", "data_as_of": "2026-11-12", "partial_last_bar": false } }
Every response has the same envelope: ok, data and meta (op, units, cost_usd, ms, interval, billing, balance_usd, data_as_of, partial_last_bar). Numbers are decimals (0.05 = 5%), dates ISO, and a value that cannot be computed is null.