OPEN-SOURCE SCRIPT

Gold Swings Peaks & Troughs

119
//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

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.