ta.cog()Center of Gravity
The Center of Gravity oscillator is the negative ratio of a bar-position-weighted price sum to the unweighted price sum over the lookback. It is not a price level.
Syntax
ta.cog(source, length) → series floatArguments
| Parameter | Type | Description |
|---|---|---|
| source | series int/float | Series of values to process. |
| length | series int | Number of bars in the rolling window. |
Returns
Center of Gravity.
Remarks
na values in the source series are ignored.
Code Examples
//@version=6
indicator("ta.cog", overlay=true)
plot(ta.cog(close, 10))
// the same on pine
pine_cog(source, length) =>
sum = math.sum(source, length)
num = 0.0
for i = 0 to length - 1
price = source[i]
num := num + price * (i + 1)
-num / sum
plot(pine_cog(close, 10))Trading Applications
Inspect shifts in the price-weighted center across a rolling window
Compare oscillator turns with price; no universal overbought threshold is implied
Build mean-reversion strategies
Test oscillator-based hypotheses without treating turns as forecasts
Related Functions
Frequently Asked Questions
Generate ta.cog() Code with AI
Draft Pine Script using ta.cog() with Pineify's AI Coding Agent, then review the arguments and test the result on your chart. Usage depends on your plan and available credits.
Related Pine Script Functions
ta.stoch() - Stochastic Oscillator
Learn how to use ta.stoch() in Pine Script. Syntax, parameters, code examples for the Stochastic Oscillator.
ta.rsi() - Relative Strength Index
Learn how to use ta.rsi() in Pine Script. Syntax, parameters, code examples for the RSI momentum oscillator.
ta.linreg() - Linear Regression
Learn how to use ta.linreg() in Pine Script. Syntax, parameters, code examples for linear regression curve fitting.
ta.sma() - Simple Moving Average
Learn how to use ta.sma() in Pine Script. Syntax, parameters, code examples, and trading applications for the Simple Moving Average function.
ta.ema() - Exponential Moving Average
Learn how to use ta.ema() in Pine Script. Syntax, parameters, code examples, and trading applications for the Exponential Moving Average function.