微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Tradingview Pine Script 帮助 - 如何不重复触发警报

如何解决Tradingview Pine Script 帮助 - 如何不重复触发警报

我对下面的代码有疑问。显然,这段代码在图表上给出了买入/卖出图形状,但它给出了太多重复的形状(多个买入信号或连续卖出信号)。我想让它只显示一次。

这是当前代码图片

enter image description here

我希望它看起来像:

enter image description here

以下是我使用的代码

//@version=3
study(title="Money miner - Trailing Profit/Stoploss - Buy/Sell",overlay = true)

////////////////////////////////////////////////////////////////////////////////INPUTS

nATRPeriod = input(21,"Period")
nATRMultip = input(6.3,"Multiplier",type=float,minval=0.5,maxval=1000,step=0.1)

/////////////////////////////////////////////////////////////////////////////////ATR

xATR = atr(nATRPeriod)
nLoss = nATRMultip * xATR
xATRTrailingStop = na
xATRTrailingStop := iff(close > nz(xATRTrailingStop[1],0) and close[1] > nz(xATRTrailingStop[1],0),max(nz(xATRTrailingStop[1]),close - nLoss),iff(close < nz(xATRTrailingStop[1],0) and close[1] < nz(xATRTrailingStop[1],min(nz(xATRTrailingStop[1]),close + nLoss),iff(close > nz(xATRTrailingStop[1],close - nLoss,close + nLoss)))
 

pos = na
pos := iff(close[1] < nz(xATRTrailingStop[1],0) and close > nz(xATRTrailingStop[1],1,iff(close[1] > nz(xATRTrailingStop[1],0) and close < nz(xATRTrailingStop[1],-1,nz(pos[1],0)))

color = pos == -1 ? red: pos == 1 ? lime : blue
//patr=plot(xATRTrailingStop,color=color,linewidth=2,title="ATR Trailing Stop",transp=0)

// Deternine if we are currently LONG
isLong = false
isLong := nz(isLong,false)

// Determine if we are currently SHORT
isShort = false
isShort := nz(isShort,false)

//Trading
// Buy only if the buy signal is triggered and we are not already long
LONG = not isLong and pos == 1

// Sell only if the sell signal is triggered and we are not already short
SHORT = not isShort and pos == -1

if (LONG)
    isLong := true
    isShort := false

if (SHORT)
    isLong := false
    isShort := true

barcolor(isLong ? lime : isShort ? red : na)

// Show Break Alerts
plotshape(SHORT,title="Sell",style=shape.labeldown,location=location.abovebar,size=size.normal,text="Sell",transp=0,textcolor = white,color=red,transp=0)
plotshape(LONG,title="Buy",style=shape.labelup,location=location.belowbar,text="Buy",color=green,transp=0)

// === /PLottING ===
// Send alert to TV alarm sub-system
alertcondition(LONG,message="Sell")
alertcondition(SHORT,title="BuY",message="Buy")
alertcondition(SHORT,message="Buy")

////////////////////////////////////////////////////////////////////////////////VWMA

len2 = input(100,minval=1,title="Smooth")
src = input(close,title="Source")
out = vwma(src,len2)

avg1=avg(out,xATRTrailingStop)
plot(avg1,color=aqua,title="ATR")

如果你们能给我指路,真的很感激。我是松树脚本的菜鸟。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。