本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=3
study("NoHesi EMA by PeterO", overlay=true)
nohesi(osc,hesit) => //Hesitation Smoothing function - can be applied to any data series
nohesi_peak=na
nohesi_bottom=na
nohesi_peak := osc > nohesi_peak[1] ? osc : osc < nohesi_bottom[1] ? osc + hesit : nz(nohesi_peak[1])
nohesi_bottom := osc < nohesi_bottom[1] ? osc : osc > nohesi_peak[1] ? osc - hesit : nz(nohesi_bottom[1])
OscUp = nohesi_peak>nohesi_peak[1]
OscDn = nohesi_bottom<nohesi_bottom[1]
OscHesi = not OscUp and not OscDn
OscNoHesi = na
OscNoHesi:= OscUp or OscDn ? osc : OscNoHesi[1]
length=input(230, title='EMA Length')
src=input(close)
hesitation=input(0.0001, title='EMA Hesitation to ignore')
ema_nohesi=nohesi(ema(src,length),hesitation)
ematrend=na
ematrend:=nz(ematrend[1])
if rising(ema_nohesi,1)
ematrend:=1
if falling(ema_nohesi,1)
ematrend:=-1
emacolor=ematrend==1 ? lime : red
plot(ema_nohesi, color=emacolor, linewidth=3)
plotshape(not rising(ema_nohesi,1) and not falling(ema_nohesi,1) and rising(ema(src,length),1) ? ema_nohesi + 2*hesitation : na, style=shape.arrowdown, size=size.tiny, color=blue, transp=90, location=location.absolute, title='EMA would be in uptrend if not for NoHesi')
plotshape(not rising(ema_nohesi,1) and not falling(ema_nohesi,1) and falling(ema(src,length),1) ? ema_nohesi - 2*hesitation : na, style=shape.arrowup, size=size.tiny, color=blue, transp=90, location=location.absolute, title='EMA would be in downtrend if not for NoHesi')