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

如何在Pine Script v5中按指定RSI条件添加买卖箭头?

Pine Script v5 实现RSI15m箭头信号的具体语法

完整实现代码

//@version=5
indicator("RSI 15min Arrow Signals", overlay=true)

// 自定义RSI长度,可按需修改
rsi_length = 14
// 跨周期获取15分钟K线的RSI值
rsi15m = request.security(syminfo.tickerid, "15", ta.rsi(close, rsi_length))

// 定义信号触发条件
buy_signal = rsi15m > 50
sell_signal = rsi15m < 50

// 在K线下方绘制绿色向上箭头(买入信号)
plotshape(buy_signal, title="Buy", location=location.belowbar,
          color=color.green, style=shape.triangleup, size=size.small)

// 在K线上方绘制红色向下箭头(卖出信号)
plotshape(sell_signal, title="Sell", location=location.abovebar,
          color=color.red, style=shape.triangledown, size=size.small)

// 用你提供的逻辑设置K线颜色
barcolor(rsi15m < 50 ? color.red : color.green)

核心代码说明

  • 跨周期RSI获取:通过request.security函数拉取15分钟周期的RSI数据,参数里的"15"指定目标周期,确保主周期(当前图表周期)≤15分钟才能正常生效。
  • 箭头绘制:使用plotshape函数实现标记,location.belowbar/location.abovebar控制箭头位置,shape.triangleup/shape.triangledown指定箭头样式。
  • K线颜色控制:你提供的三元表达式直接传入barcolor函数,即可实现RSI15m低于50时K线变红、高于50时变绿的效果。

注意点

  • 如果主周期大于15分钟,跨周期数据会被聚合,信号准确性会受影响,建议主周期用1/5/15分钟这类短周期。
  • RSI长度rsi_length可以根据你的策略需求调整默认的14值。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 04:15:03