Tuesday, September 07, 2010

Accumulation Swing Index [ASI]

Descripton
Summary:
This indicator script is used to measure long term trends.

Calculation:
The cumulative total of the swing index, which attempts to show the real price of the underlying symbol.

Developer:
J. Welles Wilder, jr.

Interpretation: 
1. Upwards Trend: When the indicator script is moving upwards, the underlying symbol is in an upwards trend.
2. Downwards Trend: When the indicator script is moving downwards, the underlying symbol is in a downwards trend.
3. Upwards Momentum: When the indicator script is positive and moving upwards, the underlying symbol has upwards momentum and is likely to continue moving upwards.
4. Downwards Momentum: When the indicator script is negative and moving downwards, the underlying symbol has downwards momentum and is likely to continue moving downwards.
5. Positive Divergence:  When the underlying symbol is moving downwards, but the indicator script is moving upwards, the underlying symbol is likely to reverse direction and move upwards.
6. Negative Divergence:  When the underlying symbol is moving upwards, but the indicator script is moving downwards, the underlying symbol is likely to reverse direction and move downwards.


Variables
TypeIdentifierDescription
Integer_symbolIndexUse for the underlying symbol index on which to calculate the Accumulation Swing Index.
Number_limitMoveUse for the bar price movement limit for a futures contract. Enter a large number for stock symbols, as those have no limit.

OnInitialize
Function Parameters
TypeIdentifierDescription
SymbolsymbolIndexUse for the underlying symbol index on which to calculate the Accumulation Swing Index.
NumberlimitMoveUse for the bar price movement limit for a futures contract. Enter a large number for stock symbols, as those have no limit. [Default 10]
Implementation
	 ' Initialize the indicator as an index indicator.
	IndicatorIndex(symbolIndex)
	 ' Assign the parameters to script variables.
	_symbolIndex = symbolIndex
	_limitMove = limitMove

OnValues
Function Parameters
TypeIdentifierDescription
IntegerbarIndex
Integerlength
Implementation
	 ' Get the opening prices of the underlying symbol, indexed by bar index.
	Define open() As Number = BarOpen(_symbolIndex, barIndex, length + 1)
	 ' Get the highest prices of the underlying symbol, indexed by bar index.
	Define high() As Number = BarHigh(_symbolIndex, barIndex, length + 1)
	 ' Get the lowest prices of the underlying symbol, indexed by bar index.
	Define low() As Number = BarLow(_symbolIndex, barIndex, length + 1)
	 ' Get the closing prices of the underlying symbol, indexed by bar index.
	Define close() As Number = BarClose(_symbolIndex, barIndex, length + 1)
	 ' Get the volume values of the underlying symbol, indexed by bar index.
	Define volume() As Number = BarVolume(_symbolIndex, barIndex, length + 1)
	 ' Get the last Accumulation Swing Index value.
	Define ASI As Number = IndicatorIndexValue()
	 ' Use for various calculations.
	Define swingIndex,upper,R,K,R1,R2,R3,R4 As Number
	
	 ' Use for the calculated Accumulation Swing Index values, indexed by bar index.
	Define results(length - 1) As Number
	 ' Calculate the Accumulation Swing Index values for the specified bar range.
	For i As Integer = length - 1 To 0 Step -1
		 ' Calculate the Accumulation Swing Index value for the current bar.
		If (close(i+1) <> 0) Then
			upper = (close(i) - close(i+1)) + 0.5 * (close(i) - open(i)) + 0.25 * (close(i+1) - open(i+1))
			R1 = MathAbs(high(i) - close(i+1))
			R2 = MathAbs(low(i) - close(i+1))
			R3 = MathAbs(high(i) - low(i))
			R4 = MathAbs(close(i+1) - open(i+1))
			If (R1 >= MathMax(R2, R3)) Then
				R = R1 - (R2 / 2) + (R4 / 4)
			Else If (R2 >= MathMax(R1,R3)) Then
				R = R2 - (R1 / 2) + (R4 / 4)
			Else
				R = R3 + (R4 / 4)
			End If
			K = MathMax(R1,R2)
			If (R <> 0) Then
				swingIndex = (50 * (upper / R) * K) / _limitMove
				If (-100 <= swingIndex And swingIndex <= 100) Then
					ASI += swingIndex
				Else If (swingIndex > 100) Then
					ASI += 100
				Else
					ASI += -100
					ASI += swingIndex
				End If
			End If
		End If
		 ' Assign the Accumulation Swing Index value for the current bar.
		results(i) = ASI
	Next
	Return results

Copyright © 2010 IQBroker, LLC. All rights reserved.