IndicatorNeo_Support_Resistance_Alerts

neo_gallage · study · 128 行 · 点赞 767 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// ╔══════════════════════════════════════════════════════════════════════╗
// ║ Copyright © 2026 Eranga Gallage (neo_gallage). All rights reserved.  ║
// ║                                                                      ║
// ║ This work is authored and maintained by Eranga Gallage under the     ║
// ║ trademark “neo_gallage”.                                             ║
// ║ This copyright notice and header must not be altered, removed, or    ║
// ║ obscured.                                                            ║
// ╚══════════════════════════════════════════════════════════════════════╝
//
//                                                            ████  ████                             
//                                                           ▒▒███ ▒▒███                             
//  ████████    ██████   ██████             ███████  ██████   ▒███  ▒███   ██████    ███████  ██████ 
// ▒▒███▒▒███  ███▒▒███ ███▒▒███           ███▒▒███ ▒▒▒▒▒███  ▒███  ▒███  ▒▒▒▒▒███  ███▒▒███ ███▒▒███
//  ▒███ ▒███ ▒███████ ▒███ ▒███          ▒███ ▒███  ███████  ▒███  ▒███   ███████ ▒███ ▒███▒███████ 
//  ▒███ ▒███ ▒███▒▒▒  ▒███ ▒███          ▒███ ▒███ ███▒▒███  ▒███  ▒███  ███▒▒███ ▒███ ▒███▒███▒▒▒  
//  ████ █████▒▒██████ ▒▒██████  █████████▒▒███████▒▒████████ █████ █████▒▒████████▒▒███████▒▒██████ 
// ▒▒▒▒ ▒▒▒▒▒  ▒▒▒▒▒▒   ▒▒▒▒▒▒  ▒▒▒▒▒▒▒▒▒  ▒▒▒▒▒███ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒  ▒▒▒▒▒▒▒▒  ▒▒▒▒▒███ ▒▒▒▒▒▒  
//                                         ███ ▒███                                 ███ ▒███         
//                                        ▒▒██████                                 ▒▒██████          
//                                         ▒▒▒▒▒▒                                   ▒▒▒▒▒▒                 
//
 
 
//@version=6
indicator(title = "IndicatorNeo_Support_Resistance_Alerts", overlay = true, max_lines_count = 100, max_labels_count = 100)
 
//--- Indicator operation and behavior:
//--- 1. The indicator identifies support and resistance from confirmed pivot lows
//---    and pivot highs. The number of bars on each side of a pivot is controlled
//---    by inp_pivot_length. A pivot is only available after the right-side bars
//---    have closed, so levels are intentionally confirmed with a delay.
//--- 2. A newly detected pivot becomes a level only when it is sufficiently far
//---    from the latest opposing level. This prevents closely spaced pivots from
//---    continuously replacing one another and reduces visual noise.
//--- 3. When inp_distance_type is "Percentage", the candidate level must differ
//---    from the opposing level by at least inp_min_distance_pct percent. When
//---    it is "ATR_Multiplier", the required price distance is calculated as
//---    ta.atr(14) multiplied by inp_atr_multiplier.
//--- 4. The latest accepted support and resistance levels are stored persistently
//---    and can be displayed as horizontal lines when inp_show_levels is enabled.
//---    Each new accepted level replaces the previous line of the same type and
//---    extends the line to the right.
//--- 5. A long signal occurs only when the confirmed closing price crosses above
//---    the latest resistance level. A short signal occurs only when the confirmed
//---    closing price crosses below the latest support level. Signal markers can
//---    be enabled or disabled with inp_show_signals.
//--- 6. Risk levels are calculated from the signal close using the ATR distance
//---    ta.atr(14) * inp_atr_multiplier. For long signals, the stop is below the
//---    entry and the target is above it. For short signals, the stop is above the
//---    entry and the target is below it. inp_stop_multiplier and
//---    inp_target_multiplier independently scale those two distances.
//--- 7. On a confirmed signal, the alert() message is emitted once per bar close
//---    using the following machine-readable format:
//---    signal=long | entry=<price> | stop=<price> | target=<price>
//---    signal=short | entry=<price> | stop=<price> | target=<price>
//--- 8. This indicator detects and reports breakout events; it does not place,
//---    manage, or close broker orders. Stops and targets are informational values
//---    included in the alert message for downstream handling or automation.
 
