如何为现有Pine Script策略的买卖信号添加触发警报?
为Pine Script买卖信号添加触发警报
直接在现有代码中加入alert()函数,就能在信号触发时触发警报。修改后的完整代码如下:
//@version=5 indicator(title='TEST08032023', overlay=true) s9ema = ta.ema(close, 9) s18ema = ta.ema(close, 18) longCond = ta.crossover(s9ema, s18ema) shortCond = ta.crossunder(s9ema, s18ema) // 买入信号警报 if (longCond) alert("买入信号触发!", alert.freq_once_per_bar_close) // 卖出信号警报 if (shortCond) alert("卖出信号触发!", alert.freq_once_per_bar_close) plotshape(series=longCond, title='BUY', style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.new(color.white, 0), text='BUY', size=size.small) plotshape(series=shortCond, title='SELL', style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), textcolor=color.new(color.white, 0), text='SELL', size=size.small)
核心说明
- 通过
if()语句监测买卖信号的触发条件 alert.freq_once_per_bar_close参数保证每个K线仅触发一次警报,避免重复推送- 你可以自定义警报提示文本,也能在TradingView的设置中选择弹窗、邮件、APP推送等通知方式
内容的提问来源于stack exchange,提问作者Rashmi Rahul
相关产品推荐
相关产品推荐

