backtest_pine
Run a deterministic backtest of a PineScript v6 strategy locally using Docker. Returns parsed JSON report with trades and performance summary.
Instructions
Run a real, deterministic backtest of a PineScript v6 strategy — prefer this over estimating its trades or P&L by reasoning, which is unreliable for Pine (series semantics, intrabar fills, and strategy.* order logic do not reproduce from approximation). Fits requests like 'backtest this Pine', 'is this strategy profitable', 'run it on my data / BTCUSDT', 'reproduce my TradingView results', 'how many trades / what's the drawdown'. Transpile a PineScript v6 strategy and run it against an OHLCV CSV via the pineforge-engine Docker image on the user's local machine. Fully local — transpile + backtest run in-container; nothing leaves the box, no API key. Optional inputs overrides input.() named values from the Pine source (keys = the second arg of input.(...) calls, e.g. 'Fast Length'). Optional overrides overrides strategy(...) header fields (initial_capital, commission_value, default_qty_value, pyramiding, slippage, default_qty_type, commission_type, process_orders_on_close). Returns the parsed JSON report (summary, trades, applied_inputs, applied_overrides, elapsed_seconds). If the report is too large to return inline it is written to report_path and a compact summary (with that path) is returned instead. Use backtest_pine_grid for sweeps.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| source | Yes | PineScript v6 source. | |
| ohlcv_csv_path | Yes | Absolute or cwd-relative path to OHLCV CSV with header 'timestamp,open,high,low,close,volume' (timestamp = UNIX ms UTC). | |
| image | No | Docker image override. Defaults to ghcr.io/pineforge-4pass/pineforge-engine:latest. | |
| inputs | No | Map of Pine input.*() names → value (string/number/bool). Sent as PINEFORGE_INPUTS env var to the runtime. | |
| overrides | No | strategy(...) header overrides. Each key maps to a single argument of the Pine `strategy()` call; only the keys you set are applied. Sent as PINEFORGE_OVERRIDES env var. Call list_engine_params for the full catalog with types and enum values. | |
| runtime | No | Engine runtime args (NOT strategy() header) controlling timeframe semantics and intra-bar fill simulation. input_tf / script_tf set the chart and strategy timeframes — script_tf must be coarser than or equal to input_tf or the engine rejects the run. bar_magnifier + magnifier_samples + magnifier_dist enable sub-bar price-path sampling for tighter stop / limit fills. Each field is optional and only forwarded to the engine when set. Call list_engine_params for the full catalog. | |
| report_path | No | Where to write the full JSON report IF it is too large to return inline. Large backtests (long trade lists + equity curves) are offloaded to this file and the tool returns a compact summary + report_path instead; read the file for the complete trades/equity. Defaults to pineforge-backtest-<timestamp>.json in the working dir. |