McGinley Dynamic Indicator for ThinkorSwim

BenTen

Administrative
Staff member
Staff
VIP
Lifetime
This indicator is called McGinley Dynamic for ThinkorSwim. Investopedia dubbed it "The Most Reliable Indicator You've Never Heard Of". I thought it would be interesting to share it here.

The tradition simple and exponential moving averages tend to lag. McGinley Dynamic indicator will try to overcome that by automatically adjusting itself relative to the speed of the market.

nZaCklD.png


thinkScript Code

Code:
# McGinley Dynamic Indicator
# Mobius
# V02.11.2011
#  D = D1 + ((I - D1) / ( N * (I/D1)^4))
# where D1= yesterday's Dynamic, I = today's price, N = smoothing factor.

input value= close;
input length= 20;
input Slength = 5;
def A1= ExpAverage(value, length)[1];
def MDI = A1 + ((value - A1) / Sqr(value / A1));
plot Data = ExpAverage(MDI, Slength);
Data.SetPaintingStrategy(PaintingStrategy.LINE);
Data.SetLineWeight(2);
#Data.SetDefaultColor(GetColor(8));
def A2 = ExpAverage(value, length*3)[1];
def MDI2 = A2 + ((value - A2) / Sqr(value / A2));
plot Data2 = ExpAverage(MDI2, Slength*3);
Data2.DefineColor("Data2_SlopePos", Color.GREEN);
Data2.DefineColor("Data2_SlopeNeg", Color.MAGENTA);
Data2.AssignValueColor(if Data  > Data2 then Data2.Color("Data2_SlopePos") else Data2.Color("Data2_SlopeNeg"));
Data2.setlineweight(2);
data2.hide();
Data.DefineColor("Data_SlopePos", Color.CYAN);
Data.DefineColor("Data_SlopeNeg", Color.RED);
Data.AssignValueColor(if Data  > Data2 then Data.Color("Data_SlopePos") else Data.Color("Data_SlopeNeg"));
data.hide();
plot EMA8 = expaverage(close,8);
EMA8.setdefaultcolor(color.DARK_ORANGE);
EMA8.setlineweight(2);
EMA8.hide();
# End Code ------------
def buySignal = if Data > Data2 and Data[1] <= Data2[1] and expaverage(close,8) > average(close,13) then 1 else 0;
def sellSignal = if Data < Data2 and Data[1] >= Data2[1] and expaverage(close,85) < average(close,13) then 1 else 0;
plot signal = if buySignal or sellSignal then Data else double.nan;
signal.assignValueColor(if buySignal then color.WHITE else color.YELLOW);
signal.setLineWeight(5);
#signal.SetStyle(curve.points);
signal.setpaintingstrategy(paintingStrategy.SQUARES);

# additional plots from yahoo forum
input price = close;
input length2 = 14;
input displace = 0;
plot WS = WildersAverage(price[-displace], length2);
WS.setDefaultColor(GetColor(8));
input periods = 10;
rec _md = compoundValue( 1, _md[1] + (( close - _md[1] ) / ( periods *
power( close / _md[1], 4 ) ) ), close );
plot MD = _md;
MD.setdefaultcolor(color.CYAN);
MD.setlineweight(2);
MD.hide();

def buySignal2 = if MD > WS and MD[1] <= WS[1] and expaverage(close,8) > average(close,13) then 1 else 0;
def sellSignal2 = if MD < WS and MD[1] >= WS[1] and expaverage(close,85) < average(close,13) then 1 else 0;
plot signal2 = if buySignal2 or sellSignal2 then MD else double.nan;
signal2.assignValueColor(if buySignal2 then color.WHITE else color.YELLOW);
signal2.setLineWeight(5);
signal2.SetStyle(curve.points);
#signal2.setpaintingstrategy(paintingStrategy.SQUARES);

Here is the simplified version that paints your candles to the trend of the indicator.

