从V2迁移至V4时出现Too much arguments错误的原因排查求助
Fixing "Too much arguments converting from V2 to V4" in Pine Script
I’ve run into this exact snag when migrating Pine Script code from V2 to V4—let’s break down what’s going wrong and how to fix it quickly.
The Root Cause
Your error comes from a breaking change in how Pine Script handles color definitions between versions:
- In V2, you could use the
color()function with 1 or 2 arguments (likecolor(color.red)orcolor(color.red, 50)) to define base colors or semi-transparent ones. - In V4, this syntax was retired. Instead:
- Native color constants like
color.redare already validcolorvalues—you don’t need to wrap them in an extracolor()call. - To create a color with transparency, you must use the
color.new()function (note: the second argument here is transparency, where 0 = fully opaque and 100 = fully transparent).
- Native color constants like
Fixed Code
Swap your original line with this corrected version:
colors = cond1 ? color.red : cond2 ? color.new(color.aqua, 50) : color.new(color.red, 50)
Why This Works
- We remove the redundant
color()wrapper aroundcolor.red(since it’s already a valid color value in V4). - We use
color.new()for the semi-transparent colors, which matches V4’s required API syntax. - This eliminates the "too many arguments" error because we’re now using the function signatures that V4 expects.
内容的提问来源于stack exchange,提问作者Fernando Caldas




