ta.cog
Locate where the weight of the window sits, from the newest bar to the oldest.
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.
| Name | Kind | Type | Default | Range | Description |
|---|---|---|---|---|---|
source | Series | number | - | - | The series to read. |
length | Constant | number | 10 | 1 to 10000 | Window in observed bars. |
Output
| Name | Type |
|---|---|
value | number |
Warm-up and missing values
- Warm-up
lengthbars. Names in the warm-up are this operator’s parameters.- Missing values
- Returns na until
lengthconsecutive 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
ta.cog(close, 10)plot(ta.cog(close, 10), "Centre of gravity 10")