【问题标题】:How can I stop an alertcondition once its been activated激活后如何停止警报条件
【发布时间】:2019-12-27 15:40:30
【问题描述】:

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

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

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....)

【问题讨论】:

    标签: pine-script


    【解决方案1】:

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

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

    您需要使用一个标志来确定您是多头还是空头。因此,如果您尚未购买/出售,则只能“购买”/“出售”。

    你可以这样做:

    //@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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多