OPEN-SOURCE SCRIPT

Gold Swings Peaks & Troughs

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

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.