Code:
#McGinleyIndicator
declare upper;

input periods = 10;

rec _md = CompoundValue( 1, _md[1] + (( close - _md[1] ) / ( periods * Power( close / _md[1], 4 ) ) ), close );

plot MD = _md;
AssignPriceColor(if MD > MD[1] then Color.GREEN else Color.RED);

Shareable Link

https://tos.mx/XqTZTf
Credits:
 

Attachments

  • nZaCklD.png
    nZaCklD.png
    93.1 KB · Views: 212
This indicator seems to give much more information for a better trade with the following plots. It seems the other plots were added to the McGinley Dynamic Indicator but I think they enhance it.

Data - ON
Date2 - ON
EMA8 - OFF
Signal - ON
WS - OFF
MD - OFF
Signal2 - OFF because seems to be a late or confirming signal

Tried to paste a chart image but not sure how to use the new insert image.

Thank You for posting.
 
Last edited by a moderator:
Hi @mc01439 and @BenTen - Thanks for sharing this. Do you guys have any descriptions of the multiple inputs and the plots on this indicator and what they mean?
 
@mc01439 Thanks for the reply!

Are the 2 lines in your screenshot: Data and Data2 from the study that @BenTen posted?

On mobile now, will go home and install your shared study - Thanks again!
 
@gang - No the one attached is the high and low bands of the MDI by Mobius that I referenced in post #9.
 
@David45 Try this Detrended MACD

Code:
# Detrended MACD

# Mobius

# V01.04.2015

 

declare lower;

 

input fastLength = 12;

input slowLength = 26;

input MACDLength = 9;

input averageType = AverageType.EXPONENTIAL;

input showBreakoutSignals = no;

 

plot Value = MovingAverage(averageType, close + (close - close[(fastlength-1)/2]), fastLength) - MovingAverage(averageType, close + (close - close[(slowLength-1)/2]), slowLength);

plot Avg = MovingAverage(averageType, Value, MACDLength);

 

plot Diff = Value - Avg;

plot ZeroLine = 0;

 

plot UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;

plot DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;

 

UpSignal.SetHiding(!showBreakoutSignals);

DownSignal.SetHiding(!showBreakoutSignals);

 

Value.SetDefaultColor(GetColor(1));

Avg.SetDefaultColor(GetColor(8));

Diff.SetDefaultColor(GetColor(5));

Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

Diff.SetLineWeight(3);

Diff.DefineColor("Positive and Up", Color.GREEN);

Diff.DefineColor("Positive and Down", Color.DARK_GREEN);

Diff.DefineColor("Negative and Down", Color.RED);

Diff.DefineColor("Negative and Up", Color.DARK_RED);

Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));

ZeroLine.SetDefaultColor(GetColor(0));

UpSignal.SetDefaultColor(Color.UPTICK);

UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

DownSignal.SetDefaultColor(Color.DOWNTICK);

DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

# End Code Detrended MACD
 
not clean but i think this is closer to the intended implementation data2 is my take. length is how long before to start creating the MGI and N is smoothing.

Code:
# McGinley Dynamic Indicator
# Mobius
# V02.11.2011
#  D = D1 + ((I - D1) / ( N * (I/D1)^4))
# where D1= yesterday's Dynamic, I = today's price, N = smoothing factor.

input value= close;
input length= 20;
input Slength = 5;
input N = 20;
def A1= ExpAverage(value, length)[1];
def MDI = A1 + ((value - A1) / 0.6*power(value / A1, 4));
plot Data = MDI; #ExpAverage(MDI, Slength);
Data.SetPaintingStrategy(PaintingStrategy.LINE);
Data.SetLineWeight(2);

plot data2 =fold i = 0 to length
           with s = getvalue (close, length+1)
           do   (s + ((getvalue(close,length-i)-s)/(0.6*N*power(getvalue(close,length-i)/s ,4)) )) ;
 
