Docs

ta.cog

Locate where the weight of the window sits, from the newest bar to the oldest.

itm
ta.cog(source, length)

Centre of gravity: -sum(source[i] * (i + 1)) / sum(source[i]) over i = 0..length-1, where source[0] is the current bar. The value is negative by construction, as in the published form. A value near -1 means the weight sits on the newest bar and a value near -length means it sits on the oldest.

Parameters

A series parameter takes a value on every bar. A constant parameter must be known before the first bar, such as a number or an input.

NameKindTypeDefaultRangeDescription
sourceSeriesnumber--The series to read.
lengthConstantnumber101 to 10000Window in observed bars.

Output

NameType
valuenumber

Warm-up and missing values

Warm-up
length bars. Names in the warm-up are this operator’s parameters.
Missing values
Returns na until length consecutive non-na observations are in the window. An na resets the accumulation. na when the window sums to zero, because the centre is undefined there.

Example

itm
ta.cog(close, 10)
itm
plot(ta.cog(close, 10), "Centre of gravity 10")