Ehlers Center Of Gravity Oscillator [CC] For ThinkOrSwim

WildTiger99

New member
This is John Ehlers' Center of Gravity Oscillator. Not the COG with bands and fibs.
Just a simple plain vanilla oscillator that sits below the chart in ToS.

The author states: The Center of Gravity Oscillator was created by John Ehlers (Cybernetic Analysis For Stocks And Futures pg 49) and this provides a pretty accurate way to see how the stock is trending.

If the indicator stays above 0 then the stock is in a pretty strong uptrend and if it stays below 0 then the stock is in a pretty strong downtrend.

Buy when the indicator changes from red to green and sell when it changes from green to red.

olzjKlP.png



Here is the original Tradingview code:
https://www.tradingview.com/script/thsL7j1b-Ehlers-Center-Of-Gravity-Oscillator-CC/

The new ThinkOrSwim code can be found in the next post.
 
Last edited by a moderator:
Looking for John Ehlers' Center of Gravity Oscillator for TOS. I'm looking for the oscillator, not the one with bands and fibs. Just a simple plain vanilla oscillator that sits below the chart in Tos, please.

Like this:
https://www.tradingview.com/script/thsL7j1b-Ehlers-Center-Of-Gravity-Oscillator-CC/
check the below:

CSS:
#//Indicator for TOS
#// Copyright (c) 2019-present, Franklin Moormann (cheatcountry)
#// Ehlers Center Of Gravity Oscillator [CC] script may be freely distributed under the MIT license.
#study("Ehlers Center Of Gravity Oscillator [CC]", overlay=false)
# Converted by Sam4Cok@Samer800    - 10/2024
Declare lower;

input timeframe = AggregationPeriod.MIN;
input AllowRepainting = no;
input colorBars = yes;
input Source = FundamentalType.HL2;
input length = 10;

def na = Double.NaN;
def last = isNaN(close);
def current = GetAggregationPeriod();
def tf = Max(current, timeframe);
def src = if AllowRepainting then
         if !last then Fundamental(Source, Period = tf) else src[1] else
         if !last then Fundamental(Source, Period = tf)[1] else src[1];

def num = fold i = 0 to length with p do
          p + (1 + i) * src[i];
def denom = sum(src, length);
def cg = if denom != 0 then (-num / denom) + ((length + 1) / 2) else 0;
def cg1 = cg[1];
def sig = if cg > 0 then 1 else if cg < 0 then -1 else 0;

plot cgLine = if last then na else cg;
plot cgLine1 = if last then na else cg1;
plot zero = if last then na else 0;

cgLine.SetLineWeight(2);
cgLine.AssignValueColor(if sig>0 then Color.GREEN else if sig<0 then Color.RED else Color.GRAY);
cgLine1.SetDefaultColor(Color.DARK_GRAY);
zero.SetDefaultColor(Color.DARK_GRAY);
zero.SetStyle(Curve.SHORT_DASH);

AddCloud(cgLine, cgLine1, Color.DARK_GREEN, Color.DARK_RED);

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if sig>0 then Color.GREEN else if sig<0 then Color.RED else Color.GRAY);

# End of CODE
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
153 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top