OPEN-SOURCE SCRIPT

Support and Resistance Zones

//version=5
indicator("Support and Resistance Zones", overlay=true)

// Input parameters
lookback = input.int(20, "Lookback Period for Zones", minval=1)
zoneWidth = input.float(0.3, "Zone Width (%)", minval=0.1, step=0.1)
highlightZones = input.bool(true, "Highlight Zones", inline="Highlight")

// Identify swing highs and lows
isSwingHigh = ta.highest(high, lookback) == high and high > ta.highest(high[1], lookback)
isSwingLow = ta.lowest(low, lookback) == low and low < ta.lowest(low[1], lookback)

// Store significant levels using arrays
var float resistanceLevel = na
var float supportLevel = na

if isSwingHigh
resistanceLevel := high
if isSwingLow
supportLevel := low

// Define support and resistance zones
resistanceZoneTop = resistanceLevel * (1 + zoneWidth / 100)
resistanceZoneBottom = resistanceLevel * (1 - zoneWidth / 100)

supportZoneTop = supportLevel * (1 + zoneWidth / 100)
supportZoneBottom = supportLevel * (1 - zoneWidth / 100)

// Highlight zones if the price is within them
bgcolor(highlightZones and resistanceLevel and close >= resistanceZoneBottom and close <= resistanceZoneTop ? color.new(color.red, 85) : na, title="Resistance Zone")
bgcolor(highlightZones and supportLevel and close >= supportZoneBottom and close <= supportZoneTop ? color.new(color.green, 85) : na, title="Support Zone")

// Plot support and resistance levels
plot(resistanceLevel, title="Resistance", color=color.red, linewidth=2, style=plot.style_line)
plot(supportLevel, title="Support", color=color.green, linewidth=2, style=plot.style_line)

// Alerts for when price enters the zones
alertcondition(close >= resistanceZoneBottom and close <= resistanceZoneTop, title="Resistance Zone Alert", message="Price entered Resistance Zone")
alertcondition(close >= supportZoneBottom and close <= supportZoneTop, title="Support Zone Alert", message="Price entered Support Zone")
Candlestick analysisTrend AnalysisWave Analysis

開源腳本

在真正的TradingView精神中,這個腳本的作者以開源的方式發佈,這樣交易員可以理解和驗證它。請向作者致敬!您可以免費使用它,但在出版物中再次使用這段程式碼將受到網站規則的約束。 您可以收藏它以在圖表上使用。

想在圖表上使用此腳本?

免責聲明