Independent market intelligence
Research over noise · Risk before return
FOREX INDICATOR GUIDE

CCI20: typical price and the mean absolute deviation

CCI measures how far the current typical price sits from its recent mean relative to the same window’s mean absolute deviation. Three EUR/JPY H4 examples separate a zero crossing, an upper-zone crossing and a continuing lower-zone state.

In simple terms

For this guide, CCI20 uses the selected completed candle and its 19 preceding observed candles. A positive value places typical price above that window’s mean; a negative value places it below. The size also depends on the window’s dispersion. The conventional ±100 levels describe an indicator state and do not determine the next price move.

On this page
01

Start with typical price, rather than the close alone

Typical price TP is the average of a candle’s high, low and close. The open is not an input. In a synthetic candle with high 112, low 100 and close 109, TP is 107. This is a calculation from the candle, not a claim that a trade occurred at 107. CCI can therefore change even if two candles share the same close.

TP_t = (H_t + L_t + C_t) / 3

02

Use 20 observed candles, including the selected one

Our mean M is the arithmetic average of 20 typical prices: the selected completed candle and its 19 predecessors. CCI20 is a chosen setting, not a universal platform default. The first mean needs 20 observations; the first adjacent-value comparison needs 21, provided both CCI values are defined. Here an observed candle remains in the window across a calendar gap; we do not fill missing intervals or reset the calculation at weekends.

M_t = (TP_(t−19) + … + TP_t) / 20

03

Centre every deviation on the same current mean

Mean absolute deviation MAD is the average of the 20 absolute differences between each TP and the current window’s mean M. Every term uses that same M. This is neither standard deviation nor median absolute deviation. In the synthetic window of ten values of 100, nine of 110 and a final 120, M is 105.5 and MAD is 5.5. The current deviation is 14.5, giving CCI of approximately 175.76 with the exact constant 0.015.

MAD_t = (|TP_(t−19) − M_t| + … + |TP_t − M_t|) / 20
CCI20_t = (TP_t − M_t) / (0.015 × MAD_t); MAD_t > 0

Teaching example: one window, one mean

Teaching example: one window, one meanSynthetic typical priceAbsolute distance from current mean105.51001101205.54.514.5120
Synthetic typical prices: ten values of 100, nine of 110 and a final 120. The shared mean is 105.5; the absolute distances are 5.5, 4.5 and 14.5. Their 20-value average is 5.5, giving CCI of approximately 175.76 for the final observation. These are illustrative values, not market candles.
04

Avoid averaging residuals from different rolling means

SMA20 of the historical values abs(TP_i−SMA20_i) is a different calculation: each term has a different centre. Consider 19 values of 100 followed by 20 values of 110. At the last observation, the current 20-value window is constant, so M is 110 and the correct MAD is 0. The incorrect residual average is 4.75. Here CCI is unavailable when MAD is 0; substituting a denominator from the other method would falsely produce zero. Even nonflat candles can have identical typical prices: twenty candles with high 110, low 90 and close 100 all have TP of 100.

Teaching example: the wrong centre changes the denominator

CalculationCurrent meanDenominator before ×0.015Resulting CCI
Current window, shared mean1100.00Unavailable
Residuals from changing historical means1104.750 · incorrect result
After 19 typical prices of 100 and 20 of 110, the current 20 values all equal 110. Their mean absolute deviation is 0, while averaging residuals around each historical rolling mean gives 4.75. This guide uses the first method to calculate MAD for CCI.
05

Read ±100 as reference levels, not scale endpoints

CCI is not normalized to 0–100. We use strict upper and lower zones: CCI above 100 and CCI below −100. Exactly 100 or −100 lies on a boundary. A large magnitude can reflect a large current deviation, a small MAD, or both; it does not establish that a currency is cheap or expensive. With this precise current-inclusive 20-value formula and positive MAD, arithmetic gives a finite absolute limit of 2000/3, about 666.67. That limit is a property of the formula, not a trading target.

06

Distinguish an upward crossing from a continuing state

An upward zero crossing requires a defined previous CCI at or below 0 and a current value strictly above 0 on completed candles with adjacent scheduled H4 anchors. The upward 100 crossing applies the same rule at 100, with no additional ceiling. Staying below −100 is a state, not a new crossing on every candle. Unavailable readings block a crossing. These descriptive flags do not define order execution, exits or risk.

CCI_prev ≤ 0; CCI_t > 0
CCI_prev ≤ 100; CCI_t > 100

07

Retain the limits of the EUR/JPY source

The pinned HistData Bid source contains 10,592 observed H4 candles from seven annual files. Prices are JPY per EUR. Of these candles, 2,364 contain fewer than 240 source-minute rows; there are 353 calendar gaps between scheduled H4 anchors. A calendar gap need not be a provider error. The provider uses fixed EST without daylight-saving changes; the archived conversion adds five hours to obtain UTC. First and last source-minute stamps are interval labels, not individual execution times. We reuse pinned H4 data and do not download the raw ZIP files again in this guide.

08

