Pine Script

Pine Script – Undeclared identifier ‘green’ / ‘color.green’ – how to fix it?

Pine Script – Undeclared identifier ‘green’ / ‘color.green’ – how to fix it?

You might see the following error in Pine Script quite often, especially if you’re trying to merge a few scripts or copy certain elements from another script. You might see this error with basically all supported colors:

Undeclared identifier `color.red`
Undeclared identifier `color.black`
Undeclared identifier `color.white`
Undeclared identifier 'red'
Undeclared identifier 'black'
Undeclared identifier 'white'

If you see one of these errors, then you have a conflict with Pine Script versions. When Pine Script was updated from v3 to v4, quite a lot of keywords were renamed and colors as well. In v4 and v5, you have to use colors with the prefix “color.”. You can use the following table to see the changes made to built-in color vars:

V3 and beforeV4 and above
aquacolor.aqua
black color.black
blue color.blue
fuchsia color.fuchsia
gray color.gray
green color.green
lime color.lime
maroon color.maroon
navy color.navy
olive color.olive
orange color.orange
purple color.purple
red color.red
silver color.silver
teal color.teal
white color.white
yellow color.yellow

So simply pick the correct variable for your version of Pine Script, and it will be fixed. For example the following will work in v3 and below:

//@version=3
study("My script")
plot(close, color = black)

And the following code works for the v4 and above:

//@version=4
study("My script")
plot(close, color = color.black)

Follow me on TradingView and YouTube.

This image has an empty alt attribute; its file name is wide.png

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Pine Script Programming Courses
Pine Script Programming Courses
Learn to build your own TradingView Indicators and Strategies
Sidebar Signup Form
If you want to be the first in this business, subscribe to the latest news