如何在当前时间框架下计算并同图绘制更低时间框架的RSI?
解决方法
直接对request.security_lower_tf返回的RSI数组计算平均值,再用plot函数绘制即可,具体实现如下:
完整代码示例
//@version=5 indicator("双周期RSI同图展示", overlay=false) // 当前时间框架RSI current_rsi = ta.rsi(close, 14) plot(current_rsi, color=color.blue, title="当前周期RSI") // 更低时间框架(60分钟)RSI数组,并计算平均值 lower_tf_rsi_array = request.security_lower_tf(syminfo.tickerid, "60", ta.rsi(close, 14)) lower_tf_rsi_avg = ta.mean(lower_tf_rsi_array) // 绘制低周期RSI平均值 plot(lower_tf_rsi_avg, color=color.red, title="60分钟RSI平均值", style=plot.style_circles)
关键说明
ta.mean(lower_tf_rsi_array):直接对低周期RSI数组计算算术平均值,得到当前K线对应的低周期RSI平均数值- 通过设置不同
color和style可以区分两条曲线,方便观察对比 - 如果需要其他统计值(比如中位数、最大值),可以替换
ta.mean为ta.median、ta.highest等对应函数
内容的提问来源于stack exchange,提问作者sey eeet
相关产品推荐
相关产品推荐

