【问题标题】:Alert condition / consecutive signal issues警报条件/连续信号问题
【发布时间】:2020-11-28 21:21:25
【问题描述】:

快速提问。我一直在摆弄 pinescript 并且被卡住了。我整理的这段代码可以按我想要的方式绘制所有内容,但我无法弄清楚为什么 alertconditions 不起作用。它们要么不作为选项出现在编辑器中,要么在每个栏关闭时不管条件如何。我没有包括我摆弄过的警报条件,因为它们显然是错误的。当价格穿过 emas 时,我想将警报条件与箭头的绘图(buyConditions 和 sellCondition)配对。关于如何编写这些或重新编码阻止连续信号的行的任何建议?我想这就是错误所在,但我无法找到不同的方法来做到这一点。仍然在学习。 谢谢

//@version=4
study("3x3", overlay=true)
//inputs
src= close
len= 7
lowband= sma(low,10)
highband= sma(high,20)
mom= src-src[28]
paintbar = mom > 0 ? color.lime : mom < 0 ? color.fuchsia: na
buyCondition = crossunder(low,lowband[1])
sellCondition = crossover(high,highband[1])
//plots
plot(lowband, title="Low SMA", color=color.orange, linewidth=1, offset=1)
plot(highband, title="High SMA", color=color.orange, linewidth=1, offset=1)
barcolor(color=paintbar)

//to avoid multiple signals
bs = 0
bs := buyCondition ? 1 : sellCondition ? 2 : nz(bs[1])


plotshape(bs != bs[1], color = bs == 1 ? color.lime : color.red,title="Order Arrow", style=shape.arrowup, location=location.belowbar)

【问题讨论】:

    标签: pine-script


    【解决方案1】:

    为了让您的警报条件显示在编辑器中,您必须给它们一个标题。
    另见How to highlight TradingView alert setups with text and shapes?

    这是您的代码,带有警报条件:

    //@version=4
    study("3x3", overlay=true)
    //inputs
    src= close
    len= 7
    lowband= sma(low,10)
    highband= sma(high,20)
    mom= src-src[28]
    paintbar = mom > 0 ? color.lime : mom < 0 ? color.fuchsia: na
    buyCondition = crossunder(low,lowband[1])
    sellCondition = crossover(high,highband[1])
    //plots
    plot(lowband, title="Low SMA", color=color.orange, linewidth=1, offset=1)
    plot(highband, title="High SMA", color=color.orange, linewidth=1, offset=1)
    barcolor(color=paintbar)
    
    //to avoid multiple signals
    var int bs = na
    bs := buyCondition ? 1 : sellCondition ? 2 : 0
    
    alertcondition(buyCondition, title="buyCondition Title", message="Buy here")
    alertcondition(sellCondition, title="sellCondition Title", message="Sell here")
    
    
    plotshape(bs != 0, color = bs == 1 ? color.lime : color.red,title="Order Arrow", style=shape.arrowup, location=location.belowbar)
    

    【讨论】:

    • 谢谢。解决了它。本可以发誓我在以前的版本中已经这样做了,但我想不会。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多