You need to enable JavaScript to run this app. Pine Script威廉鳄鱼指标sma函数调用一致性告警问题咨询
优惠活动
大模型
产品
解决方案
定价
更多

Pine Script威廉鳄鱼指标sma函数调用一致性告警问题咨询

TradingView威廉鳄鱼指标sma调用告警消除方案

告警原因

你收到的告警是因为原代码将sma()函数放在三元运算符的分支内,仅在smma[1]为空(即指标首次计算的第一根K线)时才会调用sma(),后续K线计算不会触发sma()执行,不符合Pine Script要求内置指标函数每根K线都执行的一致性规则。

修复后完整代码

//@version=4
study(title="Williams Alligator", shorttitle="Alligator", overlay=true, resolution="")
smma(src, length) =>
    smma =  0.0
    // 提前计算sma值,保证每轮K线计算都调用sma函数
    sma_val = sma(src, length)
    smma := na(smma[1]) ? sma_val : (smma[1] * (length - 1) + src) / length
    smma
jawLength = input(13, minval=1, title="Jaw Length")
teethLength = input(8, minval=1, title="Teeth Length")
lipsLength = input(5, minval=1, title="Lips Length")
jawOffset = input(8, title="Jaw Offset")
teethOffset = input(5, title="Teeth Offset")
lipsOffset = input(3, title="Lips Offset")
jaw = smma(hl2, jawLength)
teeth = smma(hl2, teethLength)
lips = smma(hl2, lipsLength)
plot(jaw, "Jaw", offset = jawOffset, color=#3BB3E4)
plot(teeth, "Teeth", offset = teethOffset, color=#FF006E)
plot(lips, "Lips", offset = lipsOffset, color=#36C711)

修改说明

  • 仅调整了自定义smma函数内部的逻辑,原有指标的计算结果完全不变,不会影响鳄鱼指标的输出数值
  • 把sma()函数的调用从三元运算符分支中提取出来,提前赋值给临时变量sma_val,保证每根K线计算时都会执行一次sma(),直接消除告警

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.20 18:36:04