TradingView
tkarolak
1 Th09 2023 10:43

ATR Adaptive RSI Oscillator 

BTCUSDT Perpetual ContractBybit

Mô tả

The "ATR Adaptive RSI Oscillator" is a versatile technical analysis tool designed to help traders make informed decisions in dynamic market conditions. It combines the Relative Strength Index (RSI) with the Average True Range (ATR) to provide adaptive and responsive insights into price trends.

Key Features:

  • Adaptive RSI Periods: The indicator introduces the concept of adaptive RSI periods based on the ATR (Average True Range) of the market. When enabled, it dynamically adjusts the RSI calculation period, offering longer periods during high volatility and shorter periods during low volatility. This adaptability enhances the accuracy of RSI signals across varying market conditions.

  • Volume-Based Smoothing: The indicator includes a smoothing feature that computes a time-decayed weighted moving average of RSI values over the last two bars, using volume-based weights. This approach offers a time-sensitive smoothing effect, reducing noise for a clearer view of trend strength compared to the standard RSI.

  • Divergence Detection: Traders can enable divergence detection to identify potential reversal points in the market. The indicator highlights regular bullish and bearish divergences, providing valuable insights into market sentiment shifts.

  • Customizable Parameters: Traders have the flexibility to customize various parameters, including RSI length, adaptive mode, ATR length, and divergence settings, to tailor the indicator to their trading strategy.

  • Overbought and Oversold Levels: The indicator includes overbought (OB) and oversold (OS) boundary lines that can be adjusted to suit individual preferences. These levels help traders identify potential reversal zones.


The "ATR Adaptive RSI Oscillator" is a powerful tool for traders seeking to adapt their trading strategies to changing market dynamics. Whether you're a trend follower or a contrarian trader, this indicator provides valuable insights to support your decision-making process.

Phát hành các Ghi chú

Change Log:

1. Some bug fixes

2. Added logic to enhance the calculation of dynamic/adaptive RSI length, now derived from a Normal Distribution based on a larger data sample.
Normal Distribution: The Normal Distribution is a statistical concept used to model the distribution of data. It is characterized by two key parameters: the mean (average) and the standard deviation (a measure of data dispersion).

  • Identifying Data Points (ATR) : The primary objective of utilizing this dataset and Normal Distribution is to identify specific data points that meet predefined criteria.
  • Criteria Exceeding One Standard Deviation (1st Z-Score Range): The selection criteria involve identifying ATRs that deviate from the mean by more than one standard deviation. In simpler terms, we focus on data points that fall outside the range of one standard deviation above and below the mean.
  • Adaptive RSI Length: The adaptive RSI length is dynamically determined based on the characteristics of the dataset and the criteria mentioned above. Specifically, when data points exceed one standard deviation from the mean, indicating increased volatility or divergence from the norm, the RSI calculation period is adjusted. This adaptive approach ensures that the RSI indicator responds effectively to changing market conditions."

Phát hành các Ghi chú

Bugfix: The 'over1ZscoreAtr' array, which was previously limited to 100, has now been configured to match the 'i_sampleSize' input

Phát hành các Ghi chú

  • Added z-score. The Z-scores multiplier acts as a filtering mechanism, offering insights into the degree to which each data point (ATR) deviates from the mean in terms of standard deviations.
  • Made minor changes and added input constraints.

Phát hành các Ghi chú

Code refactor
  • Code Refactor
  • Added dynamic color for "RSI plot".
  • Added a switch to control the appearance of the RSI length boost histogram.

Phát hành các Ghi chú

Bug fixes

Phát hành các Ghi chú

changed z-score default value to 2

Phát hành các Ghi chú

Added original RSI plot

Phát hành các Ghi chú

  • Code refactor
  • Incorporated an indicator description as comments within the code to provide better context and understanding

Phát hành các Ghi chú

Technical Optimizations:

  • Normalized ATR values to align with the boosted range of RSI lengths, refining the adaptive mechanism.
  • Simplified RSI calculations for various periods and implemented a new method for adaptive length determination based on ATR conditions.


Code Refinements:

  • Adopted camelCase naming convention throughout the script for improved readability and standardization.
  • Added minimalistic and informative comments to aid in understanding the script's functionality.

Phát hành các Ghi chú

Minor bug fixes

Phát hành các Ghi chú

Function to Calculate Dynamic Length for ATR Adaptive Indicators added

Phát hành các Ghi chú

Code refactor

Phát hành các Ghi chú

Change Log:

  • Improved RSI calculation efficiency and accuracy.
  • Optimized code for faster execution and better resource management.

Phát hành các Ghi chú

Changes include:

  • Improvements to the non-adaptive mode functionality.
  • Resolved issues with runtime errors.
  • Enhanced data collection for the default length when not using adaptive mode.

Phát hành các Ghi chú

Updated documentation for functions (documentation strings)
Bình luận
rajeshdvaishnav
The issue with this indicator is that it is, even though we set the RSI to be calculated using ATR, but ATR values is always returning higher than maxLength, so it is always drawing the RSI for length = maxLength, not for dynamic ATR
tkarolak
@rajeshdvaishnav, I will check on this, what timeframe?
tkarolak
@rajeshdvaishnav, I've updated the method for calculating dynamic length. It should work properly now. Please remove it from your favorites and add it back.
rajeshdvaishnav
@tkarolak,Hey
Even after update, the issue is same on all timeframe,
For eg, if we set maximum length to 1+default rsi length then the grpah is identical, for both normal rsi as well as default RSI,
Where as
if RSI is adaptive then above should not be the case.

Let me know if some more clearity is needed
tkarolak
@rajeshdvaishnav, what you're seeing is expected. If the default length is set at 14 and the maximum at 15, the length will only vary slightly between these two values, making the graphs nearly identical.
rajeshdvaishnav
@tkarolak, yes understood,
But if you increase the max length let's suppose you increase the max length to 40
Then as per you, the RSI should be calculated on dynamic length, but it is not, it is calculated at length 40, you can verify by adjusting original RSI length to 40 or 39 the graph is same, which should not be the case if indicator is calculating RSI on dynamic length
tkarolak
@rajeshdvaishnav, in the adaptive mode the silver plot / line represents the RSI for default length, if you would like to compare the plot of e.g. the value of max length, you can load a copy of this indicator or RSI Divergence Indicator (tradingview build-in) and set it to 40. Remember to uncheck the somoothing option. In my opinion, now everything is fine... The adaptive is adaptive and not the max length plot.
rajeshdvaishnav
@tkarolak, Heyp

Simplest way to check if it's working fine or not is to do following,
On any chart at any given candle
Comapre the ADAPTIVE RSI value, provided by indicator with Normal RSI value calculated on lengh = max length (Using RSI indicator provided by TV)

If both are the same then this indicator is not doing what it is supposed to do
if both are diffrent then it's working fine
rafaelbrown40
Thank you. It rocks!
tkarolak
@rafaelbrown40, I've uploaded a new version of the indicator. To access it, please first remove the current version from your favorites, and then add the new one again.
Thêm nữa