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

求助:如何在TradingView的Semafor指标圆点出现时设置预警

How to Set Alerts for Semafor Indicator Circles in TradingView

Hey there, I see you're trying to set up alerts when those tiny circles from the Semafor indicator pop up. The original code draws the circles using labels, but doesn't give us a direct condition to trigger alerts—so we'll need to tweak the code to track when a new circle is created. Here's how to do it:

The Problem with the Original Code

The zigzag() function in your code creates a label (the circle) but doesn't keep track of when a new one is added. We need to modify the function to return a boolean value that tells us "a new circle was drawn on this bar."

Modified Code with Alert Conditions

Here's the updated code that adds alert-compatible signals for each Semafor size (Small, Medium, Large):

study("Semafor with Alerts", overlay=true)

// Modified zigzag function that returns true when a new circle is created
zigzag(Depth, Deviation, Color) =>
    var lw = 1, var hg = 1
    lw := lw + 1, hg := hg + 1
    p_lw = -lowestbars(Depth), p_hg = -highestbars(Depth)
    lowing = lw == p_lw or low - low[p_lw] > Deviation*syminfo.mintick
    highing = hg == p_hg or high[p_hg] - high > Deviation*syminfo.mintick
    lh = barssince(not highing), ll = barssince(not lowing)
    down = lh > ll, lower = low[lw] > low[p_lw], higher = high[hg] < high[p_hg]
    
    // Track if we're updating the swing point (new circle)
    newCircle = false
    if lw != p_lw and (not down[1] or lower)
        lw := p_lw < hg ? p_lw : 0
        newCircle := true
    if hg != p_hg and (down[1] or higher)
        hg := p_hg < lw ? p_hg : 0
        newCircle := true
    
    x1 = down ? lw : hg
    y1 = down ? low[lw] : high[hg]
    lb = down ? label.style_label_up : label.style_label_down
    label point = label.new(bar_index-x1, y1, color=Color, style=label.style_circle, size=size.tiny)
    if down == down[1]
        label.delete(point[1])
    
    // Return whether a new circle was created on this bar
    newCircle

// Assign signals for each Semafor size
smallSignal = input(true, "Small") ? zigzag(input(7, "Depth (Small)"), input(3, "Deviation (Small)"), input(color.lime, "Color (Small)")) : false
mediumSignal = input(true, "Medium") ? zigzag(input(14, "Depth (Medium)"), input(6, "Deviation (Medium)"), input(color.orange, "Color (Medium)")) : false
largeSignal = input(true, "Large") ? zigzag(input(72, "Depth (Large)"), input(24, "Deviation (Large)"), input(color.red, "Color (Large)")) : false

// Optional: Plot visible markers to verify alert triggers
plotshape(smallSignal, title="Small Circle Trigger", location=location.belowbar, color=color.lime, style=shape.circle, size=size.small)
plotshape(mediumSignal, title="Medium Circle Trigger", location=location.belowbar, color=color.orange, style=shape.circle, size=size.medium)
plotshape(largeSignal, title="Large Circle Trigger", location=location.belowbar, color=color.red, style=shape.circle, size=size.large)

How to Set Up the Alert

  1. Replace your existing indicator code: Paste the modified code above into the Pine Editor, save it (name it something like "Semafor with Alerts"), and add it to your chart.
  2. Open the Alert menu: Click the "Alerts" button at the top of TradingView, then select "Create Alert".
  3. Configure the alert condition:
    • Under "Condition", choose your new indicator ("Semafor with Alerts").
    • Pick the signal you want to alert on: smallSignal, mediumSignal, or largeSignal.
    • Set the condition to "is true"—this triggers when a new circle is drawn.
  4. Set notification preferences: Choose how you want to be notified (email, in-app alert, SMS, etc.).
  5. Save the alert: Click "Create" to activate it.

Key Notes

  • The plotshape() lines are optional but helpful—they add visible markers below bars when a circle is created, so you can confirm alerts are triggering correctly.
  • Each signal matches the original Semafor size colors: green for Small, orange for Medium, red for Large.
  • Alerts fire exactly when a new swing point (and circle) is detected, based on the Depth and Deviation settings you choose.

内容的提问来源于stack exchange,提问作者Tozey

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 06:32:32