TradingView-Exact Python Backtester and Auto-Optimizer
Proves a local backtester reproduces TradingView trade for trade, then sweeps parameters offline with numbers that match the chart.
On TradingView's own exported bars: 84 of 84 trades, identical timestamps, fills and P&L; optimiser's top prediction re-read from TradingView to the cent; and a clear finding that consolidated vendor data, not the engine, causes residual differences.

- 84/84 trade parity on TradingView-exported bars
- Optimiser prediction confirmed on-chart to the cent
- Residual error attributed to consolidated vs single-exchange data
- Established the extract-from-chart rule used in later pipelines
Offline optimisation is only useful if the optimiser's numbers survive contact with the chart. This project set out to prove parity before trusting a single sweep result. Run A fed TradingView's own exported hourly SPY bars into a Python replica of a Supertrend strategy: 84 of 84 trades matched with identical entry and exit timestamps, identical fill prices and identical per-trade P&L, and every summary metric agreed exactly. The optimiser's best setting was pushed back to TradingView and its ledger re-read: the predicted net profit matched to the cent with 100 percent identical fills.
Run B used a local one-minute tape from a data vendor aggregated to hourly bars. Trades still numbered 84 but three timestamps and about ten percent of net profit differed. The investigation showed why, and why it is not fixable in code: the chart is a single-exchange feed while the vendor tape is consolidated across all US exchanges, so hundreds of hourly closes differ by a cent or more. The lesson, now applied across other projects, is to extract bars from the chart itself whenever exactness matters.
How it works
- Export the chart's bars and the strategy's trade list
- Replay the strategy in Python on the same bars
- Diff trades, fills and metrics against TradingView
- Sweep parameters offline on the verified engine
- Push the winner to the chart and re-read the ledger
Software and automation are infrastructure, not financial advice. No performance guarantees. Every live system needs staged testing, risk limits, and owner approval.