Saturday, September 04, 2010

Cumulative Volume Index [CVI]

Descripton
Summary:
This indicator script measures market momentum to illustrate money flows in and out of an exchange.

Calculation:
The cumulative difference between the volumes of advancing and declining symbols of the specified exchange.

Developer:
Steven B. Achelis

Interpretation:
1. Upwards Trend: When the indicator script is moving upwards, the underlying exchange is in an upwards trend.
2. Downwards Trend: When the indicator script is moving downwards, the underlying exchange is in a downwards trend.
3. Positive Divergence:  When the underlying exchange is moving downwards, but the indicator script is moving upwards, the underlying exchange is likely to reverse direction and move upwards.
4. Negative Divergence:  When the underlying exchange  is moving upwards, but the indicator script is moving downwards, the underlying exchange is likely to reverse direction and move downwards.


Variables
TypeIdentifierDescription
String_exchangeIDUse for the exchange ID of the symbols to include in the Cumulative Volume Index calculation. (i.e. NYSE, LSE, NASDAQ)

OnInitialize
Function Parameters
TypeIdentifierDescription
StringexchangeIDUse for the exchange ID of the symbols to include in the Cumulative Volume Index calculation. (i.e. NYSE, LSE, NASDAQ) [Default NYSE]
Implementation
	 ' Assign the parameter to a script variable and make sure it is in upper case.
	_exchangeID = StringToUpper(exchangeID)
	 ' Find a symbol index that matches the specified exchange ID.
	Define symbolIndex As Integer = -1
	For i As Integer = 0 To SymbolCount() - 1
		If (SymbolExchangeID(i) = _exchangeID)
			symbolIndex = i
		End If
	Next
	 ' Initialize the indicator index.
	IndicatorIndex(symbolIndex)

OnValues
Function Parameters
TypeIdentifierDescription
IntegerbarIndex
Integerlength
Implementation
	 ' Use for the volume of advancing symbols, indexed by bar index. 
	Define advancing(length - 1) As Integer
	 ' Use for the volume of declining symbols, indexed by bar index.
	Define declining(length - 1) As Integer
	 ' Use for the calculated indicator values, indexed by bar index.
	Define results(length - 1) As Number
	 ' Iterate over all of the symbols in the group.
	For symbolIndex As Integer = 0 To SymbolCount() - 1
		 ' Only process symbols that belong to the specified exchange.
		If (SymbolExchangeID(symbolIndex) = _exchangeID) Then
			 ' Get the opening prices of the current symbol, indexed by bar index.  
			Define open() As Number = BarOpen(symbolIndex, barIndex, length)
			 ' Get the closing prices of the current symbol, indexed by bar index. 
			Define close() As Number = BarClose(symbolIndex, barIndex, length)
			 ' Get the volume of the current symbol, indexed by bar index.  
			Define volume() As Number = BarVolume(symbolIndex, barIndex, length)
			 ' Iterate over all of the symbol bars while counting the advancing and declining volumes.
			For i As Integer = length - 1 To 0 Step -1
				If (close(i) > open(i)) Then
					advancing(i) += volume(i)
				Else If (close(i) < open(i)) Then
					declining(i) +=  volume(i)
				End If
			Next
		End If
	Next

	Define indexValue As Number = IndicatorIndexValue()
	 ' Calculate the Cumulative Volume Index values for the specified bar range.
	For i As Integer = length - 1 To 0 Step -1
		 ' Calculate the Cumulative Volume Index value for the current bar.
		indexValue = indexValue + (advancing(i) - declining(i))
		results(i) = indexValue
	Next
	Return results

Copyright © 2010 IQBroker, LLC. All rights reserved.