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

请将Version 2版SuperTrend ATR + RSI指标代码转换为Version 5版

SuperTrend ATR + RSI 指标:Pine Script v2 转 v5 完整实现

以下是完全保留原指标逻辑、参数设置及绘图规则的Pine Script v5版本代码:

//@version=5
indicator(title = "SuperTrend ATR + RSI", shorttitle = "SuperTrend ATR + RSI", overlay = true)

// 参数设置
Factor = input.int(title="Super Trend", defval=3, minval=1, maxval=100)
ATR_Period = input.int(title="ATR", defval=7, minval=1, maxval=100)
RSI_Period = input.int(title="RSI", defval=7, minval=1, maxval=100)

// Super Trend ATR 计算
Up = hl2 - (Factor * ta.atr(ATR_Period))
Dn = hl2 + (Factor * ta.atr(ATR_Period))

TUp = close[1] > TUp[1] ? math.max(Up, TUp[1]) : Up
TDown = close[1] < TDown[1] ? math.min(Dn, TDown[1]) : Dn

Trend = close > TDown[1] ? 1 : close < TUp[1] ? -1 : nz(Trend[1], 1)
Tsl = Trend == 1 ? TUp : TDown

linecolor = Trend == 1 ? color.green : color.red

// RSI 相关计算
src = close
ep = 2 * RSI_Period - 1
auc = ta.ema(math.max(src - src[1], 0), ep)
adc = ta.ema(math.max(src[1] - src, 0), ep)

x1 = (RSI_Period - 1) * (adc * 70 / (100 - 70) - auc)
ub = ta.iff(x1 >= 0, src + x1, src + x1 * (100 - 70) / 70)

x2 = (RSI_Period - 1) * (adc * 30 / (100 - 30) - auc)
lb = ta.iff(x2 >= 0, src + x2, src + x2 * (100 - 30) / 30)

// 绘图
plot(ta.avg(ub, lb), color=color.purple, style=plot.style_line, linewidth=1, title="RSI")
plot(Tsl, color=linecolor, style=plot.style_line, linewidth=1, title="SuperTrend ATR")

转换关键说明

  • 替换v2的study()为v5标准的indicator(),保持标题、短标题及叠加属性不变
  • 输入参数改用input.int()明确类型,原参数的默认值、范围完全保留
  • 适配v5命名空间规则:技术分析函数(atr/ema/iff/avg)添加ta.前缀,数学函数(max/min)添加math.前缀
  • 移除原代码中语法错误的多余逗号(src = close,末尾的逗号)
  • 颜色设置直接使用v5内置的color.green/color.red/color.purple,与原v2行为一致
  • 所有核心计算逻辑、趋势判断规则、绘图样式均未修改,确保指标表现与原v2版本完全一致

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 19:27:24