Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
142 views2 pages

STORSI Smoothed

Download as txt, pdf, or txt
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 2

//@version=3

study(title="Smoothed Stochastic RSI [Krypt]", shorttitle="ES Stoch RSI [Krypt]",


precision=1)

PI = 3.14159265359

drop1st(src) =>
x = na
x := na(src[1]) ? na : src

xlowest(src, len) =>


x = src
for i = 1 to len - 1
v = src[i]
if (na(v))
break
x := min(x, v)
x

xhighest(src, len) =>


x = src
for i = 1 to len - 1
v = src[i]
if (na(v))
break
x := max(x, v)
x

xstoch(c, h, l, len) =>


xlow = xlowest(l, len)
xhigh = xhighest(h, len)
100 * (c - xlow) / (xhigh - xlow)

Stochastic(c, h, l, length) =>


rawsig = xstoch(c, h, l, length)
min(max(rawsig, 0.0), 100.0)

xrma(src, len) =>


sum = na
sum := (src + (len - 1) * nz(sum[1], src)) / len

xrsi(src, len) =>


msig = nz(change(src, 1), 0.0)
up = xrma(max(msig, 0.0), len)
dn = xrma(max(-msig, 0.0), len)
rs = up / dn
100.0 - 100.0 / (1.0 + rs)

EhlersSuperSmoother(src, lower) =>


a1 = exp(-PI * sqrt(2) / lower)
coeff2 = 2 * a1 * cos(sqrt(2) * PI / lower)
coeff3 = -pow(a1, 2)
coeff1 = (1 - coeff2 - coeff3) / 2
filt = na
filt := nz(coeff1 * (src + nz(src[1], src)) + coeff2 * filt[1] + coeff3 *
filt[2], src)

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")
src = input(close, type=source, title="Source")

ob = 80
os = 20
midpoint = 50

price = log(drop1st(src))
rsi1 = xrsi(price, lengthRSI)
rawsig = Stochastic(rsi1, rsi1, rsi1, lengthStoch)
sig = EhlersSuperSmoother(rawsig, smoothK)
ma = sma(sig, smoothD)

plot(sig, color=#0094ff, title="K", transp=0)


plot(ma, color=#ff6a00, title="D", transp=0)
lineOB = hline(ob, title="Upper Band", color=#c0c0c0)
lineOS = hline(os, title="Lower Band", color=#c0c0c0)
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

ploff = 4
plot(buysignals ? sig[1] - ploff : na, style=circles, color=#008fff, linewidth=3,
title="Buy Signal", transp=0)
plot(sellsignals ? sig[1] + ploff : na, style=circles, color=#ff0000, linewidth=3,
title="Sell Signal", transp=0)

You might also like