McGinley Dynamic (Improved) - John R. McGinley, Jr.

For all the McGinley enthusiasts out there, this is my improved version of the "McGinley Dynamic", originally formulated and publicized in 1990 by John R. McGinley , Jr. Prior to this release, I recently had an encounter with a member request regarding the reliability and stability of the general algorithm. Years ago, I attempted to discover the root of it's inconsistency, but success was not possible until now. Being no stranger to a good old fashioned computational crisis, I revisited it with considerable contemplation.

I discovered a lack of constraints in the formulation that either caused the algorithm to implode to near zero and zero OR it could explosively enlarge to near infinite values during unusual price action volatility conditions, occurring on different time frames. A numeric E-notation in a moving average doesn't mean a stock just shot up in excess of a few quintillion in value from just "10ish" moments ago. Anyone experienced with the usual McGinley Dynamic, has probably encountered this with dynamically dramatic surprises in their chart, destroying it's usability.

Well, I believe I have found an answer to this dilemma of 'susceptibility to miscalculation', to provide what is most likely McGinley's whole hearted intention. It required upgrading the formulation with two constraints applied to it using min/max() functions. Let me explain why below.

When using base numbers with an exponent to the power of four, some miniature numbers smaller than one can numerically collapse to near 0 values, or even 0.0 itself. A denominator of zero will always give any computational device a horribly bad day, not to mention the developer. Let this be an EASY lesson in computational division, I often entertainingly express to others. You have heard the terminology "$#|T happens!🙂" right? In the programming realm, "AnyNumber/0.0 CAN happen!🤪" too, and it happens "A LOT" unexpectedly, even when it's highly improbable. On the other hand, numbers a bit larger than 2 with the power of four can tremendously expand rapidly to the numeric limits of 64-bit processing, generating ginormous spikes on a chart.

The ephemeral presence of one OR both of those potentials now has a combined satisfactory remedy , AND you as TV members now have it, endowed with the ever evolving "Power of Pine". Oh yeah, this one plots from bar_index==0 too. It also has experimental settings tweaks to play with, that may reveal untapped potential of this formulation. This function now has gain of function capabilities, NOT to be confused with viral gain of function enhancements from reckless BSL-4 leaking laboratories that need to be eternally abolished from this planet. Although, I do have hopes this imd () function has the potential to go viral. I believe this improved function may have utility in the future by developers of the TradingView community. You have the source, and use it wisely...

I included an generic ema () plot for a basic comparison, ultimately unveiling some of this algorithm's unique characteristics differing on a variety of time frames. Also another unconstrained function is included to display some the disparities of having no limitations on a divisor in the calculation. I strongly advise against the use of umd() in any published script. There is simply just no reason to even ponder using it. I also included notes in the script to warn against this. It's funny now, but some folks don't always read/understand my advisories... You have been warned!

NOTICE: You have absolute freedom to use this source code any way you see fit within your new Pine projects, and that includes TV themselves. You don't have to ask for my permission to reuse this improved function in your published scripts, simply because I have better things to do than answer requests for the reuse of this simplistic imd () function. Sufficient accreditation regarding this script and compliance with "TV's House Rules" regarding code reuse, is as easy as copying the entire function as is. Fair enough? Good! I have a backlog of "computational crises" to contend with, including another one during the writing of this elaborate description.

When available time provides itself, I will consider your inquiries, thoughts, and concepts presented below in the comments section, should you have any questions or comments regarding this indicator. When my indicators achieve more prevalent use by TV members , I may implement more ideas when they present themselves as worthy additions. Have a profitable future everyone!
Release Notes: Provided the resolution= parameter to study() to offer MTF capabilities
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Want to use this script on a chart?


500 coins
+1 Reply
I am a huge fan of the McGinley Dynamic
Over time I have made so many tweaks and adjustments to it
The McGinley Dynamic is the core or center of my TA

having spent quite a few hours playing with your code or should I say your version of the McGinley Dynamic
I have to say wow this is awesome !!!

this is not just a hd remaster its a full on remake from the ground up

But the awesome thing is that YES I totally agree with you "most likely McGinley's wholehearted intention"
You nailed it

