Sidechair

ta.cog()

Browse the reference

Returns the center of gravity oscillator: a weighted position of price inside the window, negative and shifting with each new bar.

Try it in the editor

ta.cog computes the sum of source[i] * (i + 1) over the window, divided by the plain sum of source, and negates it. Bar i counts back from the newest bar, so recent values get the smallest weights.

The output sits between -length and -1 and moves slightly with each bar; its turns lead price turns. Values start once length bars have been seen.

Syntax

Pine Script
ta.cog(source: series int/float, length: series int) -> series float

Arguments

NameTypeDefaultDescription
sourceseries int/floatrequiredThe series whose centre of gravity is measured over the last length bars.
lengthseries intrequiredNumber of bars in the window. A whole number of 1 or more.

Returns

series float: the weighted center of gravity, or na while the window is not full.

Remarks

  • Plot it with a one-bar-late copy of itself to read crossings: plot(cog[1]).

Example

Pine ScriptCenter of gravity with its trigger lineOpen in editor
//@version=6
indicator("COG")
value = ta.cog(close, 10)
plot(value, "COG", color = color.blue)
plot(value[1], "Trigger", color = color.red)

See also

Runs on Sidechair