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 | Relative Strength Index — momentum oscillator |
cci | Commodity Channel Index — deviation from statistical mean |
stochastic | Stochastic Oscillator — closing price vs recent range |
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.
//@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"]);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.
//@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"]);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.
//@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"]);