@Hustle Detrended MACD is basically the same as the regular MACD but all the lengths are shorten by half. You can use the the MACD MTF here and adjust the length from there.
 
I tried to use the Mc Ginley with the Higs and Lows.
Maybe it could be used
  • to go Long if Price closes over the MCG Higs, Exit when Price touches the MCG Lows
  • to go Short if Price closes below the MCG Lows, Exit when Price touches the MCG Higs
Maybe this could be an approach.

0Tjtn7x.png


Maybe one more detail to use it in connection after the breakout of BB Squeeze

fch4XLS.png
 
@samoya I like this one too

Code:
# Mobius
# V04.05.2014

#  D = D[1] + (I - D[1]) / ( N * (I/D[1])^4)
# where D[1] = yesterday's Dynamic, I = today's price, N = smoothing factor.
# Self Adjusting with Fractal Dimensions Algorithm
#re-labelled MDI with 'a' to avoid conflict with above script



input I = close;
input N = 10;
input AscaleLow = 3;
input AscaleHigh = 10;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;


def o;

def h;

def l;

def c;

def TR;

def B;
def sDev = stdev(data = I, length = N);
def Ascaled;



# Internal Script

script Scale {

    input c = close;

    input Min = .01;

    input Max =   1;

    def hh = HighestAll(c);

    def ll   = LowestAll(c);

    plot Range = (((Max - Min) * (c - ll)) /  (hh - ll)) + Min;

}

# Calculations

o = (open + close[1]) / 2;

h = Max(high, close[1]);

l = Min(low, close[1]);

c = (o + h + l + close) / 4;

TR = Max(h, c[1]) - Min(l, c[1]);

B = (Log(Sum(TR, N) / (Highest(h, N) - Lowest(l, N))) 

             / Log(10)) / (Log(N) / Log(10));

Ascaled = Round(Scale(c = B, min = AscaleLow, max = AscaleHigh), 2);



def D;

D = CompoundValue(1, D[1] + (I - D[1]) /  Ascaled * (Power((I / D[1]), 4)), I);



plot MDIa = D;

MDIa.SetPaintingStrategy(PaintingStrategy.LINE);

MDIa.SetLineWeight(2);

mdia.AssignValueColor(if mdia < mdia[1] then Color.red else if mdia > mdia[1] then Color.green else Color.white);

  MDIa.SetDefaultColor(GetColor(8));



addlabel(1, ( "McGinley Frac=" + MDIa ), if mdia < mdia[1] then color.magenta else color.cyan);

plot LowerBand = D + num_Dev_Dn * sDev;
plot UpperBand = D + num_Dev_Up * sDev;
 
@ibenjamin305
The Shared Link: https://tos.mx/gYEjjz0 works just fine
Try clicking on the below for foolproof instructions on loading shared links
Easiest way to load shared links
td48Xus.png

or you can just copy the study below:
Ruby:
# McGinley Dynamic Indicator
# Mobius
# V02.11.2011
#  D = D1 + ((I - D1) / ( N * (I/D1)^4))
# where D1= yesterday's Dynamic, I = today's price, N = smoothing factor.

