---
title: What is and how to use CCI in Tuned Script
slug: what-is-and-how-to-use-cci-in-tuned-script
docTags: 
createdAt: 2022-06-13T16:10:53.000Z
---

### What Is the Commodity Channel Index?

The CCI is a momentum-based oscillator used to help determine when an asset is reaching a condition of being overbought or oversold. The CCI was originally developed to spot long-term trend changes but has been adapted by traders for use on all markets or time-frames. Trading with multiple time frames provides more buy or sell signals for active traders. Traders often use the CCI on the longer-term chart to establish the dominant trend and on the shorter-term chart to isolate pull-backs and generate trade signals.

![](https://api.archbee.com/api/optimize/sLyofYuHQt3L9DD4FlP8D/7hCaTfPVJ9NVPgSWWdI6m_image.png)

### Key points about the CCI

1. The CCI is a market indicator used to track market movements that may indicate buying or selling;
2. The CCI compares the current price to the average price over a specific time period;
3. Different strategies can use the CCI in different ways, including: using it across multiple timeframes to establish dominant trends, pullbacks, or entry points into that trend;
4. Some trading strategies based on CCI can produce multiple false signals or losing trades when conditions turn choppy.

### How to add the CCI to my script?

Below you will find a short example of using the CCI in your script.

:::CodeblockTabs
TunedScript

```javascript
//Inputs
length = intInput("Length of the CCI", 20) 

//Indicator
cci = cci(length)

//Plot
plot(cci, "cci", "#996A15", 2, PlotStyle.LINE, 0, false)
band1 = plot(seriesOf(100.0), "Upper Band", "#c0c0c0", 1, PlotStyle.LINE, 0, false)
band2 = plot(seriesOf(-100.0), "Lower Band", "#c0c0c0", 1, PlotStyle.LINE, 0, false)
fill(band1, band2, "#9C6E1B", 80, "Background", false)

//Signal Push
out(NEVER_ORDER)
```
:::

![](https://api.archbee.com/api/optimize/sLyofYuHQt3L9DD4FlP8D/-3jXKmMeLDs3G7WZKNpDu_image.png "CCI plot on Tuned")

### How to use the CCI to generate buy and sell signals?

For the example, we'll use the default settings - `Length` = 20.

To generate signals we will use the most basic method of setting a crossover and crossunder of the zero line to generate either a long or a short.

- Crossover the zero line = Long trade
- Crossunder the zero line = Short trade

:::CodeblockTabs
TunedScript

```javascript
//Inputs
length = intInput("Length of the CCI", 20) 

//Indicator
cci = cci(length)

//Conditions
buy = crossover(cci, seriesOf(0.0))
sell = crossunder(cci, seriesOf(0.0))

//Plot
plot(cci, "cci", "#996A15", 2, PlotStyle.LINE, 0, false)
band1 = plot(seriesOf(100.0), "Upper Band", "#c0c0c0", 1, PlotStyle.LINE, 0, false)
band2 = plot(seriesOf(-100.0), "Lower Band", "#c0c0c0", 1, PlotStyle.LINE, 0, false)
fill(band1, band2, "#9C6E1B", 80, "Background", false)

//Signal Push
out(signalIf(buy, sell))
```
:::

![](https://api.archbee.com/api/optimize/sLyofYuHQt3L9DD4FlP8D/XS3zaGCWFBl9eWM-W1eV6_image.png)

So now you have learned what CCI is, how to use it and how to put it in a script and generate signals from it.
Have fun scripting!

