I use a wave indicator that I find very useful but the signal line is a bit slow.
/Noro
//2017
study(title = Noro's WaveTrend Oscilator v1.0
, shorttitle = WaveTrend 1.0
)
n1 = input(10, Channel Length
)
n2 = input(21, Average Length
)
needbg = input(true, Need background?
)
limitob = input(60, Limit Overbought
)
limitos = input(-60, Limit Oversold
)
ap = hlc3
esa = ema(ap, n1)
d = ema(abs(ap - esa), n1)
ci = (ap - esa) / (0.015 * d)
tci = ema(ci, n2)
plot(limitob, color = red, title = Overbought
)
plot(limitos, color = green, title = Oversold
)
plot(0, color = black, title = 0-line
)
plot(tci, color = green, linewidth = 3, transp = 0, title = WaveTrend
)
//BackGround
up = tci < limitos ? 1 : 0
dn = tci > limitob ? 1 : 0
col = needbg == false ? na : up == 1 ? lime : dn == 1 ? red : na
bgcolor(col, transp = 0)
Now there's a more complex oscilator but i ONY like the EMA/SIGNAL line from this script.
The following code:
//@version=3
study(title=WaveTrend Oscillator [Krypt]
, shorttitle=WT_Krypt
, precision=3)
PI=3.14159265359
dropn(src, n) =>
na(src[n]) ? na : src
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 = 0.0
filt := nz(coeff1 * (src + nz(src[1], src)) + coeff2 * filt[1] + coeff3 * nz(filt[2], filt[1]), src)
// Replaces built-in EMA function for better sensitivity in the beginning
xema(src, len) =>
mult = 2.0 / (len + 1.0)
res = na
res := mult * src + (1.0 - mult) * nz(res[1], src)
EhlersEmaSmoother(sig, smoothK, smoothP) =>
EhlersSuperSmoother(xema(sig, smoothK), smoothP)
// step function (assigns values if series evaluates to True
// and keeps them until a new True result is seen)
step(xs, vals) =>
res = na
res := nz(xs ? vals : res[1], vals)
// try to detect monotonous increase in step function
casc(xs, start, while) =>
res = na
res := abs(nz((start and xs > xs[1] and (not res[1]) and while) ? xs - xs[1] : (xs >= xs[1] and while ? res[1] + xs - xs[1] : 0.0)))
// try to detect monotonous decrease in step function
cdesc(xs, start, while) =>
res = na
res := abs(nz((start and xs < xs[1] and (not res[1]) and while) ? xs[1] - xs : (xs <= xs[1] and while ? res[1] + xs[1] - xs : 0.0)))
findhidden(price, allbottoms, alltops, bottomsteps, topsteps, backtrack) =>
pricebottoms = step(allbottoms, lowest(price, backtrack))
pricetops = step(alltops, highest(price, backtrack))
hbull = sqrt(cdesc(bottomsteps, true, true) * casc(pricebottoms, true, true))
hbear = sqrt(casc(topsteps, true, true) * cdesc(pricetops, true, true))
[hbull / (1.0 + hbear), hbear / (1.0 + hbull)]
n1 = input(10, title=Channel Length
, minval=1)
n2 = input(21, title=Average Length
, minval=1)
smoothing = input(4, title=Signal Smoothing
, minval=0)
maperiod = input(4, title=MA Period
, minval=1)
ob = input(0.75, title=Overbought Level
, minval=0.0)
os = input(-0.75, title=Oversold Level
, maxval=-0.0)
showhist = input(true, title=Histogram
)
showsignals = input(true, title=Buy/Sell Signals
)
src = input(close, type=source, title=Source
)
price = log(dropn(src, 1))
delta = price - xema(price, n1)
d = xema(abs(delta), n1)
ci = ((d == 0) ? 0 : (delta / d))
sig = EhlersEmaSmoother(ci, n2, smoothing)
ma = sma(sig, maperiod)
// create plots
plot(sig, color=#0094ff, style=line, title=Signal
, transp=0)
plot(ma, color=#ff6a00, style=line, title=SMA
, transp=0)
lineBuyBottom = plot(os, color=orange, title=Oversold Level
)
lineSellTop = plot(ob, color=#00bb00, title=Overbought Level
)
lineBuy = plot(series=(sig < os ? sig : os), transp=100, title=n/a
, editable=false)
lineSell = plot(series=(sig > ob ? sig : ob), transp=100, title=n/a
, editable=false)
fill(plot1=lineBuy, plot2=lineBuyBottom, color=orange, transp=50, title=Oversold area
, transp=0)
fill(plot1=lineSellTop, plot2=lineSell, color=#00bb00, transp=50, title=Overbought area
)
plot(showhist ? sig-ma : na, color=sig > ma ? #5fc8ff : #ff9900, style=area, transp=80, title=Histogram
)
// buy/sell signals
midpoint = (ob + os) / 2
exoff = (ob - midpoint) / 7
ploff = (ob - midpoint) / 8
hiddenupper = midpoint + 0.61803398875
hiddenlower = midpoint - 0.61803398875
// filter out false positives by adding sum of signal and MA at last 5 pips
reqpips = 5
sumsig = sum(sig, reqpips)
summa = sum(ma, reqpips)
allbottoms = showsignals and ma < ob and crossover(sig, ma) and sumsig[1] < summa[1]
alltops = showsignals and ma > os and crossunder(sig, ma) and sumsig[1] > summa[1]
// bullish and bearish conditions
bottomsteps = step(allbottoms, ma)
topsteps = step(alltops, ma)
[hiddenbull, hiddenbear] = findhidden(price, allbottoms, alltops, bottomsteps, topsteps, reqpips)
possiblebull = casc(bottomsteps, bottomsteps[1] < os or (hiddenbull[1] > hiddenbear[1]), sig < ob)
possiblebear = cdesc(topsteps, topsteps[1] > ob or (hiddenbear[1] > hiddenbull[1]), sig > os)
bullishtrend = possiblebull / (1.0 + possiblebear)
bearishtrend = possiblebear / (1.0 + possiblebull)
buysignals = allbottoms and ((ma < midpoint and (sig[1] < os - exoff or bullishtrend > hiddenbear)) or (ma < hiddenupper and hiddenbull > bearishtrend))
sellsignals = alltops and ((ma > midpoint and (sig[1] > ob + exoff or bearishtrend > hiddenbull)) or (ma > hiddenlower and hiddenbear > bullishtrend))
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)
Im useless when it comes to coding. I get compiling error's left and right!
Can anyone assist me on taking the EMA/Signal code and adding it into the first script?