Saturday, September 04, 2010

Chande Momentum Oscillator [CMO]

Descripton
Summary:
This indicator script is a price momentum oscillator based on a modified version of the RSI indicator.

Calculation:
The difference between the sum of all recent gains and the sum of all recent losses divided by the result by the sum of all price movement over the period. 

Developer:
Tushar S. Chande

Interpretation: 
1. Overbought:  When the underlying indicator is moving upwards, but the indicator script is approaching its upper bound, the underlying indicator is likely to reverse direction and move downwards.
2. Oversold: When the underlying indicator is moving downwards, but the indicator script is approaching its lower bound, the underlying indicator is likely to reverse direction and move upwards.



Variables
TypeIdentifierDescription
Integer_indicatorKeyUse for the underlying indicator key on which to calculate the result indictor.
Integer_periodsUse for the number of periods to include in the Chande Momentum Oscillator calculation.

OnInitialize
Function Parameters
TypeIdentifierDescription
IndicatorindicatorKeyUse for the underlying indicator key on which to calculate the result indictor.
IntegerperiodsUse for the number of periods to include in the Chande Momentum Oscillator calculation. [Default 10]
Implementation
	 ' Assign the parameters to script variables.
	_indicatorKey = indicatorKey
	_periods = periods

OnValues
Function Parameters
TypeIdentifierDescription
IntegerbarIndex
Integerlength
Implementation
	 ' Get the underlying indicator values, indexed by bar index.
	Define values() As Number = IndicatorValues(_indicatorKey,barIndex,length + _periods + 1)
	 ' Use for summming.
	Define sum1, sum2 As Number
	 ' Use for the calculated Chande Momentum Oscillator indicator values, indexed by bar index.
	Define results(length - 1) As Number
	 ' Calculate the Chande Momentum Oscillator values for the specified bar range.
	For i As Integer = length - 1 To 0 Step -1
		 ' Calculate the Chande Momentum Oscillator value for the current bar.
		sum1 = 0
		sum2 = 0
		For j As Integer = i + _periods - 1 To i Step -1
			If (values(j) > values(j+1)) Then
				sum1 = sum1 + (values(j) - values(j+1))
			Else
				sum2 = sum2 - (values(j) - values(j+1))
			End If
		Next
		 ' Assign the Chande Momentum Oscillator value for the current bar.
		results(i) = ((sum1 - sum2) / (sum1 + sum2)) * 100
	Next
	Return results

Copyright © 2010 IQBroker, LLC. All rights reserved.