Implementing a Customizable RSI Indicator in ProBuilder

31 May 2020
0 comment
0 attachment

This code snippet demonstrates how to implement a Relative Strength Index (RSI) indicator in ProBuilder, which can be displayed with or without its traditional 0-100% scale. The RSI is a popular momentum oscillator used in technical analysis that measures the speed and change of price movements.

// RSI custom (with & without scale)
// (https://www.prorealcode.com/topic/indicatore-rsi/#post-51250)
// (https://www.investopedia.com/terms/r/rsi.asp)
//
// p = 14 //periods
p = max(1,min(p,999)) //1 - 999
Ob = 70 //OverBought
Os = 100 - Ob //OverSold
Middle = 50 //mean line
//
// r = 0
// g = 0
// b = 255
// t = 255
//
// Bullish = MAX(0, CLOSE - CLOSE[1])
// Bearish = MAX(0, CLOSE[1] - CLOSE)
//
// mmBullish = WILDERAVERAGE[p](Bullish)
// mmBearish = WILDERAVERAGE[p](Bearish)
//
// RS = mmBullish / mmBearish
IF ScaleEnabled THEN
    myRSI = 100 - (100 / (1 + RS)) //scale
ELSE
    MyRSI = RS //no scale
    t = 0
    Ob = MyRSI
    Os = MyRSI
    Middle = MyRSI
ENDIF
//
// RETURN MyRSI AS "Rsi",Os coloured(r,g,b,t) AS "Os",Ob coloured(r,g,b,t) AS "Ob", Middle coloured(r,g,b,t) as "Mid"

The code snippet above is structured to calculate and display the RSI in two modes: scaled and unscaled. Here’s a breakdown of its components:

  • Parameter Initialization: The period p is set and constrained between 1 and 999. The overbought (Ob) and oversold (Os) levels are defined, along with a middle line (Middle).
  • Color Settings: Variables for color settings (r, g, b, t) are initialized but not altered in the snippet provided.
  • Calculation of Bullish and Bearish Values: These are calculated by comparing the current close price with the previous close price. The Wilder’s Moving Average is applied to both.
  • RS Calculation: The Relative Strength (RS) is calculated by dividing the average gain (mmBullish) by the average loss (mmBearish).
  • Conditional RSI Calculation: If ScaleEnabled is true, the traditional RSI formula is used. If false, the RSI is represented by the RS value itself, affecting the display of overbought, oversold, and middle lines to match the RS value.
  • Output: The RSI value and the levels (Os, Ob, Middle) are returned, with color settings applied based on the initial color variables.

This example is useful for understanding conditional statements and custom indicator development in ProBuilder.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/modification-rsi/#post-153896

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.
robertogozzi Master
Roberto https://www.ots-onlinetradingsoftware.com
Author’s Profile

Comments

Search Snippets

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

Snippets Categories

global
35
indicator
133
strategy
171

Recent Snippets

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 [...]
How to Build a Step-Based Trailing Stop That Moves to Break-Even First
strategy
This snippet implements a step trailing stop that advances in fixed increments once price reaches predefined profit [...]
Utilizing Arrays to Track and Compare Indicator Values Within the Same Bar in ProBuilder
indicator
This ProBuilder code snippet demonstrates how to use arrays to compare the values of an indicator (RSI in this case) [...]
Logo Logo
Loading...