This skill is designed to take raw TradingView PineScript files (
) and rigorously deconstruct them into Python-native components so they can be optimized using vectorization and tools like Optuna.
Use this skill when you want to migrate a backtest from the TradingView ecosystem into a headless Python environment. This is critical for running multi-fold Walk-Forward Analysis (WFA) and Monte Carlo simulations that TradingView cannot handle.
-
Deconstruction & Classification (The IR Build)
- Parse the script to identify , , , and .
- Classify parameters into three buckets:
- Signal: Parameters that dictate entries (e.g., , ).
- Risk: Parameters that dictate exits (e.g., , ).
- Display: Parameters used only for plotting/UI (discard these).
-
Boundary Extraction
- For every Signal and Risk parameter, extract the , , and if provided.
- Format these into Optuna trial suggestions (e.g.,
trial.suggest_int('length', 10, 50)
).
-
Logic Translation
- Translate PineScript technical analysis functions (, , ) into their or equivalents.
- Vectorize the entry and exit conditions. Do not use standard loops over rows unless path-dependency strictly requires it. Use and wherever possible.
-
Hardening & Auditing
- Repaint Risk: Scan the translation for anything relying on the current unclosed bar data. Force the use of for signal generation.
- Division by Zero: Wrap all denominators in a
np.maximum(denominator, 1e-8)
guard to prevent NaN explosions during optimization.