OPEN-SOURCE SCRIPT

Saral Relative Strength

ที่อัปเดต:
Relative Strength Indicator

### Overview

The Relative Strength (RS) Indicator is a robust tool designed to measure the performance of a security relative to a benchmark or another security. Unlike traditional indicators, this RS Indicator calculates the outperformance or underperformance in percentage terms, providing a clear and concise comparison.

The equation for calculation can be found in the code itself. This equation compares how much a security's price has changed over a given period (len) relative to the change in price of a benchmark over the same period. The result is expressed as a percentage, showing whether the security has outperformed or underperformed the benchmark. A positive RS value indicates outperformance, while a negative value signals underperformance.

Basically, this indicator is an enhanced version of 'Relative Strength' indicator of 'BharatTrader' Sir with added features like automatic divergence plotting, color-coded filled area and sector names for NSE F&O securities. Default values for some of the parameters are based on discussion by Subhadip Nandy Sir in Trader's Talk with Mr. Rohit Katwal.


### Input Parameters:

  • Source: The price of a security used in the calculation, with the default being the 'close' price.

  • Comparative Symbol: Ticker ID of the comparative security, with the default set to NIFTY 50.

  • Period-RS: The period for calculating the RS line, with a default of 22. The RS line measures the relative performance of the security against the benchmark, helping to identify outperformance or underperformance over time.

  • Period-MA: The period for calculating the Simple Moving Average (SMA) overlay on the RS line, with a default of 11. The SMA provides a smoothed view of the RS line, helping to identify trends more clearly.

  • Lookback - Zero Line Trend: Zero Line Trend look-back period, used to determine the angle of the RS line, with a default of 5. This parameter influences the color of the Zero Line based on whether the RS line’s angle is positive or negative.

  • Lookback - Divergence: Divergence look-back period, with a default of 2, used to detect divergence between the price and the RS line.

  • Display MA Line: Controls the display of the SMA line. When enabled, the SMA line is plotted over the RS line to indicate trend strength.

  • Toggle RS Color on MA Crossovers: Controls the color of the RS line. If disabled, the RS line is purple. If enabled, the RS line changes color based on its position relative to the SMA: green for RS > MA, red for RS < MA.

  • Display Zero Line Trend: Controls the display of the Zero Line. If disabled, the Zero Line is black. If enabled, the Zero Line’s color changes to green or maroon based on the RS line’s angle over time.

  • Display Divergence: Controls the display of divergence dots on the RS line, indicating potential reversal points.

  • Display Filled Area: Controls whether the area between the Zero Line and the RS line is filled with color. The fill color changes based on the relationship of the RS line with the SMA & Zero Line as given below.
    - Dark Green: RS > 0 and RS > MA, indicating strong outperformance.
    - Light Green: RS > 0 and RS < MA, indicating weakening outperformance.
    - Dark Red: RS < 0 and RS < MA, indicating strong underperformance.
    - Light Red: RS < 0 and RS > MA, indicating weakening underperformance.

  • Display Sector Name: Controls the display of sector names for NSE F&O securities, helping to plot RS with sectoral indices.


