RSI

Modified on 2010/08/25 10:55 by Eugene — Categorized as: Standard Indicators

Syntax

public RSI(DataSeries ds, int period, string description)
public static RSI Series(WealthLab.DataSeries ds, int period)

Parameter Description

ds The source DataSeries
period Indicator calculation period

Description

The RSI function returns the Relative Strength Index indicator. RSI is one of the classic momentum indicators and was developed by Welles Wilder. RSI measures a market's internal strength by dividing the average of the sum of the up day closing prices by the the average of the sum of the down day closing prices over a specific period of time. It returns a value within the range of 0 to 100. The RSI is a leading or a coincidental indicator. Popular averaging periods for the RSI are 9, 14 and 25. Wilder used 14 periods. The indicator becomes more volatile and amplitude widens with fewer periods used.

Interpretation


Remarks


Calculation

RSI = 100 - ( 100 / ( 1 + RS ) )

where,

RSI relative strength index
RS = (average of n bars' up closes) / (average of n bars' down closes)
n = number of bars or period, typically 14


Note in calculating the RS values for the total of closes up, add all price changes where the close is greater then previous close. For closes down, add all price changes where the close is less then previous close.

Finally, the RSI formula may be found in some technical references as the following equivalent expression:

RSI = 100 * UpDaysAvg / ( UpDaysAvg + DownDaysAvg )

Example

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { // Thank you fundtimer public Color WS4ColorToNET( double WS4Color ) { return Color.FromArgb( (int)Math.Floor( ( WS4Color % 1000 ) / 100 * 28.4 ), (int)Math.Floor( ( WS4Color % 100 ) / 10 * 28.4 ), (int)Math.Floor( WS4Color % 10 * 28.4 ) ); } protected override void Execute() { // This script colors each bar based on the RSI oversold/overbought level DataSeries rsi = RSI.Series( Close, 14 ); double x = 0; double col = 0; // RSI is an "unstable" indicator; consult Language Guide for(int bar = 14*3; bar < Bars.Count; bar++) { x = rsi[bar]; if( x > 50 ) { x -= 50; x *= 2; x /= 9; col = Math.Truncate( x ) * 100; } else { x = 50 - x; x *= 2; x /= 9; col = Math.Truncate( x ) * 10; } SetBarColor( bar, WS4ColorToNET(col) ); }

ChartPane RSIPane = CreatePane( 35, true, true ); SetPaneMinMax( RSIPane, 0, 100 ); PlotSeries( RSIPane, rsi, Color.Red, WealthLab.LineStyle.Solid, 1 ); } } }