§27 STRATEGY_BACKTESTER¶
Run a strategy against historical price data and read the performance ledger before committing capital.
OVERVIEW¶
Backtest replays a rule on past daily bars for one stock and tells you what it would have done: total return, drawdown, win rate and every trade. It is a way to check an idea, not a promise.
A server-side strategy backtester. You pick a symbol, a strategy, its parameters, a date range, and a starting balance; the backtest pulls daily historical closes for that symbol, walks bar-by-bar evaluating the strategy's signal at each close, and simulates a long-only book: on a buy, it deploys available cash into shares at that day's close; on a sell, it liquidates the position at that day's close. Round-trip P&L is computed at the sell; equity is marked-to-close every day. The Sharpe ratio is annualized off daily returns with the standard √252 scaling.

- Buy signal: deploys available cash into shares at that day's close
- Sell signal: liquidates the position at that day's close
- Round-trip P&L is recorded at the sell; equity is marked-to-close every day
- Sharpe ratio is annualized off daily returns using the standard √252 scaling
Scope limitations
Daily-bar only. No intraday timing. Commission, slippage, position sizing, and short selling are optional settings rather than hard limits. Custom-strategy upload is not a thing you can do anonymously — use the Custom Formula (Pine-lite) path to write your own entry and exit rules. Past results do not predict future ones.
FEATURES¶
Strategies¶
| Strategy | Signal logic | Defaults |
|---|---|---|
rsi_crossover |
Buy when RSI(period) crosses below oversold; sell when RSI crosses above overbought |
period 14 / oversold 30 / overbought 70 |
ma_crossover |
Buy when close crosses above the moving average; sell when close crosses below. maType=0 SMA, maType=1 EMA |
period 20 |
macd_signal |
Buy on bullish MACD cross (MACD line crosses above signal line); sell on bearish cross | fast 12 / slow 26 / signal 9 |
bollinger_breakout |
Buy when price breaks below the lower band; sell when price breaks above the upper band (mean-reversion logic) | period 20 / stdDev 2.0 |
formula_strategy |
Custom entry and exit rules written in Pine-lite formula boxes | — |
Simulation Settings¶
The following four settings apply to every strategy and appear beneath the strategy-specific inputs:
| Setting | Description | Default |
|---|---|---|
| Commission (bps) | Cost applied on every buy and sell, in basis points. 10 bps = 0.10% | 0 |
| Slippage (bps) | Fill penalty relative to the bar's close. Buys fill higher; sells fill lower | 0 |
| Position Size (%) | Share of available cash used on each entry, from 1 to 100 | 100 |
Shorts (ALLOW_SHORT) |
When enabled, an exit signal while flat opens a short; an entry signal closes it | Off |
Try 5–10 bps each for commission and slippage to see how much of a rule's profit survives trading costs.
Result Metrics¶
| Metric | Definition |
|---|---|
| Total Return | (finalEquity − initialCapital) / initialCapital × 100 |
| Buy & Hold | Same window, all cash deployed at the first close, marked at the last close |
| Max Drawdown | Peak-to-trough decline of the strategy equity curve |
| Sharpe Ratio | Annualized Sharpe off daily returns, √252 scaling |
| Win Rate | Percentage of closed trades with positive P&L |
| Total Trades | Count of completed round-trip trades |
| Final Equity | Closing portfolio value at end of window |
| vs Buy & Hold | Total Return minus the Buy & Hold return for the same window |
Output Panels¶
Summary cards — eight metrics displayed with green/red coloring matched to the sign of the result. Beating buy-and-hold is the bar to clear.
Equity curve — strategy line plotted against buy-and-hold over the full date range. The shape of the curve — particularly drawdown behavior — is more informative than the endpoint alone.
Trade log — bar-by-bar entry and exit table showing trade type (buy, sell, short, or cover), date, price, share count, and profit for every completed trade. Use this to identify whipsaw runs and individual blow-up trades.
Saved Strategies¶
Type a name in the Strategy name field, then click Save. The full setup is stored, including dates, costs, and formulas. Pick a saved strategy from the list and click Load to restore the form, or Delete to remove it. Up to 100 saved strategies are supported.
ACCESS¶
| Item | Detail |
|---|---|
| Path | /backtest |
| Keyboard shortcut | None |
| Sidebar location | §TOOLS group |
| Required tier | Pro and above |
Tier gate
Free accounts see the upgrade gate. Access is enforced server-side as well as in the app — the backtest cannot be run from a Free account regardless of how the request is made.
HOW TO USE¶
- Click Backtest in the sidebar to open
/backtest. The form loads pre-filled withAAPL,RSI Crossover, default parameters, a start date of one year ago, today's date, and$10,000initial capital. - Enter a Symbol. Input is uppercased automatically.
- Select a Strategy from the dropdown —
RSI Crossover,MA Crossover,MACD Signal,Bollinger Breakout, orCustom Formula (Pine-lite). Changing the strategy resets all parameters to that strategy's defaults. - Set Start Date and End Date.
- Set Initial Capital ($). Must be greater than 0.
- Adjust strategy parameters in the inputs below. Each strategy exposes its own parameter set — see the Strategies table above for the full field list per strategy.
- Optionally adjust Commission (bps), Slippage (bps), Position Size (%), and Shorts — see the Simulation Settings table above.
- Click [ RUN_BACKTEST ]. The button changes to [ RUNNING... ] while data is pulled and the engine runs.
- Review the eight summary cards, the equity curve, and the trade log.
Writing a Custom Formula¶
- Choose Custom Formula (Pine-lite) as the strategy. Two boxes appear — one for the entry rule and one for the exit rule.
- Click a preset to fill them: RSI reversion, SMA trend, or 55-bar breakout.
- Or type your own — for example
rsi(close, 14) < 30to enter andrsi(close, 14) > 70to exit. Each rule must evaluate to true or false on each bar. - A message beneath a box indicates if the rule cannot be parsed. Fix any errors before running.
Reading the results
Do not use the absolute return numbers to validate a real trading system. Focus on the delta between strategy and buy-and-hold, and the shape of the equity curve — particularly whether the strategy moves to cash ahead of significant drawdowns. Long tests on a single stock overfit easily; try several tickers and periods.
WHEN TO USE¶
- First-pass edge check — does RSI(14) with 30/70 thresholds beat buy-and-hold on a given name over the last year?
- Strategy family comparison — same window, same capital, swap RSI → MACD → Bollinger and compare Sharpe deltas.
- Parameter sweep — change RSI period from 14 to 21 and observe win rate movement.
- Drawdown stress test — bracket a known bear cycle with the date range and check whether the strategy moves to cash or rides it down.
TROUBLESHOOTING¶
| Symptom | Fix |
|---|---|
| Upgrade card shown | Backtest requires a Pro plan. See Pricing. |
| Zero trades | The rule never triggered in that window. Widen the dates or loosen the rule. |
| Formula will not run | Read the message under the box. Check brackets and confirm each rule ends in a true/false test. |
| No data for ticker | Check the spelling and confirm the symbol traded during the dates chosen. |