Automated parameter optimization for TradingView Pine Script strategies on futures markets (NQ, ES, MNQ). Uses Chrome DevTools Protocol to control TradingView Desktop, run strategy backtests, and find optimal parameters through Bayesian optimization.
+---------------------------+
| TradingView Desktop |
| (CDP / Chrome DevTools) |
+----------+----------------+
|
+----------v----------------+
| TV Bridge (CDP) |
| Set params, read results |
+----------+----------------+
|
+--------------------+--------------------+
| | |
+---------v--------+ +-------v--------+ +---------v--------+
| Bayesian (TPE) | | Grid Search | | Auto-Tune |
| Optuna, 30-50 | | Exhaustive | | Coordinate |
| trials to | | sweep with | | descent, coarse |
| converge | | live TV tester | | then fine sweep |
+------------------+ +----------------+ +------------------+
|
+----------v----------------+
| Self-Learning |
| Drift detection, auto |
| re-optimize, regime-aware |
| param storage, versioning |
+---------------------------+
- Bayesian optimization via Optuna TPE (Tree-structured Parzen Estimator) — converges in ~30-50 trials
- Local Bayesian — runs against Numba engine for sub-second evaluations, then validates top results on TV
- Auto-tune — sequential single-parameter optimization with coarse/fine sweep (coordinate descent)
- Grid search — exhaustive sweep with live TV strategy tester integration
- Composite scoring — 50% reliability (Profit Factor) + 50% profitability (Net Profit), normalized
- Drift detection — monitors live strategy performance vs baseline, alerts on degradation
- Autonomous re-optimization — triggers Bayesian optimization when drift is detected
- Regime-aware parameter storage — stores best params per market regime, suggests switching when regime changes
- Pine Script versioning — bakes optimized params into Pine Script defaults, saves versions with metadata
- Chrome DevTools Protocol integration — reads/writes TradingView Desktop via CDP
- DOM scraping for strategy tester metrics
- Indicator input control — changes Pine Script parameters programmatically
- Pine Script compilation — pushes modified source, compiles, validates
- Streamlit web UI for optimization and results
- MA comparison across multiple moving average types
- Regime distribution analysis with interactive parameter tuning
- One-click apply — push optimized params directly to TradingView
- Strategy library — browse and compare optimization runs
| Component | Technology |
|---|---|
| Optimization | Optuna (Bayesian/TPE), itertools (grid search) |
| Dashboard | Streamlit, Plotly |
| Strategy source | Pine Script v5 (TradingView) |
| TV automation | Chrome DevTools Protocol (CDP) |
| Data storage | SQLite (performance tracking), CSV (OHLCV data) |
| Risk management | JSON rules engine |
pip install -r requirements.txt
# Set up TradingView Desktop with CDP
# Launch TradingView with: --remote-debugging-port=9222
# Set environment variables
export TV_CLI_PATH="/path/to/tradingview-mcp/src/cli/index.js"
export OPTIMIZER_PASSCODE="your-passcode"
# Launch optimizer dashboard
streamlit run app.pyapp.py Main Streamlit app
config.py Instruments, param schemas, input index maps
tv_bridge.py TradingView CDP bridge
core/
bayesian_optimizer.py Optuna-based Bayesian optimization
optimization_engine.py Grid search + TV integration
auto_tune.py Coordinate descent auto-tuning
self_learning.py Drift detection + autonomous re-optimization
regime_params.py Per-regime parameter storage
param_grid.py Parameter grid generation
calibrator.py Backtest vs TV result calibration
versioning.py Pine Script version management
rules.py Risk management rules engine
tabs/
optimizer.py Optimization tab UI
results.py Results viewer tab
self_learning.py Self-learning tab
strategy_library.py Strategy library browser
data_manager.py Data import/export
data/
README.md Data format documentation
MIT