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 (将#修改为@)