Separate each body into an up part and a down part
For each bar, set U = max(close − open, 0) and D = max(open − close, 0). Sum U and D over the latest N bars, including the current bar. Divide the up sum by the total and multiply by 100. This is a ratio of sums, not an average of separate per-bar percentages. TA-Lib implements this rolling body calculation; the thinkorswim reference confirms the open-to-close input distinction.
- With a positive denominator, equal up and down totals give 50, only up bodies give 100, and only down bodies give 0.
- An individual doji adds zero to both totals but still occupies one position in the N-bar window. Its arrival can change IMI by removing an older nonzero body.
| Body condition | U contribution | D contribution |
|---|---|---|
| Close above open | Close − open | 0 |
| Close below open | 0 | Open − close |
| Close equals open | 0 | 0 |