Pine Script v6: What Changed From v5 and How to Convert Your Indicator
TradingView released Pine Script v6 in December 2024. Most v5 indicators convert with one click, but a few changes alter how existing code behaves, especially around booleans, integer division and strategies. Here is what changed, what breaks, and how to convert.
How to convert a script to v6
Open the script in the Pine Editor, open the Manage script menu and choose Convert code to v6. The script must compile in v5 first. The converter fixes many changes automatically; others need a manual fix, which is what the rest of this guide covers. The first line becomes //@version=6.
The changes that break v5 code
- No implicit cast to bool: an
intorfloatno longer works as a condition by itself. Writebool(bar_index)or a real comparison such asx != 0. - Booleans can't be
na: a bool is always true or false, andna(),nz()andfixnan()no longer accept bool arguments. - Lazy
and/or: the second condition is only evaluated when it's needed to decide the result. If you relied on a function call inside the second condition running on every bar (for example ata.*function), move it to its own line first. - Integer division: dividing two integers that don't divide evenly now returns a fraction even for constants:
5/2is 2.5, not 2. Wrap it inint(),math.floor()ormath.round()if you need a whole number. - Dynamic requests by default:
request.*()calls can run inside loops and conditional blocks. You can turn this off withdynamic_requests = falsein the declaration. timeframe.periodalways has a multiplier: it returns "1D" instead of "D", so comparisons with "D" stop matching.- Removed parameters:
transpis gone (use colors with transparency, such ascolor.new()) and the minimumlinewidthis 1. - Some default colors changed: for example
color.red,color.tealandcolor.yellowhave new values, and the default label text color is now white.
Strategy changes
- The
whenparameter is removed fromstrategy.entry(),strategy.exit(),strategy.close()and the other order functions. Put the call inside anifblock instead. - The default
margin_longandmargin_shortare now 100. Set them to 0 to reproduce v5 results. - Instead of failing when a strategy passes 9,000 orders, v6 trims the oldest orders.
What's new
- Bold and italic text in labels, boxes and tables with
text_formatting = text.format_bold(ortext.format_italic, or both added together). - Negative array indices:
array.get(a, -1)returns the last element.
Running v6 indicators outside TradingView
TQ Charts, which draws charts from your NinjaTrader data, runs Pine Script indicators that you paste in, and reads the //@version line: v6 code uses v6 integer division and v5 code keeps the old behaviour. It accepts the text_formatting parameter and request.security() on higher timeframes of the same symbol. Strategies (strategy()) are not supported, only indicators. See Pine Script indicators outside TradingView, or converting Pine Script to NinjaTrader if you need it inside NinjaTrader itself.
FAQ
When was Pine Script v6 released?
TradingView announced Pine Script v6 on December 10, 2024.
How do I convert Pine Script v5 to v6?
In the Pine Editor, open Manage script and choose Convert code to v6. The v5 script has to compile first, and some changes need manual fixes.
Why does my indicator behave differently after converting to v6?
Usually because of lazy and/or evaluation, integer division returning fractions, or timeframe.period returning "1D" instead of "D".