警报条件被激活后如何停止

How can I stop an alertcondition once its been activated

我正在触发两个单独的警报条件(发生交叉和交叉时)

他们在收到此警报后经过几次,并多次触发警报。我希望设置一个条件,以便一旦他们完成它就不再触发警报条件,直到触发另一个警报条件

aka alertcondition(long...) 仅在其条件再次发生时触发一次,但条件在 alertcondition(short...) 触发后恢复,反之亦然

long = crossover(RSIMain,SellAlertLevel)
short = crossunder(RSIMain,BuyAlertLevel)

alertcondition(long, title='BUY', message='BUY!')
alertcondition(short, title='SELL', message='SELL!')

plotshape(long, style=shape.arrowup, text="Long", color=green, location=location.belowbar, size=size.auto)
plotshape(short, style=shape.arrowdown, text="Short", color=red, location=location.abovebar, size=size.auto)

isLongOpen = false
isShortOpen = false

然后在代码的底部:

if (long)
    isLongOpen := true
    isShortOpen := false

if (short)
    isShortOpen := true
    isLongOpen := false

alertcondition((long and not isLongOpen), title....)
plotshape((long and not isLongOpen), title....)

嗯,绘制 longshort 可能会有所帮助。它可视化您的问题。

longshort 为真,只要 crossover/crossunder 发生。只要它为真,就会触发您的警报。

您需要使用一个标志来判断您是否已经做多或做空。所以,如果你还没有 bought/sold.

,你只能 "BUY" / "SELL"

你可以这样做:

//@version=4
study("My Script", overlay=true)

SellAlertLevel = 30
BuyAlertLevel = 70

isLong = false              // A flag for going LONG
isLong := nz(isLong[1])     // Get the previous value of it

isShort = false             // A flag for going SHORT
isShort := nz(isShort[1])   // Get the previous value of it

RSIMain = rsi(close, 14)

buySignal = crossover(RSIMain,SellAlertLevel) and not isLong    // Buy only if we are not already long
sellSignal = crossunder(RSIMain,BuyAlertLevel) and not isShort  // Sell only if we are not already short

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

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

plotshape(series=buySignal, title="BUY", text="BUY", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(series=sellSignal, title="SELL", text="SELL", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)