Convert Pine Script to v5 or v6
Upgrade a Pine Script from v3 or v4 to v5, or from v5 to v6, using TradingView's converter and version-specific checks.
Use TradingView’s Pine Editor to upgrade a script one version at a time. This guide keeps the original v5 conversion steps and adds the path from v5 to v6.
Looking to connect a script to PineConnector? Version conversion does not add trading alerts. Use Connect a Pine Script to PineConnector for that task.
Before converting
Section titled “Before converting”Save a separate copy of your original script. Check its //@version= declaration and confirm it compiles before starting. You need access to editable source code; ask the author for an updated version if the code is protected.
| Starting version | Upgrade path |
|---|---|
| v5 | v5 → v6, if you need to migrate |
| v4 | v4 → v5, then optionally v6 |
| v3 | v3 → v4 → v5, then optionally v6 |
| v1, v2, or no version declaration | Review the older migration guides before using the converter |
TradingView’s migration overview describes the editor converter and its compilation requirement.
Convert v4 to v5
Section titled “Convert v4 to v5”- Open your v4 script in Pine Editor and fix any existing compilation errors.
- Open the editor’s Manage script menu and select the conversion option for v5.
- Review the result, resolve any highlighted errors, and save the converted copy.
The v5 migration guide covers common changes, including study() becoming indicator() and technical-analysis functions moving into the ta. namespace. Changing only the version declaration does not make those changes for you.
Convert v3 to v5
Section titled “Convert v3 to v5”Convert to v4 first. Resolve errors and save that version before repeating the process for v5. Use TradingView’s v4 migration guide for the first step, then follow the v4-to-v5 steps above.
Version 1, version 2, or no version declaration
Section titled “Version 1, version 2, or no version declaration”The automatic converter starts with v3 scripts. For older code, work through the relevant migration guides or ask the script’s author to update it. Do not relabel an older script as v3 or v5 and assume its logic has migrated.
Convert v5 to v6
Section titled “Convert v5 to v6”With a compiling v5 copy open, choose Manage script → Convert code to v6. Resolve errors and save a separate copy.
Review the v6 migration guide even if conversion succeeds. Changes to boolean evaluation, strategy margin defaults and exit handling can affect behaviour. A successful compilation does not prove that the converted script produces the same signals or simulated trades.
Check the result before reconnecting alerts
Section titled “Check the result before reconnecting alerts”- Compare the original and converted scripts on the same symbol, timeframe, inputs and chart history.
- Check entries, exits, position size and alert timing. Investigate differences before using the converted script for automation.
- If the script already sends PineConnector messages, check that its License ID, broker symbol and sizing remain intentional.
Use the demo verification guide to check the connection, then observe a new real-time event from the converted script. Follow that event’s message through TradingView, PineConnector and the intended broker account. Check symbol, direction, volume and any unexpected duplicate. A successful temporary test alert does not verify the converted script’s behaviour. For adding messages to source code, continue to Add alerts to your script.