A small positive value can be a completed zero crossing

The first eligible zero crossing from 2023 onward is available at 2023-01-26 16:00 UTC. CCI rises from −10.35 to 0.34. Current TP is 141.586000, the mean is 141.584767 and MAD is 0.241233 JPY per EUR. A small positive difference is enough for a strict crossing; there is no required margin. S stays on the completed reference candle. Five later observed candles provide context only.

A zero crossing can be small and still be strict

A zero crossing can be small and still be strictCandles are evenly spaced in observed order. Calendar gaps are compressed and marked by a dashed line. Connectors join observed values; no missing candles are added. Outlined candle bodies mark buckets with fewer than 240 source-minute rows.EUR/JPY Bid · JPY per EURTPM139.043139.929140.815141.700142.586Calendar gap: 2023-01-20 20:00 → 2023-01-22 20:00 UTCCCI20−200−1000100200Signed deviation / MAD · JPY per EUR−2.1220.0002.122TP − MMADS2023-01-20 12:002023-01-26 12:002023-01-27 08:00

Calendar gap Candles are evenly spaced in observed order. Calendar gaps are compressed and marked by a dashed line. Connectors join observed values; no missing candles are added. Outlined candle bodies mark buckets with fewer than 240 source-minute rows.

Select a candle, move the slider or use arrow keys. OHLC prices show three decimals, derived price quantities six and CCI two. S stays on the reference candle; the vertical cursor and details follow your selection. Pane scales stay fixed while selecting. Undefined values are shown as unavailable.

Interval anchor · UTC
2023-01-26 12:00 UTC
Scheduled interval end · UTC
2023-01-26 16:00 UTC
First source-minute label · UTC
2023-01-26 12:00 UTC
Last source-minute label · UTC
2023-01-26 15:59 UTC
Open
141.539
High
141.901
Low
141.261
Close
141.596
Source-minute rows · maximum 240
240
Typical price · TP
141.586000
Mean typical price · 20 values
141.584767
Mean absolute deviation · MAD
0.241233
Current TP minus mean
0.001233
CCI20
0.34
First eligible case, available 2023-01-26 16:00 UTC. The upper pane has EUR/JPY Bid candles, TP and its 20-value mean. CCI is in the middle; the signed deviation and MAD are below. S is the fixed completed reference candle. Later candles provide context.
09

A crossing above 100 describes a larger relative deviation

At 2023-01-20 12:00 UTC, CCI rises from 72.07 to 127.44 in the first eligible upward 100 crossing. Current TP is above its 20-value mean. The middle pane shows CCI, while the lower pane separates the signed current deviation from the positive MAD. Those lower quantities have price units; CCI is a ratio with no price unit. The crossing alone does not specify a purchase or a later reversal.

Above 100: current deviation relative to current MAD

Above 100: current deviation relative to current MADCandles are evenly spaced in observed order. Calendar gaps are compressed and marked by a dashed line. Connectors join observed values; no missing candles are added. Outlined candle bodies mark buckets with fewer than 240 source-minute rows.EUR/JPY Bid · JPY per EURTPM137.533138.665139.796140.928142.060Calendar gap: 2023-01-20 20:00 → 2023-01-22 20:00 UTCCCI20−300−1000100300Signed deviation / MAD · JPY per EUR−2.3290.0002.329TP − MMADS2023-01-16 04:002023-01-20 08:002023-01-23 00:00

Calendar gap Candles are evenly spaced in observed order. Calendar gaps are compressed and marked by a dashed line. Connectors join observed values; no missing candles are added. Outlined candle bodies mark buckets with fewer than 240 source-minute rows.

Select a candle, move the slider or use arrow keys. OHLC prices show three decimals, derived price quantities six and CCI two. S stays on the reference candle; the vertical cursor and details follow your selection. Pane scales stay fixed while selecting. Undefined values are shown as unavailable.

Interval anchor · UTC
2023-01-20 08:00 UTC
Scheduled interval end · UTC
2023-01-20 12:00 UTC
First source-minute label · UTC
2023-01-20 08:00 UTC
Last source-minute label · UTC
2023-01-20 11:59 UTC
Open
139.708
High
140.731
Low
139.673
Close
140.628
Source-minute rows · maximum 240
240
Typical price · TP
140.344000
Mean typical price · 20 values
139.265367
Mean absolute deviation · MAD
0.564237
Current TP minus mean
1.078633
CCI20
127.44
First eligible case, available 2023-01-20 12:00 UTC. CCI moves from at or below 100 to strictly above 100 through S. The lower pane separates the numerator’s signed price difference from the positive MAD used in the denominator; it does not show returns.
10

The lower zone can persist for several candles

At 2023-01-12 20:00 UTC, the current CCI is −232.20. The two preceding readings are −135.70 and −238.29, so CCI stays strictly below −100 on three adjacent completed candles through S. The current reading is less negative than the previous one but remains in the lower zone. This example is selected by a fixed condition, without ranking subsequent price changes or calculating a trade return.

Three readings can stay strictly below −100

