Implementing On-Chart RSI with Dynamic Overbought and Oversold Levels in ProBuilder

03 Mar 2017
0 comment
0 attachment

This code snippet demonstrates how to implement an on-chart Relative Strength Index (RSI) with dynamic overbought and oversold levels using the ProBuilder language. The RSI is a popular momentum oscillator used in technical analysis that measures the speed and change of price movements.

//PRC_OnChart RSI | indicator
//25.10.2019
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
// --- settings
rsiperiod=14
ATRperiod = 20
maPeriod = 20
maMethod = 0
overBought = 70
overSold = 30
// --- end of settings
maPrice = customclose
dTR = 0
for i = 0 to ATRperiod-1
    dTR=dTR+max(abs(Dhigh(i)-Dlow(i)),max(abs(Dhigh(i)-Dclose(i+1)),abs(Dlow(i)-Dclose(i+1))))
next
avgRange = dTR/ATRperiod
maValue = average[maPeriod,maMethod](maPrice)
rsivalue = rsi[rsiperiod](maPrice)
//---- Buffer1=maValue
Buffer2=maValue+(avgRange*(overBought-50)/100)
Buffer3=maValue-(avgRange*(50- overSold)/100)
Buffer4=maValue+(rsivalue -50)/100*avgRange
return Buffer1 style(dottedline,1) as "mid level",
       Buffer2 style(dottedline,1) as "overbought level",
       Buffer3 style(dottedline,1) as "oversold level",
       Buffer4 coloured(0,255,0) style(line,2) as "OnChart RSI"

Explanation of the Code:

  • Settings: The initial part of the code defines various parameters such as the RSI period, ATR period, moving average period and method, and thresholds for overbought and oversold conditions.
  • Calculating the Average True Range (ATR): The code calculates the ATR, which is used to adjust the overbought and oversold levels dynamically based on market volatility. This is done using a loop that sums the greatest of the following for each period: the absolute difference between the high and low, the high and the previous close, and the low and the previous close.
  • Moving Average and RSI Calculation: The moving average of the closing prices is calculated, followed by the RSI of the closing prices.
  • Buffers for Plotting: Four buffers are defined to store the values for plotting:
    • Buffer1 stores the moving average value (mid level).
    • Buffer2 and Buffer3 calculate the dynamically adjusted overbought and oversold levels based on the ATR.
    • Buffer4 adjusts the RSI value to be plotted on the chart, scaled by the average range.
  • Return Statement: The return statement plots these values on the chart with specific styles and colors, making it visually intuitive.

This code is a practical example of how to enhance traditional RSI indicators by incorporating market volatility into the overbought and oversold levels, providing a more adaptive tool for technical analysis in trading systems.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/rsi-sul-prezzo-2/#post-111226

Visit Link
What is a Snippet? A snippet is a small, reusable chunk of code designed to solve specific tasks quickly. Think of it as a shortcut that helps you achieve your coding goals without reinventing the wheel. How to Use: Simply copy the snippet and paste it into your project where needed. Don't forget to tweak it to fit your context. Snippets are not just time-savers; they're also learning tools to help you become a more efficient coder.
Nicolas Legend
I created ProRealCode because I believe in the power of shared knowledge. I spend my time coding new tools and helping members solve complex problems. If you are stuck on a code or need a fresh perspective on a strategy, I am always willing to help. Welcome to the community!
Author’s Profile

Comments

Search Snippets

Showing some results...
Sorry, no result found!

Snippets Categories

global
35
indicator
135
strategy
171

Recent Snippets

A multi indicator Dashboard for ProRealTime
indicator
This snippet creates a compact on-chart dashboard that aggregates multiple indicator states into a single, readable [...]
How to Track Up/Down Cumulative Volume Inside Each Candle (Tick Volume Delta)
indicator
This snippet separates the real-time, intra-candle volume into up-volume and down-volume based on whether the last [...]
How to Create a Simple MTF Trend Dashboard with EMA and SMA
indicator
This indicator builds a compact multi-timeframe (MTF) dashboard that shows whether price is trading above or below a [...]
How to Display Per-Bar Volume Accumulation in Real Time (Intrabar Updates)
global
This snippet tracks and displays the current bar’s accumulated volume while the bar is still forming, instead of only [...]
Ticks Counter: Count Tick Updates Per Bar on Tick or Time Charts
global
This snippet counts how many tick updates have occurred for the current bar by incrementing a per-bar counter on each [...]
Logo Logo
Loading...