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

Pine Script多币种RSI组合指标逻辑异常排查求助

问题排查与解决方案

核心逻辑错误分析

你的中间线颜色判断存在两个关键问题:

  1. 连续周期判断逻辑偏差
    你用rmaAVG_rising[1] and rmaAVG_rising[2]判断底部线连续上涨,但ta.rising(rmaAVG, 1)仅验证当前周期相对前一周期的上涨状态,因此rmaAVG_rising[1]是前一周期的上涨结果,rmaAVG_rising[2]是更早周期的状态——这实际是在判断“前两个历史周期连续上涨”,而非你需要的“底部线连续2个周期(包含当前显示周期)上涨”。若更早周期曾上涨,会导致底部线仅1个周期变色时,中间线误触发。

  2. 顶部线同方向条件范围过窄
    你仅用rsiSymbol_rising[1]判断顶部线状态,只覆盖了前一周期,不符合“至少1个周期同方向”的需求——若当前周期顶部线上涨但前一周期没涨,会被错误排除。

修正后的代码实现

//@version=5
indicator("Multi-Currency RSI Combo Indicator", overlay=false)

// 获取BTC和ETH的收盘价与RSI
close_btc = request.security(ticker.standard("binance:btcusdt"), timeframe.period, close)
close_eth = request.security("BINANCE:ETHUSDT", timeframe.period, close)
rsi_btc = ta.rsi(close_btc, 14)
rsi_eth = ta.rsi(close_eth, 14)

// 计算BTC&ETH的RSI均值及其RMA(底部线)
rsiAVG = (rsi_btc + rsi_eth) / 2
rmaAVG = ta.rma(rsiAVG, 14)
// 直接用ta.rising/falling判断连续2个周期上涨/下跌
rmaAVG_cont_rising = ta.rising(rmaAVG, 2)
rmaAVG_cont_falling = ta.falling(rmaAVG, 2)

// 当前标的RSI及其RMA(顶部线)
rsi_current = ta.rsi(close, 14)
rsiSymbol_rma = ta.rma(rsi_current, 14)
// 覆盖当前+前一周期,满足“至少1个周期同方向”需求
rsiSymbol_any_rising = ta.rising(rsiSymbol_rma, 1) or ta.rising(rsiSymbol_rma, 1)[1]
rsiSymbol_any_falling = ta.falling(rsiSymbol_rma, 1) or ta.falling(rsiSymbol_rma, 1)[1]

// 顶部线颜色逻辑
rsiSymbol_color = ta.rising(rsiSymbol_rma, 1)[1] ? color.green : ta.falling(rsiSymbol_rma, 1)[1] ? color.red : color.blue
plot(2, "RMA_Symbol_RSI", rsiSymbol_color, 2)

// 底部线颜色逻辑
rmaAVG_color = ta.rising(rmaAVG, 1)[1] ? color.green : ta.falling(rmaAVG, 1)[1] ? color.red : color.blue
plot(0, "RMA_Average_RSI", rmaAVG_color, 2)

// 中间线颜色逻辑(修正后)
rmaFiltered_color = if rmaAVG_cont_rising and rsiSymbol_any_rising
    color.green
elif rmaAVG_cont_falling and rsiSymbol_any_falling
    color.red
else
    color.blue

plot(1, "RMA_AVG_RSI_COMPARE", rmaFiltered_color, 2)

关键优化说明

  • 用ta.rising(src, 2)简化连续周期判断:该函数自动验证src > src[1] and src[1] > src[2],避免手动索引导致的逻辑混乱,确保只有底部线连续两个周期上涨时才触发条件。
  • 扩大顶部线判断范围:用当前周期状态 or 前一周期状态覆盖“至少1个周期同方向”的需求。
  • 改用if-elif-else结构:提升代码可读性,避免嵌套三元运算符的优先级陷阱。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 00:30:26