Three readings can stay strictly below −100Candles are evenly spaced in observed order. Calendar gaps are compressed and marked by a dashed line. Connectors join observed values; no missing candles are added. Outlined candle bodies mark buckets with fewer than 240 source-minute rows.EUR/JPY Bid · JPY per EURTPM137.544138.991140.438141.885143.332Calendar gap: 2023-01-06 20:00 → 2023-01-08 20:00 UTCCCI20−300−1000100300Signed deviation / MAD · JPY per EUR−3.0910.0003.091TP − MMADS2023-01-06 16:002023-01-12 16:002023-01-13 12:00

Calendar gap Candles are evenly spaced in observed order. Calendar gaps are compressed and marked by a dashed line. Connectors join observed values; no missing candles are added. Outlined candle bodies mark buckets with fewer than 240 source-minute rows.

Select a candle, move the slider or use arrow keys. OHLC prices show three decimals, derived price quantities six and CCI two. S stays on the reference candle; the vertical cursor and details follow your selection. Pane scales stay fixed while selecting. Undefined values are shown as unavailable.

Interval anchor · UTC
2023-01-12 16:00 UTC
Scheduled interval end · UTC
2023-01-12 20:00 UTC
First source-minute label · UTC
2023-01-12 16:00 UTC
Last source-minute label · UTC
2023-01-12 19:59 UTC
Open
140.312
High
140.498
Low
140.007
Close
140.271
Source-minute rows · maximum 240
240
Typical price · TP
140.258667
Mean typical price · 20 values
141.719983
Mean absolute deviation · MAD
0.419552
Current TP minus mean
−1.461317
CCI20
−232.20
First eligible case, available 2023-01-12 20:00 UTC. Three adjacent CCI readings through S remain below −100. A less negative reading need not leave that zone. Price, CCI and deviation are shown without assuming an exit or a later reversal.
11

Keep exact comparisons separate from rounded display

Original prices are integers scaled by 1000000. The replay uses exact rational arithmetic for CCI and its threshold comparisons. OHLC prices display three decimals, typical price and related price quantities six, and CCI two. Rounded values can hide a small boundary difference. The 31 candles are evenly spaced in observed order; calendar gaps are compressed and marked. Connectors join available observations, while unavailable values break a line. Each pane keeps its scale while you select candles, and the detail panel retains UTC metadata and minute counts.

12

Replay the calculation before adding trading rules

For each case we take the first distinct matching candle starting on or after 2023-01-01 UTC. The selected candle and its 21 predecessors must have adjacent H4 anchors. Only the selected and immediately preceding buckets must contain all 240 minute rows, starting at the bucket anchor and ending 239 minutes later; earlier buckets may be partial and remain disclosed. Three formed CCI readings require at least 22 observations. Five later observed candles are required for the display, and their prices and quality do not rank the selection. The source was used in an earlier strategy, so these are retrospective examples. Downloads include the pinned inputs, CSV and separate replay and check scripts. No entry, exit, cost model or account return is calculated.

python3 cci-guide-replay.py --protocol cci-guide-protocol.json --source-evidence eurjpy-aroon-evidence.json --output replay.json
python3 cci-guide-independent-check.py --protocol cci-guide-protocol.json --source-evidence eurjpy-aroon-evidence.json --evidence replay.json --report check.json

Frequently asked questions

Why use typical price rather than just the close?

This CCI definition averages high, low and close for each candle. A close-only variant changes the input and may change the mean, deviation, thresholds and crossings. Match the input definition before comparing platforms.

Is mean absolute deviation the same as standard deviation?

No. Here MAD averages absolute distances from the current 20-value arithmetic mean. Standard deviation uses squared distances and a square root. Median absolute deviation uses a median and is also different.

Can MAD be zero when each candle has a price range?

Yes. The high, low and close can vary while their average stays identical across all 20 candles. In that case all typical prices equal their mean and MAD is 0. CCI is unavailable here; we do not replace it with 0 or a previous value.

Does crossing above 100 mean a reversal or a buy signal?

It establishes only the specified change in relative deviation. CCI can remain above 100 or below −100 for several candles. A funded strategy needs separate execution, exit, position-size and cost rules, plus a suitable risk test.

How can this CCI20 have a finite limit beyond ±100?

In a current-inclusive 20-value window, the centred deviations sum to 0. Their absolute sum is at least twice the absolute current deviation. Dividing by 20 and using the constant 0.015 gives abs(CCI20) at most 2000/3 when MAD is positive. For example, 19 values of 100 followed by 110 attain that limit. The conventional ±100 levels remain inside this mathematical range.

Are these three examples a backtest of a trading strategy?

No. They demonstrate the calculation and deterministic indicator states on archived Bid candles. No orders, returns, spreads, slippage, commissions or position sizes are simulated. The five later candles are visual context, and the examples are retrospective.

Primary sources

Download data and reproduction files

Created by the MyProfitFactor editorial team.

Copying or republication without attribution and an active link to the original material is prohibited. Usage policy.