You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

从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 (like color(color.red) or color(color.red, 50)) to define base colors or semi-transparent ones.
  • In V4, this syntax was retired. Instead:
    • Native color constants like color.red are already valid color values—you don’t need to wrap them in an extra color() 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).

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 around color.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

火山引擎 最新活动