OPEN-SOURCE SCRIPT
تم تحديثه Relative Strength vs Index-SQB

What is Relative Strength (RS)?
Imagine you open your chart of Infosys (INFY) and you want to know — is this stock actually strong, or is it just going up because the whole IT sector is going up?
That's exactly what RS tells you.
The formula is simply:
RS = Stock's % change − Index's % change (over same period)
Stock Δ% and Index Δ%
Say you set the lookback to 63 bars (~3 months):
Infosys went up +12% in last 63 days → that's your Stock Δ%
Nifty IT index went up +7% in the same 63 days → that's your Index Δ%
RS Value = 12 − 7 = +5 → Infosys is outperforming its sector by 5%
Another example:
Infosys went up +3%
Nifty IT went up +7%
RS Value = 3 − 7 = −4 → Infosys is underperforming its sector by 4%, even though the price went up
So a stock can be going up in price but still be WEAK if the index is going up faster. This is the key insight RS gives you.
What the RS line on the price chart does
Instead of reading numbers, you get a smooth line plotted on your candle chart — just like a 50 EMA or 200 EMA. When candles are above the RS line, the stock is in a strong phase relative to the index. When candles fall below the RS line, it means relative weakness is setting in. It acts as dynamic support/resistance based on relative momentum.
Imagine you open your chart of Infosys (INFY) and you want to know — is this stock actually strong, or is it just going up because the whole IT sector is going up?
That's exactly what RS tells you.
The formula is simply:
RS = Stock's % change − Index's % change (over same period)
Stock Δ% and Index Δ%
Say you set the lookback to 63 bars (~3 months):
Infosys went up +12% in last 63 days → that's your Stock Δ%
Nifty IT index went up +7% in the same 63 days → that's your Index Δ%
RS Value = 12 − 7 = +5 → Infosys is outperforming its sector by 5%
Another example:
Infosys went up +3%
Nifty IT went up +7%
RS Value = 3 − 7 = −4 → Infosys is underperforming its sector by 4%, even though the price went up
So a stock can be going up in price but still be WEAK if the index is going up faster. This is the key insight RS gives you.
What the RS line on the price chart does
Instead of reading numbers, you get a smooth line plotted on your candle chart — just like a 50 EMA or 200 EMA. When candles are above the RS line, the stock is in a strong phase relative to the index. When candles fall below the RS line, it means relative weakness is setting in. It acts as dynamic support/resistance based on relative momentum.
ملاحظات الأخبار
Instead of trying to force-fit an RS value (which is a % difference number) onto a price axis, the correct and clean method is:Keep RS in the oscillator panel below (first script) — that's always accurate
On the price chart, use candle coloring + background shading to show RS strength visually — no scaling issues possible
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.