You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为现有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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 12:23:02