Ehlers-Smoothed Stochastic RSI [Krypt]

fskrypt · study · 52 行 · 点赞 2,014 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

study(title="Ehlers-Smoothed Stochastic RSI [Krypt]", shorttitle="ES Stoch RSI [Krypt]", precision=1)
 
PI = 3.14159265359
 
EhlersSuperSmoother(src, lower, defval) =>
	a1 = exp(-PI * sqrt(2) / lower)
	coeff2 = 2 * a1 * cos(sqrt(2) * PI / lower)
	coeff3 = -pow(a1, 2)
	coeff1 = (1 - coeff2 - coeff3) / 2
	filt = nz(coeff1 * (src + nz(src[1], src)) + coeff2 * filt[1] + coeff3 * filt[2], defval)
	filt
 
Stochastic(src, length, defval) =>
    rawsig = nz(stoch(src, src, src, length), defval)
    sig = min(max(rawsig, 0), 100)
    sig
 
smoothK = input(10, minval=1, title="K")
smoothD = input(3, minval=1, title="D")
lengthRSI = input(14, minval=1, title="RSI Length")
lengthStoch = input(14, minval=1, title="Stochastic Length")
showsignals = input(true, title="Buy/Sell Signals")
 
ob = 80
os = 20
midpoint = 50
 
price = log(close) //0.25 * log(high) + 0.25 * log(low) + 0.5 * log(close)
rsi1 = rsi(price, lengthRSI)
rawsig = Stochastic(rsi1, lengthStoch, 50)
sig = EhlersSuperSmoother(rawsig, smoothK, 50)
ma = sma(sig, smoothD)
 
plot(sig, color=blue, title="K")
plot(ma, color=red, title="D")
lineOB = hline(ob, title="Upper Band")
lineOS = hline(os, title="Lower Band")
fill(lineOB, lineOS, color=purple, title="Background")
 
// Buy/Sell Signals
 
// use curvature information to filter out some false positives
mm1 = change(change(ma, 1), 1)
mm2 = change(change(ma, 2), 2)
ms1 = change(change(sig, 1), 1)
ms2 = change(change(sig, 2), 2)
 
sellsignals = showsignals and (mm1 + ms1 < 0 and mm2 + ms2 < 0) and crossunder(sig, ma) and sig[1] > midpoint
buysignals = showsignals and (mm1 + ms1 > 0 and mm2 + ms2 > 0) and crossover(sig, ma) and sig[1] < midpoint
 
plot(buysignals ? sig[1] - 4: na, style=circles, color=red, linewidth=3, title="Buy Signal")
plot(sellsignals ? sig[1] + 4: na, style=circles, color=blue, linewidth=3, title="Sell Signal")

← 返回列表