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

Pine Script部分数据绘图失败求助(附脚本及截图)

问题解决:Pine Script部分数据无法绘制

核心问题分析

  1. gainlossspread无法绘制:meangain仅在K线收阳(Up=close>open)时计算,meanloss仅在K线收阴(Down=close<open)时计算,其余时间两者均为na。当其中一个值为na时,meangain-meanloss的结果也会是na,最终导致gainlossspread大部分时间无有效值,无法连续绘制。
  2. 注释的RSI无法绘制:公式存在语法与逻辑错误,100/1-RS的写法既缺少必要括号,也不符合标准RSI的计算逻辑。

修改后的代码

//@version=5
indicator("Gain Loss Spread", shorttitle = "GLS")
Up = close > open
Down = close < open
int datapoints = input.int(defval = 3, title="待检查数据点总数", minval = 1, maxval = 512)

// 移除条件判断,确保每个周期都能计算有效值
meangain = ta.sma((close[datapoints] + ta.change(close, datapoints)), datapoints)
meanloss = ta.sma((close[datapoints] - ta.change(close, datapoints)), datapoints)

meanpopulation = ta.sma(close, datapoints)

gainlossspread = (meangain - meanloss) + close

// 修正RSI公式的语法与逻辑
RS = meangain / meanloss
RSI = 100 - (100 / (1 + RS))

plot(meangain, color = color.green)
plot(meanloss, color = color.red)
plot(gainlossspread, color = color.blue, style = plot.style_circles)
plot(meanpopulation, color = color.aqua, linewidth = 2)
plot(RSI, color = color.purple)

关键修改说明

  • 去掉meangain和meanloss的条件判断,保证每个K线周期都能生成有效值,避免na导致绘制中断。
  • 调整RSI公式的括号位置与计算逻辑,匹配标准RSI的计算规则。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 00:52:15