Indicator · Pine Script v4 · Own pane

Center Of Gravity Oscillator

by kachook· code credited to veryfid

Calculates the Center of Gravity oscillator to identify momentum and potential turning points.

View on GitHub

GitHub stars4on the repository
Pine versionv4older, still runs
Lines of code84
Settings16inputs
LicenceNone statedfile: MPL-2.0
Last update3 years ago29 Jul 2023

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

84 lines of Pine Script v4 from Center Of Gravity Oscillator.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Center Of Gravity Oscillator.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © veryfid

//@version=4
study("Center Of Gravity Oscillator", shorttitle="COG", resolution = "")

theme = input("CUSTOM", "Theme:", options=["CUSTOM", "CLEAN", "FIBONACCI", "FIBONACCI 2"])
src =input(close)
length =input(9)
smooth = input("NONE", "Use Smoothing?", options=["RMA", "NONE"])
length5 =input(2,"Smoothing Length")
length2 =input(20,"Previous Hig/Low Length")
length3 =input(200,"LSMA Length")
length4 =input(1000,"fib Length")
col1 = input(color.white, "Fib Color")
fib = input(false, "Show Fibonacci Levels?")
pline = input(true, "Show Price Line?")
showcol = input(false, "Dual colored trigger?")
showhl = input(false,"Show High/Low Levels")

if theme == "FIBONACCI 2"
    showcol := true


windowsize = input(title="Trigger Window Size", type=input.integer, defval=3)
offset = input(title="Trigger Offset", type=input.float, defval=0.85)
sigma = input(title="Trigger Sigma", type=input.float, defval=6)

COG1 = cog(src, length)
COG= COG1
rma = rma(COG1,length5)

if smooth == "RMA"
    COG := rma
if theme == "FIBONACCI"
    fib := true
    length4 := 50
if theme == "FIBONACCI 2"
    fib := true
    length4 := 30
if theme == "CLEAN"
    COG := rma
    length5 := 9
    
