ta-lib-python
ta-lib-python copied to clipboard
multiple calculations returning incorrect results
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
and here's a snapshot of the tradingview for roughly the same time period
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
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)
Tested against MFI and got very similar results but still slightly different but reasonable
(sorry for all the images if theres a cleaner way to format this i'm open to suggestions)
any luck on fixing or replacing CMO?
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 :)
for a little more in depth look check this comment