
等级: 标准版
- 注册:
- 2024-5-6
- 曾用名:
|

楼主 |
发表于 2024-6-3 12:51
|
显示全部楼层
Pine Script(TradingView脚本语言)
//@version=4
study("Stochastic RSI", shorttitle="Stoch RSI", overlay=false)
// 获取用户输入的参数
rsiLength = input(14, title="RSI Length", minval=1)
stochLength = input(14, title="Stochastic Length", minval=1)
smoothK = input(3, title="Smooth K", minval=1)
smoothD = input(3, title="Smooth D", minval=1)
// 计算RSI
rsi = rsi(close, rsiLength)
// 计算Stoch RSI
stochRsi = (rsi - lowest(rsi, stochLength)) / (highest(rsi, stochLength) - lowest(rsi, stochLength))
// 平滑K值和D值
k = sma(stochRsi * 100, smoothK)
d = sma(k, smoothD)
// 绘制Stoch RSI
plot(k, color=color.blue, title="K", linewidth=2)
plot(d, color=color.orange, title="D", linewidth=2)
// 添加超买和超卖水平线
hline(80, "Overbought", color=color.red, linestyle=hline.style_dotted)
hline(20, "Oversold", color=color.green, linestyle=hline.style_dotted)
// 中文解释
/*
1. RSI长度: 计算RSI的周期长度,默认为14。
2. 随机长度: 用于计算Stoch RSI的周期长度,默认为14。
3. 平滑K: K值的平滑周期,默认为3。
4. 平滑D: D值的平滑周期,默认为3。
RSI:相对强弱指标(Relative Strength Index),用于衡量价格的变化速度和变化幅度。
Stoch RSI:随机RSI,是结合了随机指标和RSI的技术指标。
K值和D值:K值是Stoch RSI的平滑结果,D值是K值的平滑结果。
绘图部分:
1. 绘制K值和D值,分别用蓝色和橙色表示。
2. 在80和20位置绘制水平线,用于标记超买和超卖区域。
*/
这是刚收到的代码,可能之前的计算方式有误吧,现在不知道那个是正确的
|
|