OPEN-SOURCE SCRIPT

Gold Swings Peaks & Troughs

127
//version=5
indicator("Gold Swings Peaks & Troughs CLEAN", overlay=true, max_labels_count=500)

// ===== إعدادات المستخدم =====
len = input.int(2, "Swing Length") // عدد الشموع قبل وبعد لتحديد القمة/القاع
minDistance = input.int(5, "Min Bars Between Signals") // لتقليل الإشارات المتقاربة
buyColor = input.color(color.green, "BUY Color")
sellColor = input.color(color.red, "SELL Color")

// ===== متغير لتخزين آخر إشارة =====
var int lastBuyBar = na
var int lastSellBar = na

// ===== قمة و قاع محلية =====
localLow = low == ta.lowest(low, len*2 + 1)
localHigh = high == ta.highest(high, len*2 + 1)

// ===== رسم Labels فقط عند القمم والقيعان مع منع التكرار القريب =====
if localLow and (na(lastBuyBar) or bar_index - lastBuyBar >= minDistance)
label.new(bar_index, low, "BUY", style=label.style_label_up, color=buyColor, textcolor=color.white)
lastBuyBar := bar_index

if localHigh and (na(lastSellBar) or bar_index - lastSellBar >= minDistance)
label.new(bar_index, high, "SELL", style=label.style_label_down, color=sellColor, textcolor=color.white)
lastSellBar := bar_index

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.