PineScript v4 vs v5 vs v6 — Differences and Migration Guide
Old TradingView scripts are still around in three generations. This guide shows what changed between v4, v5 and v6, with the same script in each version and the errors that appear when you migrate.
Use PineScript v6 for new scripts. v5 introduced namespaced functions (ta.*, math.*, request.*) and indicator() in place of study(); v6 added stricter boolean handling, dynamic data requests and removed older arguments such as the when parameter of strategy.entry(). Older v4 and v5 scripts keep running on TradingView, so you can maintain them as they are or migrate them one version at a time and verify that signals stay identical.
The same script in three versions
The simplest way to see the differences is to read the same idea in each version.
//@version=4
study("SMA cross", overlay=true)
len = input(14, "Length", type=input.integer)
fast = sma(close, len)
slow = sma(close, len * 2)
plot(fast)
plot(slow)
htfClose = security(syminfo.tickerid, "D", close)
//@version=5
indicator("SMA cross", overlay=true)
len = input.int(14, "Length")
fast = ta.sma(close, len)
slow = ta.sma(close, len * 2)
plot(fast)
plot(slow)
htfClose = request.security(syminfo.tickerid, "D", close)
//@version=6
strategy("SMA cross", overlay=true)
len = input.int(14, "Length")
fast = ta.sma(close, len)
slow = ta.sma(close, len * 2)
// v6: conditions must be real booleans; no implicit number-to-bool casts
bool crossUp = ta.crossover(fast, slow)
// v6: the old `when=` argument of strategy.entry() is gone, use an if block
if crossUp
strategy.entry("Long", strategy.long)
v4 → v5: namespaces and a new header
study()becameindicator().- Built-in functions moved into namespaces:
sma()→ta.sma(),rsi()→ta.rsi(),tostring()→str.tostring(). security()becamerequest.security().input(type=input.integer)was replaced by typed inputs such asinput.int(),input.float()andinput.bool().- Libraries and exported functions were added, so shared code can be reused across scripts.
Most v4 → v5 work is mechanical renaming, which is why converters get you most of the way there.
v5 → v6: stricter and more predictable
- Booleans are strict. A
boolcan no longer bena, and numbers are not silently cast to booleans, soif myIntmust be written asif myInt != 0. - Dynamic requests.
request.*()calls can take series string arguments, so one script can scan several symbols or timeframes. - Removed arguments. The
whenargument ofstrategy.*order functions was removed in favour of ordinaryifblocks. - Lazy evaluation.
andandornow short-circuit, which can change behaviour in scripts that relied on both sides always running. - Better debugging. New
log.info(),log.warning()andlog.error()functions write to the Pine Logs panel.
Common errors when migrating
- Cannot use “series int” as a condition (or similar): an implicit number-to-boolean cast that v6 rejects.
- A strategy that suddenly places no trades after conversion because the removed
whenargument was silently dropped instead of rewritten. - Different results because short-circuit evaluation skipped a function call that had side effects, such as building a series that other code relied on.
- Signals that shift by one bar after migration; always compare old and new versions bar by bar on the same chart.
Which version should you use?
- New scripts: v6, the current version, which receives new language features.
- Working v4 or v5 scripts: there is no need to migrate unless you need a newer feature, want to combine them with v6 code, or plan to hand the code to someone else.
- Converting to MQL4/MQL5: the source version matters less than clean logic, but older versions often hide repainting and look-ahead behaviour that must be found before conversion.
ExpertNevees works with PineScript v4, v5 and v6, including migration between versions and conversion to MetaTrader. See the PineScript guide and the conversion service.
Frequently Asked Questions
Which PineScript version should I use?
Use v6 for new scripts. v5 and v4 scripts still run on TradingView, so you can keep them as they are unless you need newer features.
What changed between PineScript v5 and v6?
v6 made booleans strict (no na, no implicit number-to-boolean casts), allowed dynamic data requests, removed the when argument of strategy order functions and made and/or short-circuit. It also added log.info(), log.warning() and log.error() for debugging.
Can old v4 scripts be converted automatically?
Converters handle most of the renaming into namespaces, such as sma() to ta.sma(). Every converted script should still be checked bar by bar against the original, because small behaviour changes can shift signals.
Need a Script Migrated or Built in PineScript?
Send your script or idea on Telegram or use the contact form. The initial consultation is free.