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

Sunday, June 28, 2009

Chaikin Money Flow

Chaikin Money Flow CMF
Comes with formula, calculation steps and VBA code

Introduction

The Chaikin money flow, CMF is calculated as

CMF = Sum of (CLV x Volume) for last n periods / Sum of Volume for last n periods

, where n is specified by the user. (CLV x Volume) is a proxy of money flow in and out of a stock. The numerator, sum of (CLV x Volume) for the last n periods is actually very similar to the Accumulation/Distribution Line, ADL. While the ADL is the cumulative sum of (CLV x Volume) over your entire dataset, CMF only looks at the last n periods of money flow.

More information about ADL and its VBA code can be found 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

'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:="CMF", _ Description:="Returns the Chaikin Money Flow." & Chr(10) & Chr(10) & _
"Select n periods of high, low, close and volume", _ Category:="Technical Indicators"
End Sub

Public Function CMF(high, low, close_, volume)
no0 = volume.Count numerator = 0
For a = 1 To no0
numerator = numerator + ((close_(a, 1) - low(a, 1)) - (high(a, 1) - close_(a, 1))) / (high(a, 1) - low(a, 1)) * volume(a, 1)
Next a
CMF = numerator / WorksheetFunction.Sum(volume)
End Function

Once you are done with the above, you can compute Chaikin money flow by entering into any cell, "=CMF([Current High], [Current Low], [Current Close],[Current Volume])".

Method B
To run Method B, you have to copy the Runthis sub and the CLV sub of Method B from the page on ADL into your module.

'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
CMF_1 high, low, close1, volume, output, n

Sub CMF_1(high As Range, low As Range, close1 As Range, volume As Range, output As Range, n As Long)
output(0, 3).Value = "CMF"
'Calculate CLV first
CLV_1 high, low, close1, output
CLV0 = Range(output(1, 2), output(n, 2)).Address(False, False)
vol0 = Range(volume(1, 1), volume(n, 1)).Address(False, False)
'Calculate CMF
output(n, 3).Value = "=SUMPRODUCT(" & CLV0 & "," & vol0 & ")/SUM(" & vol0 & ")"
output(n, 3).Copy output.Offset(0, 2)
Range(output(1, 3), output(n - 1, 3)).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)

0 comments:

Post a Comment