McGinley PercentB MACD Setup For ThinkOrSwim


Active member
i'm just going to throw this in here since it relates to the other McGinley thread. the code comes from mobius. i haven't seen the indicator talked about anywhere else.

Mobius: when McGinley PercentB crosses above 0 set at 3 St Deviations and it's ATR set at 2 and the Zero Lag MACD set at 5,13,3 crosses above 0 it's a very high percentage positive trade

# McGinley PercentB
#it's price relative to an upper and lower standard deviation band. 100 top of bands 0 bottom of bands. 
#Make it 3 standard deviations and 2 ATR's and you effectively capture 99% of the data maintaining the better squeeze signals 
#and giving pretty clear buy signals on lower aggregations such as 5 min
# Mobius
# A better PercentB
# V01.2014

declare lower;

input I = close;
input N = 20;
input SDmult = 2.0;
input KCmult = 1.5;

def o;
def h;
def l;
def c;
def D;
def SD;
def ATR;
def MidLine;
def UpperBB;
def UpperKC;
def LowerBB;
def lowerKC;
o = open;
h = high;
l = low;
c =close;
plot PercentB;
D = CompoundValue(1, D[1] + (I - D[1]) / N * (Power((I / D[1]), 4)), I);
SD = StDev(I, N);
ATR = Average(TrueRange(h, c, l), N);
MidLine = D;
UpperBB = D + (SDmult * SD);
UpperKC = D + (KCmult * ATR);
LowerBB = D + (-SDmult * SD);
LowerKC = D + (-KCmult * ATR);
PercentB = 100 * ((I - LowerBB) / (UpperBB - LowerBB));
PercentB.AssignValueColor(if PercentB Crosses above 0
then Color.Yellow
else if UpperBB < UpperKC
then Color.Blue
else if PercentB < 0
then Color.Red
else Color.Cyan);
AddLabel(D crosses above 0, "Crossing Above 0", Color.Yellow);
AddLabel(UpperBB < UpperKC, "Squeeze", Color.Blue);
AddLabel(D < 0, "Less Than 0", Color.Red);
# End Code McGinley PercentB

oh, and here's the zero lag MACD that mobius refers to:

# Super Zero Lag MACD
# Mobius

declare lower;
input Fast_Length = 5;
input Slow_Length = 13;
input MACD_Length = 3;
plot MACD5 = (MACD("fast length" = Fast_Length,
                   "slow length" = Slow_Length,
                   "macd length" = MACD_Length).Avg /
        StDev(MACD("fast length" = Fast_Length,
                   "slow length" = Slow_Length,
                   "macd length" = MACD_Length).Diff, Slow_Length));
plot Squeeze = if BollingerBandsSMA().UpperBand < KeltnerChannels().Upper_Band
               then 0
               else Double.NaN;
plot zero = if IsNaN(close) or !IsNaN(Squeeze) then Double.NaN else 0;
AddCloud(zero, MACD5, Color.RED, Color.GREEN);
AddCloud(Squeeze, MACD5, Color.RED, Color.GREEN);
AddLabel(!IsNaN(Squeeze), "Squeeze", if MACD5 > MACD5[1] and
                                MACD5 < 0
                             then Color.GREEN
                             else Color.RED);
def day = GetValue(GetYYYYMMDD(), 1);
def trend = if close > (Highest(high, 21) + Lowest(low, 21)) / 2
            then 1
            else 0;
AddLabel(1, if trend == 1
            then "Trend Up"
            else "Trend Dn",
            if trend == 1
            then Color.Green
            else Color.Red);
Last edited by a moderator:

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
150 Online
Create Post

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.