inp_pivot_length = input.int(5, "Pivot Length", minval = 1, inline = "inline_1")
inp_distance_type = input.string("Percentage", "Distance Type", options = ["Percentage", "ATR_Multiplier"], inline = "inline_2")
inp_min_distance_pct = input.float(0.2, "Minimum Level Distance - Percentage(%)", minval = 0.0001, step = 0.1, inline = "inline_3")
inp_atr_multiplier = input.float(2.0, "Minimum Level Distance - ATR Multiplier", minval = 0.0, step = 0.1, inline = "inline_4")
inp_show_levels = input.bool(true, "Show Support/Resistance Levels", inline = "inline_5")
inp_show_signals = input.bool(true, "Show Entry Signals", inline = "inline_6")
inp_stop_multiplier = input.float(1.0, "Stop Multiplier", minval = 0.0, step = 0.1, inline = "inline_7")
inp_target_multiplier = input.float(1.0, "Target Multiplier", minval = 0.0, step = 0.1, inline = "inline_8")
 
//--- Varibales to hold support/resistance levels 
var float var_support = na
var float var_resistance = na
var int var_support_bar = na
var int var_resistance_bar = na
var line var_support_line = na
var line var_resistance_line = na
 
sr_pivot_low = ta.pivotlow(low, inp_pivot_length, inp_pivot_length)
sr_pivot_high = ta.pivothigh(high, inp_pivot_length, inp_pivot_length)
sr_atr = ta.atr(14)
 
if not na(sr_pivot_low)
    sr_candidate = sr_pivot_low
    sr_distance = math.abs(sr_candidate - var_resistance)
    sr_far_enough = na(var_resistance) or (inp_distance_type == "Percentage" ? sr_distance / var_resistance * 100 >= inp_min_distance_pct : sr_distance >= sr_atr * inp_atr_multiplier)
    if sr_far_enough
        var_support := sr_candidate
        var_support_bar := bar_index - inp_pivot_length
        if inp_show_levels
            line.delete(var_support_line)
            var_support_line := line.new(var_support_bar, var_support, bar_index, var_support, extend = extend.right, color = color.lime, width = 2)
 
if not na(sr_pivot_high)
    sr_candidate = sr_pivot_high
    sr_distance = math.abs(sr_candidate - var_support)
    sr_far_enough = na(var_support) or (inp_distance_type == "Percentage" ? sr_distance / var_support * 100 >= inp_min_distance_pct : sr_distance >= sr_atr * inp_atr_multiplier)
    if sr_far_enough
        var_resistance := sr_candidate
        var_resistance_bar := bar_index - inp_pivot_length
        if inp_show_levels
            line.delete(var_resistance_line)
            var_resistance_line := line.new(var_resistance_bar, var_resistance, bar_index, var_resistance, extend = extend.right, color = color.red, width = 2)
 
//--- A signal is generated only when price breaks the latest opposing level.
sr_confirmed = barstate.isconfirmed
sr_crossover = ta.crossover(close, var_resistance) 
sr_crossunder = ta.crossunder(close, var_support) 
sr_long_signal = sr_confirmed and not na(var_resistance) and sr_crossover 
sr_short_signal = sr_confirmed and not na(var_support) and sr_crossunder 
 
//--- Stop loss and take profit use the configured ATR distance from the signal close.
sr_atr_distance = sr_atr * inp_atr_multiplier
sr_stop_distance = sr_atr_distance * inp_stop_multiplier
sr_target_distance = sr_atr_distance * inp_target_multiplier
sr_long_stop = sr_long_signal ? close - sr_stop_distance : na
sr_long_target = sr_long_signal ? close + sr_target_distance : na
sr_short_stop = sr_short_signal ? close + sr_stop_distance : na
sr_short_target = sr_short_signal ? close - sr_target_distance : na
 
plotshape(inp_show_signals and sr_long_signal, title = "Long entry", style = shape.labelup, location = location.belowbar, color = color.lime, text = "LONG", textcolor = color.black, size = size.tiny)
plotshape(inp_show_signals and sr_short_signal, title = "Short entry", style = shape.labeldown, location = location.abovebar, color = color.red, text = "SHORT", textcolor = color.white, size = size.tiny)
 
if sr_long_signal
    alert("signal=long | entry=" + str.tostring(close, format.mintick) + " | stop=" + str.tostring(sr_long_stop, format.mintick) + " | target=" + str.tostring(sr_long_target, format.mintick), alert.freq_once_per_bar_close)
if sr_short_signal
    alert("signal=short | entry=" + str.tostring(close, format.mintick) + " | stop=" + str.tostring(sr_short_stop, format.mintick) + " | target=" + str.tostring(sr_short_target, format.mintick), alert.freq_once_per_bar_close)
 
alertcondition(sr_long_signal, "Long entry", "LONG breakout detected")
alertcondition(sr_short_signal, "Short entry", "SHORT breakout detected")

← 返回列表