اینجا یک اندیکاتور برای TradingView که سطوح حمایت و مقاومت را شناسایی و نمایش میدهد:
pinescript
//@version=5
indicator("حمایت و مقاومت پیشرفته", overlay=true, max_bars_back=500)
// تنظیمات ورودی
lookback = input.int(50, "دوره بررسی", minval=10, maxval=200)
strength = input.int(3, "قدرت سطوح", minval=1, maxval=10)
showMajor = input.bool(true, "نمایش سطوح مهم")
showMinor = input.bool(true, "نمایش سطوح معمولی")
touchSensitivity = input.float(0.3, "حساسیت برخورد (%)", minval=0.1, maxval=1.0)
// رنگها
majorResistanceColor = input.color(color.red, "رنگ مقاومت مهم")
minorResistanceColor = input.color(color.new(color.red, 50), "رنگ مقاومت معمولی")
majorSupportColor = input.color(color.green, "رنگ حمایت مهم")
minorSupportColor = input.color(color.new(color.green, 50), "رنگ حمایت معمولی")
// تابع شناسایی نقاط پیوت
isPivotHigh(src, left, right) =>
highestValue = ta.highest(src, left + right + 1)
src[right] == highestValue
isPivotLow(src, left, right) =>
lowestValue = ta.lowest(src, left + right + 1)
src[right] == lowestValue
// شناسایی نقاط پیوت
pivotHigh = isPivotHigh(high, strength, strength)
pivotLow = isPivotLow(low, strength, strength)
// ذخیره سطوح در آرایه
var resistanceLevels = array.new<float>()
var resistanceTouches = array.new<int>()
var supportLevels = array.new<float>()
var supportTouches = array.new<int>()
// اضافه کردن سطوح جدید
if pivotHigh
level = high[strength]
found = false
// بررسی سطوح موجود
for i = 0 to array.size(resistanceLevels) - 1
if math.abs(array.get(resistanceLevels, i) - level) / level * 100 < touchSensitivity
array.set(resistanceTouches, i, array.get(resistanceTouches, i) + 1)
found = true
break
if not found
array.push(resistanceLevels, level)
array.push(resistanceTouches, 1)
if pivotLow
level = low[strength]
found = false
// بررسی سطوح موجود
for i = 0 to array.size(supportLevels) - 1
if math.abs(array.get(supportLevels, i) - level) / level * 100 < touchSensitivity
array.set(supportTouches, i, array.get(supportTouches, i) + 1)
found = true
break
if not found
array.push(supportLevels, level)
array.push(supportTouches, 1)
// محدود کردن تعداد سطوح
if array.size(resistanceLevels) > 20
array.shift(resistanceLevels)
array.shift(resistanceTouches)
if array.size(supportLevels) > 20
array.shift(supportLevels)
array.shift(supportTouches)
// رسم سطوح
if barstate.islast
// حذف خطوط قبلی
line.delete(line.all[1])
// رسم مقاومتها
for i = 0 to array.size(resistanceLevels) - 1
level = array.get(resistanceLevels, i)
touches = array.get(resistanceTouches, i)
// تعیین اهمیت سطح
isMajor = touches >= 3
if (isMajor and showMajor) or (not isMajor and showMinor)
lineColor = isMajor ? majorResistanceColor : minorResistanceColor
lineWidth = isMajor ? 2 : 1
lineStyle = isMajor ? line.style_solid : line.style_dashed
line.new(bar_index - lookback, level, bar_index + 10, level,
color=lineColor, width=lineWidth, style=lineStyle)
// رسم حمایتها
for i = 0 to array.size(supportLevels) - 1
level = array.get(supportLevels, i)
touches = array.get(supportTouches, i)
// تعیین اهمیت سطح
isMajor = touches >= 3
if (isMajor and showMajor) or (not isMajor and showMinor)
lineColor = isMajor ? majorSupportColor : minorSupportColor
lineWidth = isMajor ? 2 : 1
lineStyle = isMajor ? line.style_solid : line.style_dashed
line.new(bar_index - lookback, level, bar_index + 10, level,
color=lineColor, width=lineWidth, style=lineStyle)
// نمایش برچسب برای سطوح مهم
var label resistanceLabel = na
var label supportLabel = na
if barstate.islast
label.delete(resistanceLabel)
label.delete(supportLabel)
// یافتن نزدیکترین مقاومت مهم
nearestResistance = na
nearestResistanceTouches = 0
for i = 0 to array.size(resistanceLevels) - 1
level = array.get(resistanceLevels, i)
touches = array.get(resistanceTouches, i)
if touches >= 3 and level > close
if na(nearestResistance) or level < nearestResistance
nearestResistance := level
nearestResistanceTouches := touches
if not na(nearestResistance)
resistanceLabel := label.new(bar_index + 5, nearestResistance,
"مقاومت مهم (" + str.tostring(nearestResistanceTouches) + " برخورد)",
color=color.new(color.red, 80),
textcolor=color.red,
style=label.style_label_left)
// یافتن نزدیکترین حمایت مهم
nearestSupport = na
nearestSupportTouches = 0
for i = 0 to array.size(supportLevels) - 1
level = array.get(supportLevels, i)
touches = array.get(supportTouches, i)
if touches >= 3 and level < close
if na(nearestSupport) or level > nearestSupport
nearestSupport := level
nearestSupportTouches := touches
if not na(nearestSupport)
supportLabel := label.new(bar_index + 5, nearestSupport,
"حمایت مهم (" + str.tostring(nearestSupportTouches) + " برخورد)",
color=color.new(color.green, 80),
textcolor=color.green,
style=label.style_label_left)
// هشدار نزدیک شدن به سطوح مهم
alertDistance = input.float(0.5, "فاصله هشدار (%)", minval=0.1, maxval=2.0)
for i = 0 to array.size(resistanceLevels) - 1
level = array.get(resistanceLevels, i)
touches = array.get(resistanceTouches, i)
if touches >= 3
if high >= level * (1 - alertDistance/100) and close < level
alert("نزدیک شدن به مقاومت مهم: " + str.tostring(level), alert.freq_once_per_bar)
for i = 0 to array.size(supportLevels) - 1
level = array.get(supportLevels, i)
touches = array.get(supportTouches, i)
if touches >= 3
if low <= level * (1 + alertDistance/100) and close > level
alert("نزدیک شدن به حمایت مهم: " + str.tostring(level), alert.freq_once_per_bar)
برای استفاده، کد را در Pine Editor تریدینگ ویو کپی کرده و به چارت اضافه کنید.