Center Of Gravity or known as COG is a momentum indicator used to identify potential reversal point when hitting the upper or lower extreme channel. When price reached one end of the channel, it's most likely going to reverse and come back.
This indicator was converted to ThinkorSwim by baffled1. It can be used on any timeframes. The Center of Gravity can be a great indicator when trading in range-bound markets. You should avoid using it when the price is trending.
thinkScript Code
Rich (BB code):
input price = close;
input length = -10;
def displacement = (length / 2) + 1;
def dPrice = price[displacement];
def tmp = if !IsNaN(dPrice) then Average(dPrice, AbsValue(length)) else tmp[1] + (tmp[1] - tmp
[2]);
def tmp1 = if !IsNaN(price) then tmp else Double.NaN;
plot Data = tmp1;
Data.SetDefaultColor(color.CYAN );
Data.SetStyle(Curve.SHORT_DASH);
def pct=100;
input width=65;
def d=width/pct;
def d1=0.8*d;
def d2=1.05*d;
def d3=1.15*d;
def stdDeviation = Highestall("data" = AbsValue(tmp1 - price));
plot UpperLine = tmp1 + stdDeviation*d1;
plot LowerLine = tmp1 - stdDeviation*d1;
plot UpperLine1 = tmp1 + stdDeviation*d2;
plot LowerLine1 = tmp1 - stdDeviation*d2;
plot UpperLine2 = tmp1 + stdDeviation*d3;
plot LowerLine2 = tmp1 - stdDeviation*d3;
UpperLine.SetDefaultColor(color.red);
UpperLine1.SetDefaultColor(color.red );
UpperLine2.SetDefaultColor(color.red );
LowerLine.SetDefaultColor(color.cyan );
LowerLine1.SetDefaultColor(color.cyan );
LowerLine2.SetDefaultColor(color.cyan );
AddCloud(UpperLine,UpperLine1,color.plum,color.plum);
AddCloud(LowerLine,LowerLine1,color.green,color.dark_green);
Shareable Link
https://tos.mx/wLM6CqAdaptive Center of Gravity
Code:
# AdaptiveCOG
# Drew Griffith
declare upper;
# Daily settings
input price = close;
input COGlength = 10;
input InnerValue = 1.0;
input OuterValue = 1.6;
input ATRLength = 14;
input showClosingPriceLine = NO;
input showPriceBar = YES;
input smooth = 1;
def displacement = (-COGlength / 2) + 1;
def dPrice = price[displacement];
def CMA = if !IsNaN(dPrice) then Average(dPrice, AbsValue(COGlength)) else
CMA[1] + (CMA[1] - CMA[2]);
def ATR = Average(TrueRange(high, close, low), ATRLength);
plot UpperOuterBand = if !IsNaN(price) then CMA + (ATR * OuterValue) else
Double.NaN;
plot LowerOuterBand = if !IsNaN(price) then CMA - (ATR * OuterValue) else
Double.NaN;
plot UpperInnerBand = if !IsNaN(price) then CMA + (ATR * InnerValue) else
Double.NaN;
plot LowerInnerBand = if !IsNaN(price) then CMA - (ATR * InnerValue) else
Double.NaN;
plot Rating = if
close > UpperOuterBand then -1
else if close > UpperInnerBand then -0.5
else if close < LowerInnerBand then 0.5
else if close < LowerOuterBand then 1
else 0;
RATING.Hide();
plot CenterLine = if !IsNaN(price) then CMA else Double.NaN;
CenterLine.DefineColor("CMA", GetColor(1));
CenterLine.DefineColor("Extrapolated", GetColor(0));
CenterLine.AssignValueColor(if !IsNaN(dPrice) then CenterLine.Color("CMA")
else
CenterLine.Color("Extrapolated"));
CenterLine.SetLineWeight(2);
CenterLine.Hide();
CenterLine.SetStyle(Curve.SHORT_DASH);
UpperOuterBand.SetDefaultColor(GetColor(5));
UpperOuterBand.SetLineWeight(2);
LowerOuterBand.SetDefaultColor(GetColor(6));
LowerOuterBand.SetLineWeight(2);
UpperInnerBand.SetDefaultColor(GetColor(5));
UpperInnerBand.SetLineWeight(1);
LowerInnerBand.SetDefaultColor(GetColor(6));
LowerInnerBand.SetLineWeight(1);
# Turn AddClouds off by putting a #-sign at the first position of the lines
AddCloud(UpperOuterBand, UpperInnerBand, Color.RED);
AddCloud(LowerInnerBand, LowerOuterBand, Color.GREEN);
HidePricePlot(!showPriceBar);
Attachments
Last edited by a moderator: