I am calculating indicator data for stock market and am having difficulty calculating Heiken Chaiken Osc because of a variable called 'Accdist' According to google it is calculated like this.
Formula is as follows:
Money Flow Multiplier = [(Close - Low) - (High - Close)] /(High - Low)
Money Flow Volume = Money Flow Multiplier x Volume for the Period
ADL = Previous ADL + Current Period's Money Flow Volume
Python code (using Talib + Numpy + Pandas)
data["cmf"] = (((data["close"] - data["low"]) - (data["high"] - data["close"])) / (data["high"] - data["low"]))
data["cmfv"] = data["cmf"] * data["volume"]
data["accdist"] = data["accdist"].shift(periods=1) + data["cmfv"]
Also tried it in pine script, but no luck there either. Any help would be appreciated.
Money_multiplier = ((close-low) - (high - close)) / (high - low)
Money_volume = Money_multiplier * volume
ADL = ADL[1] + Money_volume
Here is the pinescript code I am trying to emulate as I have indicator working, but need to translate to python(probelem is the accdist variable)
osc = ema(accdist, 3) - ema(accdist, 10)
I ran across this same question and here is what I ended up with using python, numpy and pandas.
I used the formula: Money Flow Multiplier = ((Close value – Low value) – (High value – Close value)) / (High value – Low value)
Money Flow Volume = Money Flow Multiplier x Volume for the Period
CMF = 21-day Average of the Daily Money Flow / 21-day Average of the Volume
Here we read in a basic fx or stock data file: