# Strategy tester (/vela-pro/indicators/backtesting/strategy-tester)



The strategy tester displays backtest results for [strategies](/vela-pro/indicators/backtesting/strategies) on the active chart in a resizable panel docked below the chart area. It is enabled by default when you call `enableVelaPro()` and requires no extra wiring. Because the panel listens to strategy runs on the active chart, it updates automatically after every input or property edit and on every new bar during live streaming.

## Panel behavior [#panel-behavior]

The strategy tester does not register an icon in the side rail. Instead, it manages its visibility based on active strategies on the chart:

* Opens automatically the first time a strategy reports backtest results (when `autoOpen` is `true`).
* Closes automatically when the last strategy is removed from the chart.
* Reopens after manual dismissal when the user clicks **Strategy report** on a strategy's legend row.

When multiple strategies run on the same chart, the panel title becomes a dropdown menu for switching between them. A strategy that reports its first backtest becomes the active selection automatically.

Workspace persistence records the bottom dock's height in the state document, but does not save whether the strategy tester was open. Reloading the page reopens the panel once a strategy reports results.

On narrow viewports using the mobile layout, the docked summary strip is omitted. Once a backtest completes, a floating **Backtest** button appears above the bottom bar and opens the full-screen report. See [Responsive layout](/vela-pro/customization/mobile/responsive) for mobile behavior details.

## Summary strip [#summary-strip]

By default, the strategy tester opens as a compact strip showing five headline figures above an equity curve:

| Metric        | Description                                                                               |
| ------------- | ----------------------------------------------------------------------------------------- |
| Net profit    | Strategy net profit                                                                       |
| Trades        | Total closed round-trip trades                                                            |
| Win rate      | Percentage of winning trades, alongside winning and losing trade counts                   |
| Max drawdown  | Largest peak-to-trough decline, shown as an amount and as a percentage of initial capital |
| Profit factor | Ratio of gross profit to gross loss                                                       |

The equity curve steps once per closed trade, and hovering over the curve shows the trade number and cumulative realized profit at that point. Users can adjust the strip using three layout controls:

* **Resize handle**: Drag the top border to change the dock height. As height decreases, the chart hides its axes first and then hides the curve while keeping the five headline metrics visible.
* **Collapse chevron**: Folds the dock down to a single bar showing the strategy title, date range, and net profit.
* **Maximize button**: Expands the full multi-tab report over the chart area.

When the active chart uses Heikin Ashi candles, the panel displays a warning banner explaining that synthetic averaged prices cannot be filled by real market orders and can produce overly optimistic backtest results.

<Note>
  The strategy tester labels all currency figures as USD regardless of the `currency` value declared by the strategy.
</Note>

## Report tabs [#report-tabs]

Maximizing the panel reveals three report tabs. Summary tables break results down across **All**, **Long**, and **Short** columns, displaying `-` whenever a metric cannot be computed. All trade timestamps and daily buckets use UTC.

| Tab                 | Contents                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Performance**     | Displays the equity curve with the five headline metrics, **Net Daily P\&L** and **Weekday Performance** bar charts, a **Performance** table (Net Profit, CAGR, Gross Profit, Gross Loss, Profit Factor, Average P\&L per Day, Average P\&L per Week, and Drawdown), **Risk-Adjusted Performance** (Calmar, Sharpe, and Sortino ratios), and **Benchmark** comparisons (Buy and Hold P\&L, Buy and Hold % Gain, and Strategy Outperformance).                                                                         |
| **Trades Analysis** | Displays a **P\&L Distribution** chart marking average winning trade, average losing trade, and overall average trade, a **Win Rate** ring of winners, losers, and breakeven trades, a trade summary table (closed, winning, losing, and breakeven counts, win rate, average P\&L, and average and largest winning and losing trades), a **Duration vs P\&L** scatter plot in bars with a fitted trend line, and tables of trade durations, winning and losing streaks in bars, and trade frequency per day and week. |
| **Trades Log**      | Lists every round trip with its trade number, side, entry and exit timestamps and prices, size, Net P\&L, MFE, MAE, and Cumulative P\&L. Switching **View Mode** converts the log into a monthly P\&L calendar displaying daily profit, trade count, and win rate alongside monthly net profit, best day, and worst day totals.                                                                                                                                                                                       |

In the **Trades Log**, each row includes a target button next to both its entry and exit fills. Clicking that button collapses the maximized view back to the summary strip, centers the chart on the selected fill with 60 bars of surrounding context on each side, and briefly flashes a label and crosshair marker at the execution price and bar. The highlight fades after a few seconds and is never saved in chart state.

## Configuration [#configuration]

Configure the panel via the `strategyTester` option in `enableVelaPro()`:

```ts
import { enableVelaPro } from '@luxalgo/vela-pro';

enableVelaPro({
    strategyTester: { autoOpen: false },
});
```

| Option         | Default | Description                                                                                                                                         |
| -------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| `autoOpen`     | `true`  | Opens the bottom dock to the strategy tester the first time a strategy reports. Set to `false` to open it only from the legend button or from code. |
| `order`        | `20`    | Position among panels in the bottom dock (for reference, the Trading panel uses `10`).                                                              |
| `legendAction` | `true`  | Displays the **Strategy report** button on strategy legend rows.                                                                                    |

Pass `enableVelaPro({ strategyTester: false })` to disable the strategy tester UI. Strategies still execute and draw trade fills on the chart, and you can still inspect [Backtest results](/vela-pro/indicators/backtesting/results) from code.

If you initialize features individually instead of calling `enableVelaPro()`, call `enableStrategyTester(options)` with the same options object. `enableStrategyTester` enables the bottom dock with default dimensions automatically, so call `enableBottomDock(options)` first if you want custom dock options. You must also register a scripting runtime with `enablePineEngine()` or [Custom runtimes](/vela-pro/indicators/runtimes/engines).

### Programmatic control [#programmatic-control]

When `autoOpen` is `false` or you trigger the report from custom application UI, open the dock on `STRATEGY_PANEL_ID`:

```ts
import { bottomDock, STRATEGY_PANEL_ID } from '@luxalgo/vela-pro';
import type { VelaWorkspace } from '@luxalgo/vela/workspace';

declare const workspace: VelaWorkspace;

document.querySelector('#show-backtest')?.addEventListener('click', () => {
    bottomDock(workspace.root)?.open(STRATEGY_PANEL_ID);
});
```

`bottomDock` returns `null` when the bottom dock is disabled. When enabled, the returned handle also provides `close()`, `toggle(id)`, and `setMaximized(on)`. To register additional custom panels alongside the strategy tester in the bottom dock, see [Custom panels and widgets](/vela-pro/modules/extending/custom-widgets).

## Metric calculation [#metric-calculation]

Every figure in the strategy tester derives from two data structures reported by the scripting engine: the `StrategyState` at the final bar and the list of `StrategyTrade` round trips. Most metrics are calculated from closed trades in the ledger, while bar-by-bar risk and benchmark statistics come directly from `StrategyState`.

| Metrics                                                         | Data source                                                                         |
| --------------------------------------------------------------- | ----------------------------------------------------------------------------------- |
| Sharpe Ratio, Sortino Ratio                                     | `StrategyState` fields (`sharpe`, `sortino`)                                        |
| Buy and Hold P\&L, Buy and Hold % Gain, Strategy Outperformance | `StrategyState` fields (`buyHoldPnl`, `buyHoldPct`, `outperformance`)               |
| Net profit, max drawdown                                        | `StrategyState` fields (`netPnl`, `maxDrawdown`)                                    |
| MFE, MAE                                                        | Per-trade `StrategyTrade` fields (`maxRunup`, `maxDrawdown`)                        |
| All other metrics                                               | Calculated from closed `StrategyTrade` entries (`side`, `entry`, `exit`, and `pnl`) |

The built-in Pine engine populates every field above unless a backtest span is too short to compute annualized ratios or benchmarks. When a custom runtime omits `sharpe`, `sortino`, or benchmark fields, those five rows display `-` while the remaining report metrics render normally. Open positions have no realized P\&L yet, so they appear in the **Trades Log** and are excluded from closed-trade summary calculations.

In the strategy tester UI, CAGR and the Calmar ratio compound net profit on a fixed base of `10,000` rather than on the strategy's configured `initial_capital`.

## Related [#related]

* [Strategies](/vela-pro/indicators/backtesting/strategies)
* [Backtest results](/vela-pro/indicators/backtesting/results)
* [Custom panels and widgets](/vela-pro/modules/extending/custom-widgets)