p1 = plot(theme == "FIBONACCI" or theme == "FIBONACCI 2" ? na : lowest(COG,length2),color = color.green,transp = 100, title = "Previous Low")
p2 = plot(theme == "FIBONACCI" or theme == "FIBONACCI 2" ? na : highest(COG,length2),color = color.red,transp = 100, title = "Previous High")
c2 =plot(pline ? COG : na,color = change(COG) > 0 ? #00ffaa : color.red, linewidth= theme == "FIBONACCI 2" ? 3 : 1,title = "COG Trend Line",trackprice =true )
c =plot(theme == "FIBONACCI 2" or theme == "CLEAN" ? na : COG,color = color.white, linewidth=2,title = "COG")
trigger = alma(COG, windowsize, offset, sigma)
lsma = linreg(COG,length3,0)
fill(p1,c,title = "Previous Low")
fill(p2,c,transp = 80,title = "Previous High")
plot(theme == "FIBONACCI" or theme == "FIBONACCI 2"? na : lsma,color=color.red,title = "LSMA")
plot(theme == "FIBONACCI 2" or theme == "CLEAN" ? na : trigger,title = "Trigger",color = showcol ? change(COG) > 0 ?  color.green : color.red : color.blue) 
plot(theme == "CLEAN" ? COG : na, color = color.blue, linewidth = 3)
plot(theme == "CLEAN" ? sma(COG,2) : na, color = color.white, linewidth = 2)

h = highest(COG,length4)
l = lowest(COG,length4)
range = h - l

l1 = h - range * 0.236 
l2 = h - range * 0.382  
l3 = h - range * 0.618
l4 = h - range * 0.764
l5 = h - range * 0.5

f1 = plot(fib ? l1 : na, color = col1, transp = 60, title = "0.236")
f2 = plot(fib ? l2 : na, color = col1, transp = 60, title = "0.382")
f3 = plot(fib ? l3 : na, color = col1, transp = 60, title = "0.618")
f4 = plot(fib ? l4 : na, color = col1, transp = 60, title = "0.764")
f5 = plot(fib ? l5 : na, color = theme == "FIBONACCI 2" ? #ffe0b2 : col1, transp = theme == "FIBONACCI 2" ? 20 : 60, title = "0.5")

p3 = plot(showhl or theme == "FIBONACCI" ? h : na, "high")
p4 = plot(showhl or theme == "FIBONACCI" ? l : na, "Low")
p5 = plot(theme == "FIBONACCI 2" ? h : na, "high", color = color.red)
p6 = plot(theme == "FIBONACCI 2" ? l : na, "Low", color = color.green)
//Conditions
enter = crossover(COG1,trigger)

fill(p5,f1,color.red) 
fill(p5,f2,color.red) 
fill(p6,f4,color.green) 
fill(p6,f3,color.green)

Overview

Center Of Gravity Oscillator plots the oscillator alongside an Arnaud Legoux Moving Average trigger line, a Least Squares Moving Average, historical high and low bounds, and optional Fibonacci retracement levels based on oscillator ranges. Preset themes customize layout options. Plotted in a separate indicator pane.

Details

Published by

kachook on GitHub

Code credit

veryfid, as written in the script's header

Type

Indicator, Pine Script v4

Draws

Separate pane below the chart

Category

Oscillators & momentum, Support & resistance

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Theme:stringCUSTOMtheme
srcsourceclosesrc
lengthint9length
Use Smoothing?stringNONEsmooth
Smoothing Lengthint2length5
Previous Hig/Low Lengthint20length2
LSMA Lengthint200length3
fib Lengthint1000length4
Fib Colorcolorcolor.whitecol1
Show Fibonacci Levels?boolfalsefib
Show Price Line?booltruepline
Dual colored trigger?boolfalseshowcol
Show all 16 settings
SettingTypeDefaultVariable
Show High/Low Levelsboolfalseshowhl
Trigger Window Sizeint3windowsize
Trigger Offsetfloat0.85offset
Trigger Sigmafloat6sigma
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

114 stars

This indicator combines a scaled Forecast Oscillator with a Point of Force state detector. The Forecast Oscillator calculates the percentage deviation of price from its linear regression curve and normalizes the output between 0 and 1, plotting a line in a sep

Indicator v4 Oscillators & momentumSupport & resistance Repaints

CCI DC

by be-thomas
65 stars

This indicator plots the Commodity Channel Index in a separate pane and surrounds it with a Donchian channel whose lookback length changes with volatility. It measures volatility as a ratio of short and long ATR values, then ranks that ratio and shortens or le

Indicator v5 Oscillators & momentumVolatility & bands
Updated 4 days ago · GPL-3.0 GitHub repository of CCI DC

WaveTrend 3D

by nersent
29 stars

WaveTrend 3D is a redesigned oscillator that implements the classic WaveTrend algorithm with kernel-based regression for trend reversal confirmation and multi-timeframe support. It calculates a smoothed oscillator line and displays a symmetrical three-dimensio

Indicator v5 Oscillators & momentumDivergence
Updated 11 months ago · Custom licence GitHub repository of WaveTrend 3D

Benso Pendulum

by benso87
24 stars

Benso Pendulum is an indicator that plots a customizable Relative Strength Index (RSI) oscillator in a separate pane on the price chart. It calculates the RSI using the specified source and period, applying dynamic colors that change based on overbought and ov

Indicator v5 Oscillators & momentumSupport & resistance
Updated 4 years ago · MPL-2.0 GitHub repository of Benso Pendulum
9 stars

This indicator plots currency strength values for EUR, USD, JPY, GBP, CHF, AUD, CAD, NZD and optionally XAU or XAG on a separate pane. It computes strength by comparing current pair closes to daily closes using broker-specific data from OANDA, FX or FOREXCOM.

Indicator v4 Oscillators & momentumSupport & resistance Repaints
Updated 5 years ago · None stated GitHub repository of 4th Dimension Currency Strength

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers