You need to enable JavaScript to run this app. 如何修复Pine Script中「无法以对应参数调用rma」的报错
优惠活动
大模型
产品
解决方案
定价
更多

如何修复Pine Script中「无法以对应参数调用rma」的报错

Pine Script 累积/派发指标多空判断逻辑编译报错修复

问题背景

开发Pine Script量化策略时,计划将累积/派发(A/D)指标的零轴位置作为多空开仓的指标确认条件,编写对应判断逻辑时触发连续编译报错,策略无法正常运行。

原始问题代码

Ind_Conf_2_Check = input(true, title = "Indicator 2 - C2)
len = input(14, minval = 1, title="A/D Length")          // EMA27 = SMMA/RMA14 - lunar month
price_enable = input(true, title="factor price (=money flow)")
AD_weight = input(0.0, minval=0.0, maxval=1.0, step=0.5, title="A/D weight (at 1 all volume is included)
AD_ratio = nz(change(close) / tr(true))         // 'True Range' fixes issues caused by gaps in price
AD_ratio := (1 - AD_weight) * AD_ratio + sign(AD_ratio) * AD_weight
trl = min(low, close[1])
trh = max(high, close[1])
vol = if price_enable
    volume * hlc3
 else
    volume 

plot(rma(vol * AD_ratio, len), style=plot.style_line, color=#4477ffff, title="A/D Money Flow")
hline(0, color=color.black, linestyle=hline.style_dotted, title="Zero line")
Ind_Conf_2_l = Ind_Conf_2_Check ? rma(vol * AD_ratio) > 0 ? true : false : false
Ind_Conf_2_s = Ind_Conf_2_Check ? rma(vol * AD_ratio) < 0 ? true : false : false

系统返回的编译报错信息

LINE 16: Cannot call 'rma' with arguments (series[float]); available overloads: rma(series[float], integer) => series[float];
LINE 17: Cannot call 'rma' with arguments (series[float]); available overloads: RMA(series[float], integer) => series[float];

问题根因

Pine Script 内置的rma()(Wilder平滑移动平均)存在强制参数规则:必须传入两个必填参数,第一个是需要做平滑计算的浮点序列,第二个是计算平滑周期的整数值。
原代码在第16、17行编写多空判断逻辑时,调用rma()仅传入了vol * AD_ratio作为第一个参数,漏掉了提前定义好的周期变量len,导致编译器无法匹配对应的函数重载规则,触发编译错误。
除此之外原代码还存在两处隐性语法问题,即使修复rma参数问题也可能触发后续报错:

  • 第1行input的title字符串闭合错误,右括号被误写到引号内部,书写为title = "Indicator 2 - C2),字符串没有正确闭合
  • 第4行的input语句末尾缺少右括号,完整的input方法没有正确闭合

修复方案

  • 修正两处语法书写错误:调整第1行的引号位置、补全第4行input的闭合括号
  • 优化代码运行效率:将已计算完成的A/D指标序列单独存储为变量,避免在多空判断行重复调用rma()造成的无效资源消耗
  • 多空判断逻辑直接复用提前计算好的指标序列,无需重复调用内置函数

修正后可正常编译运行的核心代码片段:

// 单独存储计算完成的A/D指标线
ad_line = rma(vol * AD_ratio, len)

plot(ad_line, style=plot.style_line, color=#4477ffff, title="A/D Money Flow")
hline(0, color=color.black, linestyle=hline.style_dotted, title="Zero line")

// 基于已存储的指标线做多空判断
Ind_Conf_2_l = Ind_Conf_2_Check ? ad_line > 0 : false
Ind_Conf_2_s = Ind_Conf_2_Check ? ad_line < 0 : false

内容的提问来源于stack exchange,提问作者Rodrigo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.29 08:15:07