Skip to content

fix: qtpylib cci uses mean deviation over the window - #855

Closed
jayhemnani9910 wants to merge 1 commit into
freqtrade:mainfrom
jayhemnani9910:fix/qtpylib-cci-mean-deviation
Closed

jayhemnani9910 wants to merge 1 commit into
freqtrade:mainfrom
jayhemnani9910:fix/qtpylib-cci-mean-deviation

Conversation

@jayhemnani9910

Copy link
Copy Markdown

qtpylib.cci divided by np.std of the whole rolling-mean column instead of the mean deviation over the window. The values were on the wrong scale, so the usual ±100 levels stopped meaning anything: on 500 random candles the last bar read -24.3 where TA-Lib CCI gives -156.0. A past bar's value also changed as later candles came in.

It now uses the rolling mean absolute deviation and matches TA-Lib CCI on the 1m BTC test data. The new test fails before the change and passes after. The rest of the suite passes; I left out test_pip_audit, which audits the installed packages.

np.std of the whole rolling-mean column put CCI on the wrong scale and
made past bars change with later candles.
@xmatthias xmatthias added the AI Slop Issue or PR partially or completely generated by AI label Nov 10, 2026

@xmatthias xmatthias left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the need to point you to our AI contributing policy - which clearly states:

Never let an LLM speak for you - all comments, issues and PR descriptions should be written in your own words, reflecting your own understanding.

We expect everyone in this org to follow this - otherwise we'll be limiting your interactions with this organization.


If we assume that the calculation should match ta-lib - we should call ta-lib instead of reimplementing the calculation "by hand".
maybe even marked with a comment about deprecation to use Ta-lib directly.

I'll be closing this here as i think this has to be redone from scratch (essentially every line here will need changing) - though i'll keep the issue open as it reports a real issue.

Comment thread tests/test_indicators.py
assert rma(dataframe, 5).isna().all()


def test_qtpylib_cci_matches_talib(testdata_1m_btc):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't cover actual problems (constant prices return NaN here - ta-lib returns 0.0).
There's also floating point errors depending on values - so it's may be matching ta-lib for this particular scenario - but that statement doesn't generalize.

It's also tons of times slower (as data amount increases).

@xmatthias xmatthias closed this Nov 10, 2026
@jayhemnani9910
jayhemnani9910 deleted the fix/qtpylib-cci-mean-deviation branch November 13, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI Slop Issue or PR partially or completely generated by AI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants