---
title: Oscillators
description: RSI, CCI, and Stochastic — momentum oscillators that flag overbought and oversold conditions.
---

## Overview

Momentum indicators fluctuate between bounded values to identify overbought and oversold conditions. Oscillators help time entries and exits by measuring market momentum and potential reversal points.

| Type | Description |
| --- | --- |
| **RSI (Relative Strength Index)** | Measures momentum by comparing recent gains to losses. Values oscillate between 0 and 100. Overbought above **70**, oversold below **30**. |
| **CCI (Commodity Channel Index)** | Measures deviation from a statistical mean to identify cyclical trends and extremes. Overbought above **+100**, oversold below **-100**. |
| **Stochastic Oscillator** | Compares the closing price to its recent high/low range. Returns `%K` and `%D` values. Overbought above **80**, oversold below **20**. |

| Function | Description |
| --- | --- |
| [`rsi`](#rsi) | Relative Strength Index — momentum oscillator |
| [`cci`](#cci) | Commodity Channel Index — deviation from statistical mean |
| [`stochastic`](#stochastic) | Stochastic Oscillator — closing price vs recent range |

<a id="rsi"></a>

## rsi - Relative Strength Index

`rsi(source: TimeSeries, period?: number = 14, priceIndex?: number = 1): number` — Relative Strength Index oscillator.

| Parameter | Type | Description |
| --- | --- | --- |
| `source` | TimeSeries | Source data for calculation |
| `period` | number | Number of periods (default: `14`) |
| `priceIndex` | number | Index of price data (default: `1`) |

**Returns:** `number` — RSI value from 0 to 100 for the current bar.

```javascript
//@version=2

define(title="Multi-RSI Strategy", position="onchart", axis=false);

timeseries ohlcvData = ohlcv(symbol=currentSymbol, exchange=currentExchange);

// Calculate multiple RSIs
var rsi14 = rsi(source=ohlcvData.open, period=14);
var rsi50 = rsi(source=ohlcvData.open, period=50);

// Plot with different colors
plotLine(value=rsi14, width=2, colors=["purple"], fill=false, smooth=true, label=["RSI 14"], desc=["14-period RSI"]);
plotLine(value=rsi50, width=2, colors=["orange"], fill=false, smooth=true, label=["RSI 50"], desc=["50-period RSI"]);
```

<a id="cci"></a>

## cci - Commodity Channel Index

`cci(source: TimeSeries, period?: number = 20, constant?: number = 0.015): number` — Commodity Channel Index.

| Parameter | Type | Description |
| --- | --- | --- |
| `source` | TimeSeries | Source data series |
| `period` | number | Number of periods (default: `20`) |
| `constant` | number | Scaling constant (default: `0.015`) |

**Returns:** `number` — CCI value, typically between -100 and +100.

```javascript
//@version=2

define(title="CCI Strategy", position="offchart", axis=true);

timeseries trade = ohlcv(symbol=currentSymbol, exchange=currentExchange);

// Calculate CCI
var cciData = cci(source=trade, period=20, constant=0.015);

plotLine(value=cciData, width=2, colors=["blue"], fill=false, smooth=true, label=["CCI"], desc=["Commodity Channel Index"]);
```

<a id="stochastic"></a>

## stochastic - Stochastic Oscillator

`stochastic(source: TimeSeries, kPeriod?: number = 14, kSmoothing?: number = 3, dPeriod?: number = 3): [number, number]` — Stochastic Oscillator.

| Parameter | Type | Description |
| --- | --- | --- |
| `source` | TimeSeries | Source data series |
| `kPeriod` | number | `%K` periods (default: `14`) |
| `kSmoothing` | number | `%K` smoothing (default: `3`) |
| `dPeriod` | number | `%D` periods (default: `3`) |

**Returns:** `[number, number]` — `[%K, %D]` values between 0 and 100.

```javascript
//@version=2

define(title="Stochastic Strategy", position="offchart", axis=true);

timeseries ohlcvData = ohlcv(symbol=currentSymbol, exchange=currentExchange);

// Calculate Stochastic
var stochasticData = stochastic(source=ohlcvData, kPeriod=14, kSmoothing=3, dPeriod=3);

plotLine(value=stochasticData, width=2, colors=["green", "red"], label=["%K", "%D"], desc=["Stochastic %K", "Stochastic %D"]);
```

## Best Practices

<table data-view="cards"><tbody>
<tr><td>Avoid False Signals</td><td>Oscillators can remain overbought or oversold for extended periods in strong trends. Always confirm with price action and trend direction.</td><td></td></tr>
<tr><td>Divergence Analysis</td><td>Look for divergences between price and oscillator. When price makes new highs or lows but the oscillator does not, a reversal may be coming.</td><td></td></tr>
<tr><td>Multiple Timeframes</td><td>Use oscillators on multiple timeframes. Higher-timeframe signals are generally more reliable than lower-timeframe signals.</td><td></td></tr>
<tr><td>Market Conditions</td><td>Oscillators work best in ranging markets. In strong trends, use them for timing entries rather than counter-trend trading.</td><td></td></tr>
</tbody></table>
