Offline backtesting

Run PineScript backtests offline, on your own data

PineForge transpiles PineScript v6 to native C++ and runs it on your local machine via Docker. Local-first, byte-reproducible, runs anywhere Docker runs. Bring your own OHLCV CSV.

Why offline?

Browser-based backtesting is great for chart-side iteration. Offline backtesting is what you reach for when the next step is shipping money behind the strategy: when you need an audit trail, when CI has to gate every commit, when a result from two months ago has to reproduce bit-for-bit today.

Running backtests offline gives you the things browser-based testers can't: results are byte-reproducible — same input, same output, every time. You pin the engine version, check results into a repository, diff trade lists between commits, and run the entire thing headlessly in your CI pipeline. The CSV you feed in is yours; the binary you run is local; the report you get back is auditable.

The practical list of what offline unlocks: version-pinned engines so a commit from two months ago produces the same trade list today; custom data ingestion so you can test against your exchange's tick reconstructions, your data vendor's point-in-time equity prices, or any alt-data feed you can serialize to OHLCV; CI integration so regressions fail the build before they reach production; and multi-broker portability because your strategy's logic isn't locked to a platform — it's a file.

If you've ever needed to share a backtest result with a colleague and realized the only way to "share" it was to screenshot a chart — offline running is what you're missing.

How it works

Three steps. The full workflow from Pine source to a JSON trade report takes under two minutes the first time and under thirty seconds for every subsequent run.

Step 1 — Pull the runtime. One container image. No pip, no key, no signup — transpile and backtest both run inside it, offline. Free for personal trading.

Step 2 — Transpile your Pine to C++. Run the container in transpile-only mode and it turns your PineScript v6 into a complete C++ source file, locally. No Pine interpreter runs at runtime — the engine compiles it to native machine code.

docker run --rm --network=none \
  -e PINEFORGE_TRANSPILE_ONLY=1 \
  -v "$(pwd)/my_strategy.pine":/in/strategy.pine:ro \
  ghcr.io/pineforge-4pass/pineforge-engine:latest > strategy.cpp

Step 3 — Backtest. Mount your OHLCV CSV alongside the generated C++ and run the container. The engine reads the data file, executes the strategy bar-by-bar, and writes a JSON report to stdout.

docker run --rm --network=none \
  -v "$(pwd)/strategy.cpp":/in/strategy.cpp:ro \
  -v "$(pwd)/ohlcv.csv":/in/ohlcv.csv:ro \
  ghcr.io/pineforge-4pass/pineforge-engine:latest > report.json

The JSON output includes a full trade list with entry and exit prices, bar indices, position sizes, and a summary block with net PnL, max drawdown, total trades, profit factor, and Sharpe ratio. All fields are stable across patch releases of the same major version — safe to parse in scripts.

That's the entire workflow. No GUI, no account re-authentication, no chart loading. If you can run Docker, you can run PineForge offline backtests.

What you can backtest

The short answer: anything you can serialize as OHLCV. PineForge is not connected to any market data provider. You bring the data; the engine runs the strategy.

Crypto from your exchange. Pull raw trade data from Binance, Bybit, Kraken, or any exchange with a REST or WebSocket API. Aggregate to whatever timeframe your strategy uses. Feed the CSV directly. Test on the exact pair-and-venue combination you'll trade.

Equities from your data vendor. Polygon, Norgate, BarChart, Tiingo — pick your source, export point-in-time adjusted prices, run backtests with your actual fills and your actual survivorship-bias-free universe.

Tick reconstructions. If you have Level 2 data and want to test on synthetic 1-second bars reconstructed from ticks, you can. Generate the OHLCV from your tick data and pass it in. The engine doesn't know or care where the bars came from.

Alt-data. Sentiment scores, on-chain metrics, funding rates, options skew — if you can express it as a time series aligned to your bar index, you can incorporate it in Pine via custom data columns and test it offline.

The 246-strategy reference suite in the gallery was backtested against TradingView CSV exports (for parity validation) and custom CSV datasets (for regression testing). 245 of the 246 hit the canonical strict-excellent tier (PnL drift ≤ 0.5% over the comparison window). The remaining 1 is a documented TV-side anomaly — all deep-analyzed, traced to TradingView state. Zero real engine bugs remain.

Get started