You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pine Script调用fill函数传参报错 无法填充EMA与CMF间区域

问题原因

Pine Script v5 中fill()函数的合法入参是两个绘图对象ID(即plot()、hline()等绘图函数执行后的返回值),不支持直接传入mf、emaf这类数值序列变量作为填充边界,参数类型不匹配就会触发Cannot call 'fill' with argument报错。

修复方案
  1. 给两条曲线的plot()语句添加变量接收返回的绘图对象
  2. 将这两个绘图对象作为参数传入fill()函数,可按需自定义填充颜色、透明度,还可以根据两条线的上下位置设置不同填充色提升辨识度
修正后可运行完整代码
//@version=5
indicator(title="Chaikin Money Flow", shorttitle="CMF", format=format.price, precision=2,
timeframe="", timeframe_gaps=true)
var cumVol = 0.
cumVol += nz(volume)
if barstate.islast and cumVol == 0
    runtime.error("No volume is provided by the data vendor.")
length = input.int(14, minval=1)
ad = close==high and close==low or high==low ? 0 : ((2*close-low-high)/(high-low))*volume
mf = math.sum(ad, length) / math.sum(volume, length)
// 接收CMF曲线的绘图对象
p_mf = plot(mf, color=#43A047, title="MF")
hline(0, color=#787B86, title="Zero", linestyle=hline.style_dashed)
emaf = ta.ema(mf, 14)
// 接收EMA均线的绘图对象
p_emaf = plot(emaf, color=#2962FF, title="CMF EMA")
// 传入两个绘图对象实现区域填充,CMF在均线上方填充淡绿色,下方填充淡红色
fill(p_mf, p_emaf, color=mf > emaf ? color.new(color.green, 90) : color.new(color.red, 90))
补充说明
  • 如果不需要根据多空状态切换填充色,直接给fill()的color参数传入固定半透明色即可,例如color.new(#43A047, 85),不建议使用不透明颜色,避免遮挡曲线本身
  • 填充透明度参数取值范围是0-100,数值越大透明度越高

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.03 02:18:15