Function Prototype
/* Commodity Channel Index */
/* Type: indicator */
/* Input arrays: 3 Options: 1 Output arrays: 1 */
/* Inputs: high, low, close */
/* Options: period */
/* Outputs: cci */
int ti_cci_start(TI_REAL const *options);
int ti_cci(int size,
TI_REAL const *const *inputs,
TI_REAL const *options,
TI_REAL *const *outputs);
Description
This documentation is still a work in progress. It has omissions, and it probably has errors too. If you see any issues, or have any general feedback, please get in touch.
The Commodity Channel Index indicator is used to detect trends. It works by taking a Simple Moving Average of the Typical Price and comparing it to the amount of volatility in Typical Price.
It takes one parameter: the period n
.
The calculation is as follows:
$$typprice_{t} = \frac{high_{t}+low_{t}+close_{t}}{3}$$
$$atp_{t} = \frac{1}{n} \sum_{i=0}^{n-1} typprice_{t-i}$$
$$md_{t} = \frac{1}{n} \sum_{i=0}^{n-1} | typprice_{t-i} - atp_{t} |$$
$$cci_{t} = \frac{typprice_{t} - atp_{t}}{0.015 md_{t}} $$
See Also
References
- Murphy, J. (1999) Technical Analysis of the Financial Markets
- Achelis, S. (2000) Technical Analysis from A to Z, 2nd Edition
Example Usage
Calling From C
/* Example usage of Commodity Channel Index */
/* Assuming that 'high', 'low', and 'close' are pre-loaded arrays of size 'in_size'. */
TI_REAL *inputs[] = {high, low, close};
TI_REAL options[] = {5}; /* period */
TI_REAL *outputs[1]; /* cci */
/* Determine how large the output size is for our options. */
const int out_size = in_size - ti_cci_start(options);
/* Allocate memory for output. */
outputs[0] = malloc(sizeof(TI_REAL) * out_size); assert(outputs[0] != 0); /* cci */
/* Run the actual calculation. */
const int ret = ti_cci(in_size, inputs, options, outputs);
assert(ret == TI_OKAY);
Calling From Lua (with Tulip Chart bindings)
-- Example usage of Commodity Channel Index
cci = ti.cci(high, low, close, 5)
Example Calculation
period = 5
date | high | low | close | cci |
---|---|---|---|---|
2005-11-01 | 82.15 | 81.29 | 81.59 | |
2005-11-02 | 81.89 | 80.64 | 81.06 | |
2005-11-03 | 83.03 | 81.31 | 82.87 | |
2005-11-04 | 83.30 | 82.65 | 83.00 | |
2005-11-07 | 83.85 | 83.07 | 83.61 | |
2005-11-08 | 83.90 | 83.11 | 83.15 | |
2005-11-09 | 83.33 | 82.49 | 82.84 | |
2005-11-10 | 84.30 | 82.30 | 83.99 | |
2005-11-11 | 84.84 | 84.15 | 84.55 | 166.67 |
2005-11-14 | 85.00 | 84.11 | 84.36 | 82.02 |
2005-11-15 | 85.90 | 84.03 | 85.53 | 95.50 |
2005-11-16 | 86.58 | 85.39 | 86.54 | 130.91 |
2005-11-17 | 86.98 | 85.76 | 86.89 | 99.16 |
2005-11-18 | 88.00 | 87.17 | 87.77 | 116.34 |
2005-11-21 | 87.87 | 87.01 | 87.29 | 71.93 |
Chart
Other Indicators
Previous indicator: Balance of Power
Next indicator: Vector Ceiling
Random indicator: Crossover
Copyright © 2016-2024 Tulip Charts LLC. All Rights Reserved.