MACD SQUEEZE [Bathula] For ThinkOrSwim

kaiso

New member
VIP
mod note:
Squeeze Trade Summary per Google search:
Look for price to be in a range or consolidation phase.
MACD histogram should be displaying a flat pattern with no evident peaks or troughs.
Await the price movement breaking out of the established market phase, to confirm direction
Validate the breakout by confirming an increase in volume


vzMqct2.png

https://www.tradingview.com/script/GHlxc37J-MACD-SQUEEZE-Bathula/
 
Last edited by a moderator:

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

fine below

CSS:
#//@version=3
#study("MACD SQUEEZE [Bathula]")
# converted by Sam4Cok@Samer800    - Request from useThinkScript.com member
Declare lower;

input movAvgType = AverageType.EXPONENTIAL;
input BollingerSource = hlc3;     # "Source"
input BollingerLength = 12;       # "Bollinger length")
input BollingerMulti  = 2.0;      # "Bollinger deviation")
input keltnerSource   = close;    # "Source"
input keltnerLength   = 25;       # "keltner Length")
input KeltnerMulti    = 1.25;     # "Keltner deviation")
input macdSource      = close;    # "Source"
input macdFastLength  = 12;
input macdSlowLength  = 26;
input macdSignalLength = 12;

def na = Double.NaN;
def last = isNaN(close);
#//Keltner
def nATR = ATR(Length = keltnerLength);
def kUpper = MovingAverage(movAvgType, keltnerSource, keltnerLength) + KeltnerMulti * nATR;
def kLower = MovingAverage(movAvgType, keltnerSource, keltnerLength) - KeltnerMulti * nATR;
#//--- Bollinger
def stdv = stdev(BollingerSource, BollingerLength);
def bbUpper = MovingAverage(movAvgType, BollingerSource, BollingerLength) + BollingerMulti * stdv;
def bbLower = MovingAverage(movAvgType, BollingerSource, BollingerLength) - BollingerMulti * stdv;
#//--- BB Squeeze
def squeeze = bbUpper <= kUpper and bbLower >=kLower;
#//macd
def fastMA = MovingAverage(movAvgType, macdSource, macdFastLength);
def slowMA = MovingAverage(movAvgType, macdSource, macdSlowLength);
def macd = fastMA - slowMA;
def signal = Average(macd, macdSignalLength);
def hist = macd - signal;

#//plots
plot macdLine = macd;
plot sigLine  = signal;
plot zero = if last then na else 0; # "Squeeze indicator"
plot Histogram = hist;              # "Histogram"

zero.SetPaintingStrategy(PaintingStrategy.SQUARES);
zero.AssignValueColor(if squeeze then Color.YELLOW else Color.DARK_GRAY);
Histogram.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
Histogram.AssignValueColor(if hist>=0 then (if hist[1] < hist then Color.GREEN else Color.DARK_GREEN) else
                                           (if hist[1] < hist then Color.DARK_RED else Color.RED));
macdLine.SetDefaultColor(Color.CYAN);
sigLine.SetDefaultColor(Color.MAGENTA);

#-- End of CODE
 
fine below

CSS:
#//@version=3
#study("MACD SQUEEZE [Bathula]")
# converted by Sam4Cok@Samer800    - Request from useThinkScript.com member
Declare lower;

input movAvgType = AverageType.EXPONENTIAL;
input BollingerSource = hlc3;     # "Source"
input BollingerLength = 12;       # "Bollinger length")
input BollingerMulti  = 2.0;      # "Bollinger deviation")
input keltnerSource   = close;    # "Source"
input keltnerLength   = 25;       # "keltner Length")
input KeltnerMulti    = 1.25;     # "Keltner deviation")
input macdSource      = close;    # "Source"
input macdFastLength  = 12;
input macdSlowLength  = 26;
input macdSignalLength = 12;

def na = Double.NaN;
def last = isNaN(close);
#//Keltner
def nATR = ATR(Length = keltnerLength);
def kUpper = MovingAverage(movAvgType, keltnerSource, keltnerLength) + KeltnerMulti * nATR;
def kLower = MovingAverage(movAvgType, keltnerSource, keltnerLength) - KeltnerMulti * nATR;
#//--- Bollinger
def stdv = stdev(BollingerSource, BollingerLength);
def bbUpper = MovingAverage(movAvgType, BollingerSource, BollingerLength) + BollingerMulti * stdv;
def bbLower = MovingAverage(movAvgType, BollingerSource, BollingerLength) - BollingerMulti * stdv;
#//--- BB Squeeze
def squeeze = bbUpper <= kUpper and bbLower >=kLower;
#//macd
def fastMA = MovingAverage(movAvgType, macdSource, macdFastLength);
def slowMA = MovingAverage(movAvgType, macdSource, macdSlowLength);
def macd = fastMA - slowMA;
def signal = Average(macd, macdSignalLength);
def hist = macd - signal;

#//plots
plot macdLine = macd;
plot sigLine  = signal;
plot zero = if last then na else 0; # "Squeeze indicator"
plot Histogram = hist;              # "Histogram"

zero.SetPaintingStrategy(PaintingStrategy.SQUARES);
zero.AssignValueColor(if squeeze then Color.YELLOW else Color.DARK_GRAY);
Histogram.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
Histogram.AssignValueColor(if hist>=0 then (if hist[1] < hist then Color.GREEN else Color.DARK_GREEN) else
                                           (if hist[1] < hist then Color.DARK_RED else Color.RED));
macdLine.SetDefaultColor(Color.CYAN);
sigLine.SetDefaultColor(Color.MAGENTA);

#-- End of CODE
Thank you
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
378 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