#Indicator
'**************************************************************
'*   Asymmetrical Relative Strength Index (ARSI.txt)
'*     by Jeremy Williams
'*	   August 13, 2008
'*
'*	Adapted from Technical Analysis of Stocks and Commodities
'*     October 2008
'*
'*  Summary: 
'*
'*      This RSI calculates its relative strength by averaging the total 
'*		number of up and down bars by their respective counts rather than a
'*		fixed period as in the standard RSI
'*
'*  Parameters:
'*
'*  Periods -  Specifies the number of bars to use in the RSI calculation
'*
'************************************************************** 

#Param "Periods", 14, 1, 100

Dim fUpBar, fDownBar, fUpCount, fDownCount as Single
Dim fUpMove, fDownMove, fUpAvg, fDownAvg as Single
Dim fARS, fARSI as Single
Dim UpAlpha, DownAlpha As Single

fUpCount = fUpCount[1]
fDownCount = fDownCount[1]

'Set our fixed scaling and labels
SetScales(0, 100)
PlotLabel(70)
PlotLabel(30)

'Calculate the Rate of Change
If C >= C[1] then
	fUpMove = C - C[1]
	fUpBar = 1
Else
	fDownMove = Abs(C - C[1])
	fDownBar = 1
End If

'If we do not have enough bars to perform our calculations, initalize our EMAs
If Bar <= 2*Periods+1 Then
	fUpAvg = fUpAvg[1]+fUpMove/Periods
	fDownAvg = fDownAvg[1]+fDownMove/Periods
'We now have enough bars
Else
	'Count the number of up and down bars
	fUpCount = Sum(fUpBar, Periods)
	fDownCount = Sum(fDownBar, Periods)
	'Calculate up and down aplhas for EMA
	UpAlpha = 2/(2*fUpCount+2)
	DownAlpha = 2/(2*fDownCount+2)
	'Calculate EMAs for ROC
	fUpAvg = UpAlpha*fUpMove+(1-UpAlpha)*fUpAvg[1]
	fDownAvg = DownAlpha*fDownMove+(1-DownAlpha)*fDownAvg[1]
	
	'Calculate asymmetrical relative strength
	fARS = fUpAvg/fDownAvg

	'Calculate the indicator
	fARSI = 100-(100/(1+fARS))
	
	Plot("ARSI", fARSI, Green)
End If

Return fARSI