Skip to content

Technical indicators

Center of Gravity Oscillator (COG)

Where the weight of the recent closes lies within the window.

John Ehlers’ Center of Gravity weights each close in the window by its age, the newest by 1 and the oldest by periods, and divides by the plain sum, giving a negative number whose level depends on periods and which moves as recent prices rise or fall against older ones. With signalPeriods, an EMA of it is added as a signal line.

Traders read crosses of the signal line as turns. Only the movement matters, not the level.

COG = −Σ close(i) × (i + 1) / Σ close(i) i = 0 for the bar that just closed
signal = EMA(COG, signalPeriods)

Call: cog(periods, signalPeriods)

Setting Chart default
periods: Periods 10
signalPeriods: Signal Periods 9

What you get: a list of 2, in this order: 1. a number; 2. a number (“cog Signal”).

Warm-up: with cog(10, 9), it asks for 10 bars of history and a run-up of 9, and its first value came on bar 19 of the example data.

Center of Gravity Oscillator (COG) drawn by its own code on example prices

The prices are made up, hourly, and the same on every page, so the chart shows how the indicator behaves, not how a market behaved.

function onIntervalClose() {
const lines = cog(10, 9);
if (OPEN_POSITIONS_COUNT === 0 && lines[0] > lines[1]) {
openPosition("BUY", { quantity: 10000, stopLossPips: 25, takeProfitPips: 40 });
}
}

It always returns a list: [COG], or [COG, signal] with signalPeriods. The line rises with the price, so this sample buys when it is above its signal.