ta-lib-python icon indicating copy to clipboard operation
ta-lib-python copied to clipboard

multiple calculations returning incorrect results

Open K-Kit opened this issue 6 years ago • 4 comments

Hello, I've spent all morning trying to figure out if i'm making some mistake or if its an issue with ta-lib. My CMO inputs have been relatively accurate when close to 0 but the minimums and maximums have been significantly different. I scaled the values up to deal with rounding errors and tried pulling 6,000 candles to deal with the unstable period. If anyone could help me out it would be much appreciated.

here's my code and the CMO is plotted at the bottom, https://gist.github.com/K-Kit/511107c4d617fb11d4330cfa2bb433e9 image

and here's a snapshot of the tradingview for roughly the same time period image

The min and max of the last ~24 hours should have been +/- 80 but its outputting +/-46

edit: I've also tried normalizing the data, just tried reading over the C code and i don't see what could cause the issue although I'm not very experienced in C

K-Kit avatar May 21 '18 19:05 K-Kit

I was able to get a much closer result using this https://github.com/kylejusticemagnuson/pyti/blob/master/pyti/chande_momentum_oscillator.py

still no luck figuring out what's happening with the ta-lib CMO calc

heres a comparison of the 2 the bottom being the pyti version (apologies for the poor labeling)

image

Tested against MFI and got very similar results but still slightly different but reasonable image

(sorry for all the images if theres a cleaner way to format this i'm open to suggestions)

K-Kit avatar May 23 '18 15:05 K-Kit

any luck on fixing or replacing CMO?

Elyasnz avatar May 23 '23 10:05 Elyasnz

i have managed to create a CMO indicator (with the help of pandas_ta) identical to tradingview CMO using the code below

mom = data.close.diff()
positive = mom.copy().clip(lower=0).rolling(self.timeperiod).sum()
negative = mom.copy().clip(upper=0).abs().rolling(self.timeperiod).sum()
cmo = 100 * (positive - negative) / (positive + negative)

hope it helps :)

Elyasnz avatar May 23 '23 10:05 Elyasnz

for a little more in depth look check this comment

Elyasnz avatar May 24 '23 08:05 Elyasnz