Sharing investing and trading ideas. Helping traders get started.

Tuesday, June 30, 2009

Chande Momentum Oscillator

Chande Momentum Oscillator CMO
Comes with formula, calculation steps and VBA code

The Chande momentum oscillator is calculated as follows.

CMO= (Sum of all positive Changes in Price – Absolute Sum of all negative Changes in Prices) / (Sum of all positive Changes in Price + Absolute Sum of all negative Changes in Prices), over n periods.

, where Today’s Change in Price = Today’s Price – Yesterday’s Price

VBA Code
Below are two different methods for calculating the Chande momentum oscillator. Method A creates a user defined function CMO. It returns the oscillator using n+1 periods of historical prices. Method B is a subroutine which is more efficient for large datasets. It outputs two columns of data - the daily change in price and the Chande momentum oscillator.

Method A
Sub AddUDF()
Application.MacroOptions macro:="CMO", _
Description:="Returns the Chande Momentum Oscillator" & Chr(10) & Chr(10) & _
"Select n+1 periods of prices", _
Category:="Technical Indicators"
End Sub

Public Function CMO(close_)
n = WorksheetFunction.Count(close_) - 1
sumpos = 0
sumneg = 0
For a = 1 To n
chg = close_(a + 1, 1) - close_(a, 1)
If chg > 0 Then
sumpos = sumpos + chg
sumneg = sumneg + chg
End If
Next a
sumneg = Abs(sumneg)
CMO = (sumpos - sumneg) / (sumpos + sumneg)
End Function

Method B
Sub Runthis()
Dim close1 As Range, output As Range, n As Long

Set close1 = Range("E2:E11955")
Set output = Range("H2:H11955")

n = 5 'number of historical periods to look at
'needed for certain indicators

CMO_1 close1, output, n
End Sub
Sub CMO_1(close1, output, n)
Closetoday = close1(2, 1).Address(False, False)
CloseYesterday = close1(1, 1).Address(False, False)
output(0, 1).Value = "Change"
output(2, 1).Value = "=" & Closetoday & "-" & CloseYesterday
output(2, 1).Copy output
output(1, 1).Clear
sumrange = Range(output(2, 1), output(n + 1, 1)).Address(False, False)
output(0, 2).Value = "CMO"
output(n + 1, 2).Value = "=SUM(" & sumrange & ")/(SUMIF(" & sumrange & "," & """>0"")+abs(sumif(" & sumrange & "," & """<0"")))"
output(n + 1, 2).Copy output.Offset(0, 1)
Range(output(1, 2), output(n, 2)).Clear
End Sub

Other references

Like what you have just read? Digg it or Tip'd it.
The objective of Finance4Traders is to help traders get started by bringing them unbiased research and ideas. Since late 2005, I have been developing trading strategies on a personal basis. Not all of these models are suitable for me, but other investors or traders might find them useful. After all, people have different investment/trading goals and habits. Thus, Finance4Traders becomes a convenient platform to disseminate my work...(Read more about Finance4Traders)


Post a Comment