input value= close;
input length= 20;
input Slength = 5;
def A1= ExpAverage(value, length)[1];
def MDI = A1 + ((value - A1) / Sqr(value / A1));
plot Data = ExpAverage(MDI, Slength);
Data.SetPaintingStrategy(PaintingStrategy.LINE);
Data.SetLineWeight(2);
#Data.SetDefaultColor(GetColor(8));
def A2 = ExpAverage(value, length*3)[1];
def MDI2 = A2 + ((value - A2) / Sqr(value / A2));
plot Data2 = ExpAverage(MDI2, Slength*3);
Data2.DefineColor("Data2_SlopePos", Color.GREEN);
Data2.DefineColor("Data2_SlopeNeg", Color.MAGENTA);
Data2.AssignValueColor(if Data  > Data2 then Data2.Color("Data2_SlopePos") else Data2.Color("Data2_SlopeNeg"));
Data2.setlineweight(2);
data2.hide();
Data.DefineColor("Data_SlopePos", Color.CYAN);
Data.DefineColor("Data_SlopeNeg", Color.RED);
Data.AssignValueColor(if Data  > Data2 then Data.Color("Data_SlopePos") else Data.Color("Data_SlopeNeg"));
data.hide();
plot EMA8 = expaverage(close,8);
EMA8.setdefaultcolor(color.DARK_ORANGE);
EMA8.setlineweight(2);
EMA8.hide();
# End Code ------------
def buySignal = if Data > Data2 and Data[1] <= Data2[1] and expaverage(close,8) > average(close,13) then 1 else 0;
def sellSignal = if Data < Data2 and Data[1] >= Data2[1] and expaverage(close,85) < average(close,13) then 1 else 0;
plot signal = if buySignal or sellSignal then Data else double.nan;
signal.assignValueColor(if buySignal then color.WHITE else color.YELLOW);
signal.setLineWeight(5);
#signal.SetStyle(curve.points);
signal.setpaintingstrategy(paintingStrategy.SQUARES);

# additional plots from yahoo forum
input price = close;
input length2 = 14;
input displace = 0;
plot WS = WildersAverage(price[-displace], length2);
WS.setDefaultColor(GetColor(8));
input periods = 10;
rec _md = compoundValue( 1, _md[1] + (( close - _md[1] ) / ( periods *
power( close / _md[1], 4 ) ) ), close );
plot MD = _md;
MD.setdefaultcolor(color.CYAN);
MD.setlineweight(2);
MD.hide();

def buySignal2 = if MD > WS and MD[1] <= WS[1] and expaverage(close,8) > average(close,13) then 1 else 0;
def sellSignal2 = if MD < WS and MD[1] >= WS[1] and expaverage(close,85) < average(close,13) then 1 else 0;
plot signal2 = if buySignal2 or sellSignal2 then MD else double.nan;
signal2.assignValueColor(if buySignal2 then color.WHITE else color.YELLOW);
signal2.setLineWeight(5);
signal2.SetStyle(curve.points);
#signal2.setpaintingstrategy(paintingStrategy.SQUARES);
 
Last edited:
Is there any way to develop a scan to pinpoint when McGinley Dynamic crosses price? I tried to do it with a custom scan but the save doesn't light so I couldn't save. This would develop an alert that could be used in a scan.

TY in advance!
 
Help to overlay an Indicator from higher time frame. Plz!
Hi peeps. I would like to have this indicator based on a 30min time frame, overlayed on a 5 min chart. Could some please help out, I'd appreciate it greatly. Thanks

# Archive Name: McGinley Dynamic Indicator_Mobius
# Archive Section: Trend
# Suggested Tos Name: McGinleyDynamicIndicator_Mobius
# Archive Date: 5.05.2018
# Archive Notes: Lounge 5.02.2018
# 16:59 Mobius: An oldie but goodie
# 17:01 Mobius: The lag on that is only a few bars and that lag can be mostly removed by detrending it by half the input length

# A More Advanced Adaptive Moving Average
# McGinley Dynamic Indicator
# Mobius
# V03.11.2011
# D = D[1] + (I - D[1]) / ( N * (I/D[1])^4)
# where D[1] = yesterday's Dynamic, I = today's price, N = smoothing factor.

input I = close;
input N = 13;

def D;
D = CompoundValue(1, D[1] + (I - D[1]) / (N * Power((I / D[1]), 4)), I);

plot MDI = D;
MDI.SetPaintingStrategy(PaintingStrategy.LINE);
MDI.SetLineWeight(1);
MDI.SetDefaultColor(Color.White);

# End Code McGinley Dynamic Indicator
 
Last edited by a moderator:

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
532 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