Center Of Gravity (COG) Indicator for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
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/wLM6Cq
 
Last edited:
A

AcquireCurrency

New member
Is it possible to make a scan that alerts when the price of the stock is in the green or below with the COG pointing up? And obviously vice-versa when COG is pointing down and price is in or above the purple portion.

 
Last edited:
W

wildtrade

New member
VIP
I was wondering if anyone had or converted this indicator to TOS? Been looking for something similar to bollinger bands with Fibs built in. Or maybe COG indicator
 
horserider

horserider

Well-known member
VIP
@wildtrade Here you go.
Code:
# Bollinger Bands With Fibonaci levels.
# Horserider 1/24/2020
 
input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.Simple;
input fib1 = 0.382;
input fib2 = 0.618;
input fib3 = 0.764;


def sDev = stdev(data = price[-displace], length = length);

plot MidLine = MovingAverage(averageType, data = price[-displace], length = length);
plot LowerBand = MidLine + num_Dev_Dn * sDev;
plot UpperBand = MidLine + num_Dev_Up * sDev;

plot UpperFibLine1 = (UpperBand - MidLine) * fib1 + MidLine;
plot UpperFibLine2 = (UpperBand - MidLine) * fib2 + MidLine;
plot UpperFibLine3 = (UpperBand - MidLine) * fib3 + MidLine;

plot LowerFibLine1 = (LowerBand - MidLine) * fib1 + MidLine;
plot LowerFibLine2 = (LowerBand - MidLine) * fib2 + MidLine;
plot LowerFibLine3 = (LowerBand - MidLine) * fib3 + MidLine;



LowerBand.SetLineWeight(2);
MidLine.SetLineWeight(3);
UpperBand.SetLineWeight(2);

LowerBand.SetDefaultColor(Color.DARK_RED);
MidLine.SetDefaultColor(Color.GRAY);
UpperBand.SetDefaultColor(Color.DARK_RED);

UpperFibLine1.SetDefaultColor(Color.GRAY);
UpperFibLine2.SetDefaultColor(Color.GRAY);
UpperFibLine3.SetDefaultColor(Color.GRAY);

LowerFibLine1.SetDefaultColor(Color.GRAY);
LowerFibLine2.SetDefaultColor(Color.GRAY);
LowerFibLine3.SetDefaultColor(Color.GRAY);

UpperFibLine1.SetStyle(Curve.SHORT_DASH);
UpperFibLine2.SetStyle(Curve.SHORT_DASH);
UpperFibLine3.SetStyle(Curve.SHORT_DASH);

LowerFibLine1.SetStyle(Curve.SHORT_DASH);
LowerFibLine2.SetStyle(Curve.SHORT_DASH);
LowerFibLine3.SetStyle(Curve.SHORT_DASH);
 
X

xiaxia

New member
I was wondering if anyone had or converted this indicator to TOS? Been looking for something similar to bollinger bands with Fibs built in. Or maybe COG indicator
I need to try out this TrueCenterBand indicator, if only someone could port it over to tos
 
H

HighBredCloud

Well-known member
VIP
@xiaxia it looks like @horserider already did in the above post...
 
horserider

horserider

Well-known member
VIP
@xiaxia Just guessing but I bet there is nothing special about those bands. You can also simulate them by adding 2 or 3 Bollinger bands studies or exponential deviation band studies and varying the outer bands say to maybe 1 , 2 , and 3 or whatever numbers you prefer.
 
BenTen

BenTen

Administrative
Staff
VIP
@spm009 Must note that this indicator kind of repaint. It will fluctuate along with the price. Careful when using it.
 
S

Snorg

New member
The colored charts ( black background ) are polynomial regression channel plots ( not COG plots). Could be a quadratic (2). Could be greater than 2 - now that would be cool.

This dude wants $200 for his TOS code. :p

https://funwiththinkscript.com/indicators/polynomial-regression-channel/
But alas, we have PRC code in C# ( ninja ).

https://www.mypivots.com/board/topic/6450/1/polynomial-regression-channel-bands
The download is safe - extracted the PRC2.cs file only and it appears to work on NT4/5.

So here's the question of the day? Who feels like converting PRC2.CS to TOS?
 
S

soary

Member
TOS drawing tools has Fib fans, arcs n spirals that would probably give the same information. I use the fib fans a lot and they are great for those price levels.
 
T

tradegeek

Active member
2019 Donor
VIP
@Snorg That dude is also a member here. 😀
 
W

wildtrade

New member
VIP
@horserider Thank you!! Do you know what the DATA plot is exactly? I thought my post got deleted.... so I didn't check back in... @Snorg that would be awesome if some could convert that code for the PRC code!
 

Similar threads

Top