Sharing investing and trading ideas. Helping traders get started.
Advertisement

Sunday, June 28, 2009

Chaikin Oscillator

Chaikin Oscillator COSC
Comes with formula, calculation steps and VBA code

Introduction

The Chaikin oscillator is very similar to the Chaikin money flow, except that it is actually the difference between two moving averages of the Accumulation/Distribution line or ADL. Some articles uses a simple moving averge, while some propose that an exponential moving average be used instead. I choose the exponential moving average. The Chaikin oscillator is calculated as such:

Chaikin Oscillator=n period EMA of the ADL - k period EMA of the ADL

An n period exponential moving average has a decay factor of 2/(n+1). An article on the exponential moving average, its formula and VBA code can be found here, while the Accumulation/Distribution line and its VBA code is covered in an article here.

VBA Code
Method A uses functions, while Method B uses sub procedures to calculate CMF. Method B is faster and more flexible.

Method A
Insert the VBA code for Method A of the Accumulation/Distribution line.
Insert the VBA code for Method A of the exponential moving average.

Calculate ADL on another column in your spreadsheet either using your own formula or the ADL function provided by me. If you are using my custom functions, you just need to enter into any cell, "=ADL([Last period ADL],[Current High], [Current Low], [Current Close],[Current Volume])" to compute current ADL.

Compute a fast exponential moving average for the ADL. Using my custom function, you enter into any cell, "=EMA([Last Period EMA],[Current ADL],[n])". Enter last period ADL as last period EMA when you are computing the first EMA of your dataset. [n] is your averaging period. Repeat the above with a larger average period. The Chaikin oscillator is the difference between the slow moving average and the fast moving average

If you must have a custom function to work with, you can follow the instructions below. You will still need to insert the VBA code for the ADL and EMA functions. The COSC function is an array function that will output the Chaikin Oscillator, ADL, Fast EMA, Slow EMA.

'Paste this code into your ThisWorkBook code window in VBA. Right Click This WorkBook in Project Explorer and click View Code.
Private Sub Workbook_Open()
AddUDF
End Sub

'The rest belong to any module
Sub AddUDF()
'Tells Excel to includes these in list of functions, add descriptions to them and create a new category called Technical Indicators.
Application.MacroOptions macro:="COSC", _
Description:="Returns Chaikin Oscillaor, current ADL, Fast EMA and Slow EMA." & Chr(10) & Chr(10) & _
"Input current high, low, close, volume, n, k, last period's ADL,fast EMA and slow EMA. n and k are the averaging periods for the fast and slow moving averages respectively.", _
Category:="Technical Indicators"
End Sub

Public Function COSC(high, low, close_, volume, n, k, ADLYesterday, FastEMAYesterday, SLowEMAYesterday)
Dim result(0, 1 To 4)
result(0, 2) = ADLYesterday + CLV(high, low, close_) * volume 'ADL
result(0, 3) = EMA(FastEMAYesterday, result(0, 2), n) 'EMAFast
result(0, 4) = EMA(SLowEMAYesterday, result(0, 2), k) 'EMASlow
result(0, 1) = result(0, 3) - result(0, 4) 'Oscillator
COSC = result
End Function

Once you are done with the above, you can compute Chaikin oscillator by entering into any cell, "=COSC([Current High], [Current Low], [Current Close],[Current Volume],...)". Select the cell and the three cells horizontally next to it, press F2 and Enter to display the full set of outputs.

Method B
To run Method B, you have to copy the Runthis sub and the CLV, ADL and EMA sub of Method B from the page on Accumulation/Distribution line and exponential moving average into your module. You will runthe COSC sub from the Runthis sub.

'Copy the following line into the Runthis sub
'Just before the line End Sub
'Disable all other macros that Runthis will call e.g. CLV, ADL, by
'marking them out as comments with single quotes
COSC_1 high, low, close1, volume, output, n, k

Sub COSC_1(high As Range, low As Range, close1 As Range, volume As Range, output As Range, n As Long, k As Long)
output(0, 6).Value = "Chaikin Oscillator"
'Calculate the ADL and EMA needed
ADL_1 high, low, close1, volume, output
EMA_1 output.Offset(0, 2), output.Offset(0, 3), n
EMA_1 output.Offset(0, 2), output.Offset(0, 4), k
'Calculate Chaikin oscillator
output0 = output(2, 4).Address(False, False)
output1 = output(2, 5).Address(False, False)
output(2, 6).Value = "=" & output0 & "-" & output1
output(2, 6).Copy output.Offset(0, 5)
output(1, 6).Clear
End Sub

Other References
http://www.gannalyst.com/Gannalyst_Professional/Gannalyst_Indicators_ChaikinOscillator.shtml


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)

0 comments:

Post a Comment