﻿Random Walk Index

# Random Walk Index

The Random Walk Index (Rwi) is used to determine if a financial security is trending or in a random trading range by comparing it to a straight line.  The more random the price movement, the more the Rwi fluctuates.  The short-term (2 to 7 periods) Rwi is an overbought/oversold indicator, while the long-term (8 to 64 periods) RWI is a trend indicator.  A financial security is trending higher if the RWI of the highs is greater than 1, while a downtrend is indicated if the Rwi of the lows is greater than 1.

Market Signals

A buy signal is generated when the long-term Rwi of the highs is greater than 1 and the short-term Rwi of the lows rises above 1.  A sell signal is generated when the long-term Rwi of the lows is greater than 1 and the short-term Rwi of the highs rises above 1.

Calculation

where Atr is the average true range over N periods preceding the current period. On each bar the calculation is repeated varying N from 2 to the maximum look back. The highest value becomes this bar’s Rwi value.

There are two periods: fast (short) period and slow (long) period. RWLow and RWHigh are calculated for all  using the formulas above. After that the maximum value for low and high are chosen. These will be LongRwiHigh and Long RwiLow.

The same process is implemented for  to find ShortRwiHigh and ShortRwiLow.

Chart Example

Implementation and Usage

To initialize Rwi use one of the following constructors:

Rwi – sets default values: fastPeriod = 7, slowPeriod = 64.  Fast period corresponds to short-term RWI, and slow period corresponds to long term RWI.

Rwi(Int32, Int32) – sets value for period

Use

LongRwiHigh

LongRwiLow

ShortRwiHigh

ShortRwiLow

properties to get current value

Example
C#
``` 1// Create new instance
2Rwi rwi = new Rwi(10, 40);
3
4// Number of stored values
5rwi.HistoryCapacity = 2;
6
7// Add new data point
8rwi.Add(Bars.Current.Open, Bars.Current.High, Bars.Current.Low, Bars.Current.Close, Bars.Current.Volume);
9
10// Get indicator value
11double IndLongHighValue = rwi.LongRwiHigh;
12double IndLongLowValue = rwi.LongRwiLow;
13double IndShortHighValue = rwi.ShortRwiHigh;
14double IndShortLowValue = rwi.ShortRwiHigh;
15// Get previous values
16if (rwi.HistoryCount == 2)
17{
18    double IndPrevLongHighValue = rwi[1].LongRwiHigh;
19    double IndPrevLongLowValue = rwi[1].LongRwiLow;
20    double IndPrevShortHighValue = rwi[1].ShortRwiHigh;
21    double IndPrevShortLowValue = rwi[1].ShortRwiHigh;
22}```