#Indicator
'**************************************************************
'*   RapidRSI (RapidRSI.txt)
'*     by Jeremy Williams
'*	   September 19,2006
'*
'*	Adapted from Technical Analysis of Stocks and Commodities
'*     October 2006
'*
'*  Summary: 
'*
'*      This indicator returns and plots the Rapid RSI indicator,  
'*  as described in "Forex Focus: Relative Spread Strenght As
'*  A Long Term Cyclic Tool" in the October 2006 edition of Technical
'*  Analysis of Stocks and Commodities.
'*
'*  Parameters:
'*
'*  Periods     = Specifies the number of periods to use in the 
'*                         Rapid RSI calculation.
'*
'************************************************************** 
#Param "Periods",14

Dim Diff		As Single
Dim UpChange	As Single
Dim DownChange	As Single
Dim UpSum	 	As Single
Dim DownSum		As Single
Dim myRS		As Single
Dim RRSI		As Single
Dim Denominator As Single

' Calculate the price change
If Bar > 1 Then
	Diff = Close - Close[1]	
	If Diff >= 0 Then
		UpChange = Diff
		DownChange = 0
	Else
		UpChange = 0
		DownChange = 0 - Diff
	End If
End If

' Use Recursive algorithm to calculate up and down sums
If Bar <= Periods + 1 Then
	' Initialization
	UpSum = UpSum[1] + UpChange
	DownSum = DownSum[1] + DownChange
Else
	' Begin Recursion
	UpSum = UpSum[1] + UpChange - UpChange[Periods]
	DownSum = DownSum[1] + DownChange - DownChange[Periods]
End If

' Calculate the ratio of up sum to down sum
If DownSum > 0 Then
myRS = UpSum/DownSum
End If

' Calculate and Plot the Rapid RSI value
Denominator = 1 + myRS
RRSI = 100 - 100/Denominator
Plot("RRSI",RRSI)

' Return the value calculated by the indicator
Return RRSI