Squeeze w/ Momentum For ThinkOrSwim

Below is a code which creates a squeeze study with an overlayed momentum oscillator.... In full disclosure, this is my first ever post/code and I can only take credit for this because I took bits of other folks scripts, tweaked them just a little and combined them into this one.... but it certainly works well!.

Hope it helps someone... and IF anyone that's good with coding wants to return the favor... I could use some help getting it to plot as a study on the mobile app....

I can get the full, working squeeze to plot on the phone... and I can get the momentum oscillator.. but they have to both be separate study's and are not overlayed like this.

Thanks for everyone's codes!

Code:
#Squeeze w/ Momentum
#by @somebritishbloke 3/13/22
declare lower;
input length = 20;
input slength = 6;
input SigLength = 3;
input arrows = 0;
input dotsize = 3;
input APC = 0;
plot s2 = ExpAverage(close, slength) - ExpAverage(close, length);
s2.setdefaultColor(Color.Cyan);
s2.SetLineWeight(2);
s2.HideBubble();
Plot Signal = ExpAverage(s2,Siglength);
Signal.SetdefaultColor(Color.Magenta);
signal.SetLineWeight(2);
Def Con1 = s2 >= 0;
Def Con2 = s2 < 0;
Def Con3 = s2 > s2[1];
Def Con4 = s2 < s2[1];
AssignPriceColor( if APC ==1 and s2 >= signal then Color.Cyan else if APC == 1 and s2 < Signal then Color.Magenta else If APC ==2 and s2 >=0 then Color.Green else If APC ==2 and s2 <0 then Color.Red else Color.Current);

input price = close;

input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.SIMPLE;
input displace = 0;
def sDev = StDev(data = price[-displace], length = length);
def MidLineBB = MovingAverage(averageType, data = price[-displace], length = length);
def LowerBandBB = MidLineBB + Num_Dev_Dn * sDev;
def UpperBandBB = MidLineBB + Num_Dev_up * sDev;
input factorhigh = 1.0;
input factormid = 1.5;
input factorlow = 2.0;
input trueRangeAverageType = AverageType.SIMPLE;
def shifthigh = factorhigh * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def shiftMid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def shiftlow = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
def average = MovingAverage(averageType, price, length);

def Avg = average[-displace];

def UpperBandKCLow = average[-displace] + shiftlow[-displace];
def LowerBandKCLow = average[-displace] - shiftlow[-displace];

def UpperBandKCMid = average[-displace] + shiftMid[-displace];
def LowerBandKCMid = average[-displace] - shiftMid[-displace];

def UpperBandKCHigh = average[-displace] + shifthigh[-displace];
def LowerBandKCHigh = average[-displace] - shifthigh[-displace];

def K = (Highest(high, length) + Lowest(low, length)) /
2 + ExpAverage(close, length);
def momo = Inertia(price - K / 2, length);

def pos         = momo>= 0;
def neg         = momo< 0;
def up         = momo >= momo[1];
def dn         = momo < momo[1];

def presqueeze      = LowerBandBB > LowerBandKCLow and UpperBandBB < UpperBandKCLow;
def originalSqueeze     = LowerBandBB > LowerBandKCMid and UpperBandBB < UpperBandKCMid;
def ExtrSqueeze     = LowerBandBB > LowerBandKCHigh and UpperBandBB < UpperBandKCHigh;

def PosUp = pos and up;
def PosDn = pos and dn;
def NegDn = neg and dn;
def NegUp = neg and up;

plot squeezeline = 0;
squeezeline.SetPaintingStrategy(PaintingStrategy.POINTS);
squeezeline.AssignValueColor(if ExtrSqueeze then Color.RED else if originalSqueeze  then Color.YELLOW else if presqueeze then Color.DARK_ORANGE else Color.black);

plot momentum = momo;
momentum.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
momentum.AssignValueColor( if PosUp then Color.green else if PosDn then Color.dark_green else if NegDn then Color.red else if NegUp then Color.dark_red else Color.YELLOW);
 
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
284 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