Skip to content

fix: divide BBI by actual number of calc params - #840

Merged
liihuu merged 1 commit into
klinecharts:mainfrom
NemeZZiZZ:fix/bbi-params-length
Sep 30, 2026
Merged

liihuu merged 1 commit into
klinecharts:mainfrom
NemeZZiZZ:fix/bbi-params-length

Conversation

@NemeZZiZZ

Copy link
Copy Markdown
Contributor

Problem

BBI averages its moving averages over a hard-coded 4 instead of the actual number of parameters:

const maxPeriod = Math.max(...params)   // derived from params
...
bbi.bbi = maSum / 4                      // ← fixed divisor

mas and maxPeriod both follow calcParams, but the divisor does not.

Verified by execution: calcParams: [3, 6, 12] on flat data at 100 yields 75 instead of 100; with 5 params the result is 25% low.

Impact

Any non-default calcParams silently produces wrong BBI values. Default [3, 6, 12, 24] is unaffected.

Fix

maSum / params.length, guarded against an empty calcParams (previously 0/4 = 0; keep 0 rather than NaN).

One line, one file.

@liihuu
liihuu merged commit 6b84d22 into klinecharts:main Sep 30, 2026
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

Successfully merging this pull request may close these issues.

2 participants