Professional Documents
Culture Documents
Script Swing Signal
Script Swing Signal
0 at
https://mozilla.org/MPL/2.0/
// ©budiadanu
//@version=4
study(title="SWING SIGNAL", overlay=true)
smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = ema(abs(x - x[1]), t)
smoothrng = ema(avrng, wper) * m
smoothrng
smrng1 = smoothrng(source, per1, mult1)
smrng2 = smoothrng(source, per2, mult2)
smrng = (smrng1 + smrng2) / 2
// Range Filter
rngfilt(x, r) =>
rngfilt = x
rngfilt := x > nz(rngfilt[1]) ? x - r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x - r
:
x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + r
rngfilt
filt = rngfilt(source, smrng)
upward = 0.0
upward := filt > filt[1] ? nz(upward[1]) + 1 : filt < filt[1] ? 0 : nz(upward[1])
downward = 0.0
downward := filt < filt[1] ? nz(downward[1]) + 1 : filt > filt[1] ? 0 :
nz(downward[1])
longCond = bool(na)
shortCond = bool(na)
longCond := source > filt and source > source[1] and upward > 0 or source > filt
and source < source[1] and upward > 0
shortCond := source < filt and source < source[1] and downward > 0 or source < filt
and source > source[1] and downward > 0
CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]
// Plotting
plotshape(long, title="Beli", text="Beli", style=shape.labelup,
textcolor=color.black, size=size.tiny, location=location.belowbar,
color=color.lime, transp=0)
plotshape(short, title="Jual", text="Jual", style=shape.labeldown,
textcolor=color.white, size=size.tiny, location=location.abovebar, color=color.red,
transp=0)
// Alerts