--> pinefixer: Pine Script v4 vs v5 vs v6: What Changed and How to Migrate
blog

Pine Script v4 vs v5 vs v6: What Changed and How to Migrate


If you're pasting in an old script and getting a wall of errors, there's a good chance it's simply written in an older Pine Script version. Here's what actually changed across v4, v5, and v6, and what to update when migrating.

Always Start With the Version Declaration

Every script needs a version annotation at the very top: //@version=6 (or 5, or 4). This single line tells the compiler which syntax rules to apply — mismatching your code style with your declared version is one of the most common migration headaches.

v4 → v5: The Big Namespace Change

The most disruptive change going from v4 to v5 was moving built-in functions into namespaces. Functions that used to be called directly are now grouped under a prefix:

  • sma(close, 14) became ta.sma(close, 14)
  • security(...) became request.security(...)
  • study(...) became indicator(...)
  • String functions moved under str., array functions under array., math functions under math.

If you're seeing "could not find function or variable" on a function that looks correct, this namespace change is almost always the cause.

v5 → v6: Smaller, More Incremental Changes

The jump to v6 was less disruptive than v4-to-v5, focused more on refinements and new capabilities than renaming existing functions. If a v5 script won't compile as v6, it's more often a genuine bug in the script than a version-syntax mismatch — worth checking your logic before assuming it's a version issue.

A Practical Migration Checklist

  • Update the version annotation at the top to match what you're actually targeting
  • Search for any bare function calls that might need a namespace prefix (sma, ema, rsi, macd, security, study are the usual suspects)
  • Check var and varip declarations — their scoping behavior is consistent from v5 onward, but v4 handled persistent variables differently
  • Re-test any strategy scripts specifically — strategy() parameter defaults have shifted slightly across versions

When in Doubt, Don't Mix Versions

A common mistake is copying half a script from one source (written in v4 style) and pasting it into a script declared as v6. The compiler doesn't auto-detect and convert — it applies v6 rules uniformly, which breaks any leftover v4-style syntax. Pick one version and convert the whole script consistently.

Cleaning up a script during migration?

Run it through the free Pine Script Formatter after updating syntax — it normalizes indentation and spacing so leftover formatting quirks from the old version don't linger.

Open the Formatter →