本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=4
// Copyright (c) 2019-present, Franklin Moormann (cheatcountry)
// Ehlers Enhanced Signal To Noise Ratio [CC] script may be freely distributed under the MIT license.
study("Ehlers Enhanced Signal To Noise Ratio [CC]", overlay=false)
f_security(_symbol, _res, _src, _repaint) =>
security(_symbol, _res, _src[_repaint ? 0 : barstate.isrealtime ? 1 : 0])[_repaint ? 0 : barstate.isrealtime ? 0 : 1]
res = input(title="Resolution", type=input.resolution, defval="")
rep = input(title="Allow Repainting?", type=input.bool, defval=false)
bar = input(title="Allow Bar Color Change?", type=input.bool, defval=true)
src = f_security(syminfo.tickerid, res, hl2, rep)
h = f_security(syminfo.tickerid, res, high, rep)
l = f_security(syminfo.tickerid, res, low, rep)
pi = 2 * asin(1)
period = 0.0
smooth = ((4 * src) + (3 * nz(src[1])) + (2 * nz(src[2])) + nz(src[3])) / 10
detrender = ((0.0962 * smooth) + (0.5769 * nz(smooth[2])) - (0.5769 * nz(smooth[4])) - (0.0962 * nz(smooth[6]))) * ((0.075 * nz(period[1])) + 0.54)
q1 = ((0.0962 * detrender) + (0.5769 * nz(detrender[2])) - (0.5769 * nz(detrender[4])) - (0.0962 * nz(detrender[6]))) * ((0.075 * nz(period[1])) + 0.54)
i1 = nz(detrender[3])
jI = ((0.0962 * i1) + (0.5769 * nz(i1[2])) - (0.5769 * nz(i1[4])) - (0.0962 * nz(i1[6]))) * ((0.075 * nz(period[1])) + 0.54)
jQ = ((0.0962 * q1) + (0.5769 * nz(q1[2])) - (0.5769 * nz(q1[4])) - (0.0962 * nz(q1[6]))) * ((0.075 * nz(period[1])) + 0.54)
i2 = i1 - jQ
i2 := (0.2 * i2) + (0.8 * nz(i2[1]))
q2 = q1 + jI
q2 := (0.2 * q2) + (0.8 * nz(q2[1]))
re = (i2 * nz(i2[1])) + (q2 * nz(q2[1]))
re := (0.2 * re) + (0.8 * nz(re[1]))
im = (i2 * nz(q2[1])) - (q2 * nz(i2[1]))
im := (0.2 * im) + (0.8 * nz(im[1]))
period := im != 0 and re != 0 ? 2 * pi / atan(im / re) : 0
period := min(max(period, 0.67 * nz(period[1])), 1.5 * nz(period[1]))
period := min(max(period, 6), 50)
period := (0.2 * period) + (0.8 * nz(period[1]))
smoothPeriod = 0.0
smoothPeriod := (0.33 * period) + (0.67 * nz(smoothPeriod[1]))
q3 = 0.5 * (smooth - nz(smooth[2])) * ((0.1759 * smoothPeriod) + 0.4607)
i3 = 0.0, sp = ceil(smoothPeriod / 2)
for i = 0 to sp - 1
i3 := i3 + nz(q3[i])
i3 := (1.57 * i3) / sp
signal = (i3 * i3) + (q3 * q3)
noise = 0.0
noise := (0.1 * (h - l) * (h - l) * 0.25) + (0.9 * nz(noise[1]))
snr = 0.0
snr := noise != 0 and signal != 0 ? (0.33 * (10 * log(signal / noise) / log(10))) + (0.67 * nz(snr[1])) : 0
hline(6)
sig = src > smooth ? 1 : src < smooth ? -1 : 0
alertcondition(crossover(sig, 0), "Buy Signal", "Bullish Change Detected")
alertcondition(crossunder(sig, 0), "Sell Signal", "Bearish Change Detected")
snrColor = sig > 0 ? color.green : sig < 0 ? color.red : color.black
barcolor(bar ? snrColor : na)
plot(snr, title="SNR", color=snrColor, linewidth=2)