### Key Features:

  • RS Line:
    The RS line represents the relative performance of a security against a benchmark over a specified period (default 22). It helps traders identify whether the security is outperforming or underperforming the benchmark.

  • SMA Overlay:
    A Simple Moving Average (SMA) line is plotted over the RS line, with a default period of 11. The SMA provides a smoothed trend of the RS, making it easier to identify consistent performance trends.

  • Trend-Sensitive Zero Line:
    The Zero Line’s color adapts based on the RS line’s trend:
    - Green: Positive angle of the RS line, indicating upward momentum.
    - Maroon: Negative angle, indicating downward momentum.
    The color can be toggled, with an option to display the Zero Line in black.

  • Divergence Detection:
    Automatically detects and highlights divergences.
    - Positive Divergence: RS line rises while the price falls, marked by blue dots.
    - Negative Divergence: RS line falls while the price rises, marked by black dots.

  • Color-Coded Fill Area:
    The area between the RS line and the Zero Line is filled with color to visually distinguish different market conditions, with Dark and Light colors providing insight into the strength of the performance:
    - Dark Green: Indicates strong outperformance (RS > 0 and RS > MA), suggesting the security is showing significant strength compared to the benchmark.
    - Light Green: Indicates weakening outperformance (RS > 0 and RS < MA), signaling that while the security is still outperforming, its strength is diminishing.
    - Dark Red: Indicates strong underperformance (RS < 0 and RS < MA), showing the security is significantly weaker than the benchmark.
    - Light Red: Indicates weakening underperformance (RS < 0 and RS > MA), suggesting the security is still underperforming but may be regaining some strength.

  • Sectoral Strength:
    Displays sector names for NSE F&O securities, helping users to compare the RS of individual securities with their respective sectoral indices. Comparative Security can be changed easily based on this sector name. Users need not to remember sector names for individual securities.
    If any security is not categorized in a specific sector, CNX500 has been considered as a default sector for NSE F&O securities. For other securities, NIFTY50 has been considered as a default sector.

เอกสารเผยแพร่
### Enhancements - December 2024:

  • New F&O Scripts: Updated newly added F&O scripts by NSE and their sector names.

  • Color Selection: Provided color selection options for RS line, Zero line, Divergence, and Sector Name for F&O script - to help rendering in different background colors.

  • Sector Name Text Color: Default color changed from black to blue to avoid display problems with dark theme.

เอกสารเผยแพร่
### Enhancements - 16 December 2024:

  • Pine Script Version 6.0:
    The code has been updated to Pine Script Version 6.0 for improved performance, compatibility, and access to the latest scripting features like dynamic requesting.

  • Benchmark Selection:
    Two benchmark options are now available to calculate relative strength:
    - NIFTY50 (Default): Relative Strength will be calculated against the NIFTY50 index by default or against a custom Comparative Symbol provided by the user.
    - NSE Sectoral Index: For NSE F&O stocks, Relative Strength is calculated against their respective NSE Sectoral Indices. If the sector for a specific stock is unknown, or for non-F&O stocks and indices, the NIFTY500 (CNX500) will be used as the benchmark.
    This enhancement allows for convenient comparison of F&O stocks against both the NIFTY50 index and their respective sectoral indices, offering deeper performance insights.

  • Divergence Lines:
    Divergence lines can now be plotted, similar to other oscillator indicators like RSI.
    - Regular & Hidden Divergence: The display of regular and hidden divergences can be toggled ON or OFF through a dedicated input option.
    - Customizable Parameters: Several input parameters allow fine-tuning of the divergence detection like Left & Right Pivot Lookback Period and Minimum & Maximum Lookback Range.
    This feature enables traders to visually identify trend reversal signals and continuation patterns effectively.

  • MA Line: The Moving Average (MA) Line is now OFF by default. Users can enable or disable it through the provided input option as needed.

  • Divergence Dots:
    - The previous divergence markers (blue and black dots) are now explicitly referred to as "Divergence Dots" in the input parameters.
    - This naming update ensures there is no confusion between Divergence Dots and the newly introduced Divergence Lines.

outperformancerelativestrengthRelative Strength Comparisonunderperformance

สคริปต์โอเพนซอร์ซ

ด้วยเจตนารมณ์หลักของ TradingView ผู้เขียนสคริปต์นี้ได้เผยแพร่เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถเข้าใจและตรวจสอบได้ ต้องขอบคุณผู้เขียน! ที่ให้คุณใช้ได้ฟรี แต่การนำโค้ดนี้ไปใช้ในการเผยแพร่ซ้ำจะต้องอยู่ภายใต้ กฎระเบียบการใช้งาน คุณสามารถตั้งเป็นรายการโปรดเพื่อใช้บนชาร์ตได้

ต้องการที่จะใช้สคริปต์นี้บนชาร์ตใช่ไหม?


และใน:

คำจำกัดสิทธิ์ความรับผิดชอบ