我在重新粉刷EMA类型指示器,更平滑的过滤器等方面遇到了严重问题,在这种情况下,无论有无安全功能,我都会得到2分钟或2分钟的蜡烛延迟以及类似的冗余;但是,安全功能会导致重新粉刷。但是,我有一个ATR指示器,我在其中添加了安全功能,并且在任何情况下都不会重绘,并且不会滞后两根蜡烛,仅在随后的一根蜡烛上正常开盘,并在确认时关闭。 / p>
```pine-script
//@version=3
// Copyright (c) 2019-present, Alex Orekhov (everget)
// SuperTrend script may be freely distributed under the terms of the GPL-
3.0 license.
study("SuperTrend", overlay=true)
length = input(title="ATR Period", type=integer, defval=22)
mult = input(title="ATR Multiplier", type=float, step=0.1, defval=3.0)
showLabels = input(title="Show Buy/Sell Labels ?", type=bool, defval=true)
src = input(title="Source", type=source, defval=close)
timeFrame = input(title="Other time frame", type=string, defval="3")
atr = 0.0
atr := nz(atr[1]) + (src - (nz(atr[1]) + nz(atr[length])) / 2) / length
////////////
// Retrieve the higher time frame's data
longStopPrev = nz(atr[1], atr)
atr := close[1] > longStopPrev ? max(atr, longStopPrev) : atr
shortStopPrev = nz(atr[1], atr)
atr := close[1] < shortStopPrev ? min(atr, shortStopPrev) : atr
dir = 1
dir := nz(dir[1], dir)
dir := dir == -1 and close > shortStopPrev ? 1 : dir == 1 and close <
longStopPrev ? -1 : dir
longColor = green
shortColor = red
plot(dir == 1 ? atr : na, title="Long Stop", style=linebr, linewidth=2,
color=longColor)
buySignal = dir == 1 and dir[1] == -1
plotshape(buySignal ? atr : na, title="Long Stop Start",
location=location.absolute, style=shape.circle, size=size.tiny,
color=longColor, transp=0)
plotshape(buySignal and showLabels ? atr : na, title="Buy Label",
text="Buy", location=location.bottom, style=shape.labelup, size=size.tiny,
color=longColor, textcolor=white, transp=0)
plot(dir == 1 ? na : atr, title="Short Stop", style=linebr, linewidth=2,
color=shortColor)
sellSignal = dir == -1 and dir[1] == 1
plotshape(sellSignal ? atr : na, title="Short Stop Start",
location=location.absolute, style=shape.circle, size=size.tiny,
color=shortColor, transp=0)
plotshape(sellSignal and showLabels ? atr : na, title="Sell Label",
text="Sell", location=location.top, style=shape.labeldown, size=size.tiny,
color=shortColor, textcolor=white, transp=0)
```