I have tried a million times to replace the McGinley Dynamic on my chart but I never found something that was actually able to replace it

BUT now I have
thank you for this publication I am very grateful :) !!!
+7 Reply
iamthree iamthree
@iamthree, I wish I could like this indicator twice !!! :)
+1 Reply
MasBart iamthree
@iamthree, may I know why do you prefer it so much? Thanks beforehand.
@MasBart, I don't know about @iamthree, but numerous other members seem to find it preferable for numerous reasons of their choosing. What the McGinley Dynamic is, is in fact an adaptive(dynamic) ema(). John McGinley named it very appropriately. That's one reason why I comparatively included the companion ema(). One of the benefits of adapting algorithms is in many situations improved characteristics from what it ordinarily would be. Most importantly, the markets are always in a state of dynamic flux, so being able to "dynamically" adapt to those situations is commonly better than repetitive arduous manual adjustments.

A brief example, when driving a vehicle straight, roadways have many imperfections causing drift. With this, we always have to make adaptive corrections in steering to be optimally centered in our lane, reducing the "risk" of collision. Without this ability to make micro adjustments easily, driving would be more tumultuous for us. The power steering in MD appears to be a much better driver at higher speeds when traveling down hill. I'm not implying it would be applicable to self-driving vehicles, but who knows...

Just as lag will always plaque moving averages, the McGinley Dynamic effectively minimalizes the lag of ema() specifically in down trends, from my observations. Now that I have provided improved operation for MD, I think another door of exploration has been opened concerning the potential use of OR even adaptation of this algorithm into another enhanced form. It clearly provides a better model than the ordinary ema() in more than one way. I have yet to use it many other complex algorithms that utilize ema(), we'll see.
+2 Reply
MasBart midtownsk8rguy
@midtownsk8rguy, thanks for your clear and comprehensive explanation. Best regards.
iamthree MasBart
@MasBart, yes @midtownsk8rguy his explanation nailed it !!! spot on
I like the ema ribbon because it is more responsive than the traditional sma
But this McGinley Dynamic I can adjust the k and exponential values WHICH IS AWESOME !!!
As well as this McGinley Dynamic does not suffer from a lot of the quirks that the original does

just try using the traditional McGinley Dynamic on a 2 day or higher time frame on BTC it does not work at times
so I like the ability to adjust the values I love to tweak and dial in settings

as well as I 100% agree this is staying true to the original vision of the McGinley Dynamic
to me it is in the spirit of that indicator but taking its intention a huge step further

frankly, I have been looking to replace the McGinley Dynamic but I was never able to
the McGinley Dynamic is a core pillar of how I gage or view a chart

@MasBart put the standard McGinley Dynamic on your chart and hop around different time frames with this new one
and you will see

Even if you set this new McGinley Dynamic to the traditional mode or values it still performed better with less anomalies

Mid town sk8rguy is the man !!! and I am 100% grateful to have access to this wonderful algo script :)
A tool in the right hands
or the horses for course
or the right tool for the job :) good luck
@iamthree, Stay tuned. I already have another intention to apply imd() in another scenario, which might theoretically exhibit characteristics even more superior, depending on it's stability. I have to find time to create it and then study it in depth. We'll see... I may even request a Pine md() built in from TV, if it has the prowess I believe it has. They might accept a proposal worthy enough to provide a handy native Pine function. Anybody else who can provide information to support that, this is the place for a voluntary open discussion.
+3 Reply
iamthree midtownsk8rguy
@midtownsk8rguy, YO Man !!! I would love to test and report findings for any indicators you are building :)
I have multiple time frames and patterns that I run indicators though
I love tweaking and adjusting settings and variables :)

If you are ever needing someone to spend 15 hours a day playing with multi-color lines on charts I am your guy (hahahhahaha )
@iamthree, I'm pretty much doing the same. Always pondering something new or searching for untapped potential. Not that 15 hours in a day leads to unique sure things worthy of use in every case for me. This publication was an all day eye opening adventure though. If you should find any utility in this one with the tweaked settings other than 0.6 and pow(4.0), let me know...
+1 Reply