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 before | V4 and above |
aqua | color.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.