Returns the center of gravity oscillator: a weighted position of price inside the window, negative and shifting with each new bar.
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
ta.cog(source: series int/float, length: series int) -> series floatArguments
| Name | Type | Default | Description |
|---|---|---|---|
| source | series int/ | required | The series whose centre of gravity is measured over the last length bars. |
| length | series int | required | Number 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
//@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