Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chaikin Money Flow indicator: NaN when positive #144

Open
RolandGuijt opened this issue Jan 14, 2021 · 4 comments
Open

Chaikin Money Flow indicator: NaN when positive #144

RolandGuijt opened this issue Jan 14, 2021 · 4 comments

Comments

@RolandGuijt
Copy link

The CMF only seems to return a negative number or NaN.

@xmatthias
Copy link
Member

CMF is a oscillator, so it is supposed to move to positive and negative.

Also, as almost every indicator, it has a startup period, where values will be NAN.

Testing this on a random dataframe, it does return both <0 and > 0.

What precise version are you using? and what parameters are you calling cmf with?

2021-01-15-072947_799x618_scrot

@RolandGuijt
Copy link
Author

RolandGuijt commented Jan 15, 2021 via email

@xmatthias
Copy link
Member

xmatthias commented Jan 15, 2021

Technical is following the definition chaikin_money-flow1 money_flow_2 - investopedia as far as i can see (feel free to correct me if you think differently based on the code below).

def chaikin_money_flow(dataframe, period=21):
mfm = (
(dataframe['close'] - dataframe['low']) - (dataframe['high'] - dataframe['close'])
/ (dataframe['high'] - dataframe['low'])
)
mfv = mfm * dataframe['volume']
cmf = mfv.rolling(period).sum() / dataframe['volume'].rolling(period).sum()
return cmf

If tradingview calculates differently, then there is nothing we can do to align, really, as their code is closed-source as far as i know, so eventual mistakes in their formulas are hidden from analysis.
Tradingview should however not be seen as reference, but the original papers of indicators should be. If Tradingview deviates from the original version, then this doesn't make "their" version the correct one.

@boschje
Copy link
Contributor

boschje commented Feb 19, 2021

You can see the logic for a Tradingview indicator by clicking on the {} button of the indicator, this is just next to the indicator settings. CMF in Tradingview:

//@version=4
study(title="Chaikin Money Flow", shorttitle="CMF", format=format.price, precision=2, resolution="")
length = input(20, minval=1)
ad = close==high and close==low or high==low ? 0 : ((2*close-low-high)/(high-low))*volume
mf = sum(ad, length) / sum(volume, length)
plot(mf, color=#459915, title="MF")
hline(0, color=#606060, title="Zero", linestyle=hline.style_dashed)

This part ((2*close-low-high)/(high-low))*volume looks wrong to me and does not follow specifications. It is quite easy to make your own indicator in Tradingview. After you click that {} button the "Pine editor" is opened, top right of that editor has a button with 3 dots -> "Make a copy".
https://www.tradingview.com/pine-script-docs/en/v4/Quickstart_guide.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants