SpecialPine Script v6

ta.cog()

Center of Gravity

The cog (center of gravity) is an indicator based on statistics and the Fibonacci golden ratio.

Syntax

Syntax
ta.cog(source, length) → series float

Arguments

ParameterTypeDescription
sourceseries int/floatSeries of values to process.
lengthseries intNumber of bars in the rolling window.

Returns

Center of Gravity.

Remarks

na values in the source series are ignored.

Code Examples

Pine Script v6 Example
//@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

Identify price equilibrium points

Detect overbought/oversold using gravity concept

Build mean-reversion strategies

Use as a leading oscillator for price direction

Related Functions

Frequently Asked Questions

Generate ta.cog() Code with AI

Skip the manual coding. Use Pineify's AI Coding Agent to generate Pine Script code using ta.cog() and other built-in functions instantly.