OPEN-SOURCE SCRIPT
RSI Divergence & Momentum Color

//version=5
// هذا مؤشر موحد يحدد الدايفرجنس (العادي والمخفي) ويقوم بتلوين الشموع حسب زخم RSI.
indicator(title="RSI Divergence & Momentum Color", shorttitle="RSI Divergence & MOM", overlay=true)
// --- 1. الإعدادات والمتغيرات (Inputs) ---
// إعدادات RSI
rsiLength = input.int(14, title="RSI Length", minval=1)
// إعدادات تحديد القمم والقيعان (Pivots)
pivotLeft = input.int(5, title="Pivot Lookback Left", minval=1)
pivotRight = input.int(5, title="Pivot Lookback Right", minval=1)
// --- 2. حساب مؤشر القوة النسبية (RSI Calculation) ---
rsi = ta.rsi(close, rsiLength)
// --- 3. تلوين الشموع حسب الزخم (RSI Momentum Color) ---
// فحص: هل RSI الحالي أكبر من RSI السابق؟
isRSIUp = rsi > rsi[1]
// تحديد اللون بناءً على الشرط
var color colorRSI = na
// تلوين الشمعة باللون الأخضر إذا كان RSI صاعداً، وبالأحمر إذا كان هابطاً
if isRSIUp
colorRSI := color.new(color.green, 60) // أخضر فاتح
else
colorRSI := color.new(color.red, 60) // أحمر فاتح
// تطبيق تلوين الشمعة على الشارت الرئيسي
barcolor(colorRSI)
// --- 4. تحديد الدايفرجنس (Divergence Detection) ---
// تحديد القمم والقيعان على السعر
price_high_pivot = ta.pivothigh(high, pivotLeft, pivotRight)
price_low_pivot = ta.pivotlow(low, pivotLeft, pivotRight)
// تحديد القمم والقيعان على RSI
rsi_high_pivot = ta.pivothigh(rsi, pivotLeft, pivotRight)
rsi_low_pivot = ta.pivotlow(rsi, pivotLeft, pivotRight)
// *** المنطق المباشر للدايفرجنس (تظهر الإشارة عند القمة/القاع المكتملة) ***
// 🔵 الدايفرجنس العادي الصعودي (Regular Bullish Div)
isRegBull = price_low_pivot and rsi_low_pivot and low < low[pivotRight] and rsi > rsi[pivotRight]
// 🔴 الدايفرجنس العادي الهبوطي (Regular Bearish Div)
isRegBear = price_high_pivot and rsi_high_pivot and high > high[pivotRight] and rsi < rsi[pivotRight]
// 🟪 الدايفرجنس المخفي الصعودي (Hidden Bullish Div)
isHiddenBull = price_low_pivot and rsi_low_pivot and low > low[pivotRight] and rsi < rsi[pivotRight]
// 🟧 الدايفرجنس المخفي الهبوطي (Hidden Bearish Div)
isHiddenBear = price_high_pivot and rsi_high_pivot and high < high[pivotRight] and rsi > rsi[pivotRight]
// --- 5. رسم إشارات الدايفرجنس على السعر (Plotting Shapes) ---
// رسم الإشارات على الشارت الرئيسي (لتحديد مناطق الانعكاس/الاستمرار)
// 1. عادي صعودي (انعكاس)
plotshape(isRegBull, title="Regular Bullish Div", location=location.belowbar, style=shape.triangleup, color=color.green, size=size.small)
// 2. عادي هبوطي (انعكاس)
plotshape(isRegBear, title="Regular Bearish Div", location=location.abovebar, style=shape.triangledown, color=color.red, size=size.small)
// 3. مخفي صعودي (استمرار)
plotshape(isHiddenBull, title="Hidden Bullish Div", location=location.belowbar, style=shape.diamond, color=color.blue, size=size.small)
// 4. مخفي هبوطي (استمرار)
plotshape(isHiddenBear, title="Hidden Bearish Div", location=location.abovebar, style=shape.diamond, color=color.orange, size=size.small)
// --- 6. عرض مؤشر RSI في نافذة فرعية (Sub-Window) ---
// يجب إضافة مؤشر RSI بشكل منفصل لترى الدايفرجنس على منحنى RSI
// لكي تظهر الخطوط على منحنى RSI، يجب عليك إضافة كود المؤشر السابق (RSI Divergence Detector (Full))
// على نافذة RSI، ولكن هذا يتعارض مع طلبك دمج كل شيء.
// أفضل طريقة هي: قم بإضافة هذا المؤشر إلى الشارت، ثم أضف مؤشر RSI الافتراضي إلى نافذة جديدة.
// أو يمكنك إنشاء مؤشر RSI منفصل خاص بك في نافذة فرعية:
plot(rsi, title="RSI Value", color=color.rgb(100, 150, 200), display=display.none) // لا تعرض في الشارت الرئيسي
// لعرض RSI في نافذة فرعية، قم بإنشاء مؤشر جديد واضبط overlay=false
// أو استخدم المؤشر التالي (بما أن هذا المؤشر يحتوي على overlay=true، لن يرسم RSI أسفل الشارت).
// --- ملاحظة أخيرة: لرسم الخطوط على RSI أسفل الشارت ---
// لتحقيق ذلك بالضبط، يجب كتابة مؤشر ثانٍ بـ (overlay=false)
// يحتوي على نفس منطق الدايفرجنس. لتجنب ذلك، يكتفي هذا الكود برسم الإشارات
// على السعر (overlay=true) وتلوين الشموع.
// هذا مؤشر موحد يحدد الدايفرجنس (العادي والمخفي) ويقوم بتلوين الشموع حسب زخم RSI.
indicator(title="RSI Divergence & Momentum Color", shorttitle="RSI Divergence & MOM", overlay=true)
// --- 1. الإعدادات والمتغيرات (Inputs) ---
// إعدادات RSI
rsiLength = input.int(14, title="RSI Length", minval=1)
// إعدادات تحديد القمم والقيعان (Pivots)
pivotLeft = input.int(5, title="Pivot Lookback Left", minval=1)
pivotRight = input.int(5, title="Pivot Lookback Right", minval=1)
// --- 2. حساب مؤشر القوة النسبية (RSI Calculation) ---
rsi = ta.rsi(close, rsiLength)
// --- 3. تلوين الشموع حسب الزخم (RSI Momentum Color) ---
// فحص: هل RSI الحالي أكبر من RSI السابق؟
isRSIUp = rsi > rsi[1]
// تحديد اللون بناءً على الشرط
var color colorRSI = na
// تلوين الشمعة باللون الأخضر إذا كان RSI صاعداً، وبالأحمر إذا كان هابطاً
if isRSIUp
colorRSI := color.new(color.green, 60) // أخضر فاتح
else
colorRSI := color.new(color.red, 60) // أحمر فاتح
// تطبيق تلوين الشمعة على الشارت الرئيسي
barcolor(colorRSI)
// --- 4. تحديد الدايفرجنس (Divergence Detection) ---
// تحديد القمم والقيعان على السعر
price_high_pivot = ta.pivothigh(high, pivotLeft, pivotRight)
price_low_pivot = ta.pivotlow(low, pivotLeft, pivotRight)
// تحديد القمم والقيعان على RSI
rsi_high_pivot = ta.pivothigh(rsi, pivotLeft, pivotRight)
rsi_low_pivot = ta.pivotlow(rsi, pivotLeft, pivotRight)
// *** المنطق المباشر للدايفرجنس (تظهر الإشارة عند القمة/القاع المكتملة) ***
// 🔵 الدايفرجنس العادي الصعودي (Regular Bullish Div)
isRegBull = price_low_pivot and rsi_low_pivot and low < low[pivotRight] and rsi > rsi[pivotRight]
// 🔴 الدايفرجنس العادي الهبوطي (Regular Bearish Div)
isRegBear = price_high_pivot and rsi_high_pivot and high > high[pivotRight] and rsi < rsi[pivotRight]
// 🟪 الدايفرجنس المخفي الصعودي (Hidden Bullish Div)
isHiddenBull = price_low_pivot and rsi_low_pivot and low > low[pivotRight] and rsi < rsi[pivotRight]
// 🟧 الدايفرجنس المخفي الهبوطي (Hidden Bearish Div)
isHiddenBear = price_high_pivot and rsi_high_pivot and high < high[pivotRight] and rsi > rsi[pivotRight]
// --- 5. رسم إشارات الدايفرجنس على السعر (Plotting Shapes) ---
// رسم الإشارات على الشارت الرئيسي (لتحديد مناطق الانعكاس/الاستمرار)
// 1. عادي صعودي (انعكاس)
plotshape(isRegBull, title="Regular Bullish Div", location=location.belowbar, style=shape.triangleup, color=color.green, size=size.small)
// 2. عادي هبوطي (انعكاس)
plotshape(isRegBear, title="Regular Bearish Div", location=location.abovebar, style=shape.triangledown, color=color.red, size=size.small)
// 3. مخفي صعودي (استمرار)
plotshape(isHiddenBull, title="Hidden Bullish Div", location=location.belowbar, style=shape.diamond, color=color.blue, size=size.small)
// 4. مخفي هبوطي (استمرار)
plotshape(isHiddenBear, title="Hidden Bearish Div", location=location.abovebar, style=shape.diamond, color=color.orange, size=size.small)
// --- 6. عرض مؤشر RSI في نافذة فرعية (Sub-Window) ---
// يجب إضافة مؤشر RSI بشكل منفصل لترى الدايفرجنس على منحنى RSI
// لكي تظهر الخطوط على منحنى RSI، يجب عليك إضافة كود المؤشر السابق (RSI Divergence Detector (Full))
// على نافذة RSI، ولكن هذا يتعارض مع طلبك دمج كل شيء.
// أفضل طريقة هي: قم بإضافة هذا المؤشر إلى الشارت، ثم أضف مؤشر RSI الافتراضي إلى نافذة جديدة.
// أو يمكنك إنشاء مؤشر RSI منفصل خاص بك في نافذة فرعية:
plot(rsi, title="RSI Value", color=color.rgb(100, 150, 200), display=display.none) // لا تعرض في الشارت الرئيسي
// لعرض RSI في نافذة فرعية، قم بإنشاء مؤشر جديد واضبط overlay=false
// أو استخدم المؤشر التالي (بما أن هذا المؤشر يحتوي على overlay=true، لن يرسم RSI أسفل الشارت).
// --- ملاحظة أخيرة: لرسم الخطوط على RSI أسفل الشارت ---
// لتحقيق ذلك بالضبط، يجب كتابة مؤشر ثانٍ بـ (overlay=false)
// يحتوي على نفس منطق الدايفرجنس. لتجنب ذلك، يكتفي هذا الكود برسم الإشارات
// على السعر (overlay=true) وتلوين الشموع.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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.