@GetRichOrDieTrying Try the following code to see whether it performs better for your needs... I found several other price references within the code that benefit from the aggregation period modification... Let me know how the modified code performs...
Ruby:
# TTM_Squeeze_Pro_Selectable_Aggregation
#
# Assembled by TheBewb using existing Mobius Squeeze Momentum coding and "squeeze" concept made popular by John Carter.
#
# Modified 2021-07-27 by rad14733 for usethinkscript.com
# Added code to allow AggregationPeriod selection
# Added code to allow styling modifications
# Default colors are in standard TTM_Squeeze style
# Colors can be edited via study settings or in the code for TTM_Squeeze_Pro style
# v1.0 : 2021-07-27 : Initial Release
# v1.1 : 2021-07-28 : Implemented additional aggregation period prices within the code
declare lower;
input agg = AggregationPeriod.THIRTY_MIN;
def price = close(period = agg);
input length = 20;
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(period = agg), close(period = agg), low(period = agg)), length);
def shiftMid = factormid * MovingAverage(trueRangeAverageType, TrueRange(high(period = agg), close(period = agg), low(period = agg)), length);
def shiftlow = factorlow * MovingAverage(trueRangeAverageType, TrueRange(high(period = agg), close(period = agg), low(period = agg)), 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(period = agg), length) + Lowest(low(period = agg), length)) / 2 + ExpAverage(close(period = agg), 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.DefineColor("NoSqueeze", Color.GREEN);
squeezeline.DefineColor("PreSqueeze", Color.GRAY);
squeezeline.DefineColor("OriginalSqueeze", Color.RED);
squeezeline.DefineColor("ExtrSqueeze", Color.ORANGE);
squeezeline.SetPaintingStrategy(PaintingStrategy.POINTS);
squeezeline.SetLineWeight(3);
squeezeline.AssignValueColor(if ExtrSqueeze then squeezeline.Color("ExtrSqueeze") else if originalSqueeze then squeezeline.Color("OriginalSqueeze") else if presqueeze then squeezeline.Color("PreSqueeze") else squeezeline.Color("NoSqueeze"));
plot momentum = momo;
momentum.DefineColor("PosUp", Color.CYAN);
momentum.DefineColor("PosDn", Color.BLUE);
momentum.DefineColor("NegDn", Color.DARK_RED);
momentum.DefineColor("NegUp", Color.YELLOW);
momentum.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
momentum.SetLineWeight(3);
momentum.AssignValueColor(if PosUp then momentum.Color("PosUp") else if PosDn then momentum.Color("PosDn") else if NegDn then momentum.Color("NegDn") else if NegUp then momentum.Color("NegUp") else momentum.Color("NegUp"));
# END - TTM_Squeeze_Pro_Selectable_Aggregation
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
All - I've been working on building a comparable setup to John Carter's squeeze pro labels + histogram labels.
I was able to modify code I found here to accomplish the "squeeze pro" portion of this. Unfortunately, it is tough to find a histogram that matches Carter's. Mobius' code has a good histogram but I find it not nearly as smooth as John Carter's. However, I found the "Awesome Oscillator" in TOS to be very close to the TTM_Squeeze histogram when you modify the 2 period lengths in the code to be 9 & 21 instead of 5 & 34. I took this logic and built an "MTF histogram label" that sits just underneath the squeeze label...similar to JC's. I've watched several of his videos and confirmed that the squeeze portion of my code works verbatim to his. The histogram is not exact but it is "damn close."
Pic of my setup here:
Here is a link to my shared grid, containing the histogram & squeeze labels: https://tos.mx/xkLakTN
Color legend for those unfamiliar:
Top row are the squeezes - Gray = low squeeze, Red = med squeeze (same as the original TTM_Squeeze indicator) and Yellow = high squeeze (this is the tightest squeeze). Green indicates no squeeze.
All - I've been working on building a comparable setup to John Carter's squeeze pro labels + histogram labels.
I was able to modify code I found here to accomplish the "squeeze pro" portion of this. Unfortunately, it is tough to find a histogram that matches Carter's. Mobius' code has a good histogram but I find it not nearly as smooth as John Carter's. However, I found the "Awesome Oscillator" in TOS to be very close to the TTM_Squeeze histogram when you modify the 2 period lengths in the code to be 9 & 21 instead of 5 & 34. I took this logic and built an "MTF histogram label" that sits just underneath the squeeze label...similar to JC's. I've watched several of his videos and confirmed that the squeeze portion of my code works verbatim to his. The histogram is not exact but it is "damn close."
Pic of my setup here:
Here is a link to my shared grid, containing the histogram & squeeze labels: https://tos.mx/xkLakTN
Color legend for those unfamiliar:
Top row are the squeezes - Gray = low squeeze, Red = med squeeze (same as the original TTM_Squeeze indicator) and Yellow = high squeeze (this is the tightest squeeze). Green indicates no squeeze.
I think the squeeze code could just be substituted for the code use in above posts, but I am not sure how to convert these input variables to the ones used used in this thread, and trying to avoid rewriting the aggregations code.
It looks like I cutoff some of the code. paste this at the bottom of my last post.
It's a lower study. The colors represent the dots on the squeeze.
My hope is to make a label - just like yours - that tells me what color dot the squeeze is at for a given timeframe.
(i.e. - if the 5 minute squeeze is a black dot, the 5M label would be black)
Code:
def midSqueeze = BolKelDelta_Mid <= 0;
def triggerMid = if sum(midSqueeze,triggerBars) == triggerBars and !midSqueeze[triggerBars] then 1 else 0;
plot signalMidLong = if triggerMid and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and oscillator > 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and oscillator > oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator > oscillator[1] and oscillator < 0 )) then low-signalOffset else double.nan;
signalMidLong.SetPaintingStrategy(paintingStrategy.ARROW_UP);
signalMidLong.setDefaultColor(color.red);
signalMidLong.setLineWeight(5);
plot signalMidShort = if triggerMid and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and oscillator <= 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and oscillator < oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator < oscillator[1] and oscillator > 0 )) then high+signalOffset else double.nan;
signalMidShort.SetPaintingStrategy(paintingStrategy.ARROW_Down);
signalMidShort.setDefaultColor(color.red);
signalMidShort.setLineWeight(5);
def highSqueeze = BolKelDelta_High <= 0;
def triggerHigh = if sum(highSqueeze,triggerBars) == triggerBars and !highSqueeze[triggerBars] then 1 else 0;
plot signalHighLong = if triggerHigh and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and oscillator > 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and oscillator > oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator > oscillator[1] and oscillator < 0 )) then low-signalOffset else double.nan;
signalHighLong.SetPaintingStrategy(paintingStrategy.ARROW_UP);
signalHighLong.setDefaultColor(color.dark_orange);
signalHighLong.setLineWeight(5);
plot signalHighShort = if triggerHigh and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and oscillator <= 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and oscillator < oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator < oscillator[1] and oscillator > 0 )) then high+signalOffset else double.nan;
signalHighShort.SetPaintingStrategy(paintingStrategy.ARROW_Down);
signalHighShort.setDefaultColor(color.dark_orange);
signalHighShort.setLineWeight(5);
It looks like I cutoff some of the code. paste this at the bottom of my last post.
It's a lower study. The colors represent the dots on the squeeze.
My hope is to make a label - just like yours - that tells me what color dot the squeeze is at for a given timeframe.
(i.e. - if the 5 minute squeeze is a black dot, the 5M label would be black)
Code:
def midSqueeze = BolKelDelta_Mid <= 0;
def triggerMid = if sum(midSqueeze,triggerBars) == triggerBars and !midSqueeze[triggerBars] then 1 else 0;
plot signalMidLong = if triggerMid and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and oscillator > 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and oscillator > oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator > oscillator[1] and oscillator < 0 )) then low-signalOffset else double.nan;
signalMidLong.SetPaintingStrategy(paintingStrategy.ARROW_UP);
signalMidLong.setDefaultColor(color.red);
signalMidLong.setLineWeight(5);
plot signalMidShort = if triggerMid and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and oscillator <= 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and oscillator < oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator < oscillator[1] and oscillator > 0 )) then high+signalOffset else double.nan;
signalMidShort.SetPaintingStrategy(paintingStrategy.ARROW_Down);
signalMidShort.setDefaultColor(color.red);
signalMidShort.setLineWeight(5);
def highSqueeze = BolKelDelta_High <= 0;
def triggerHigh = if sum(highSqueeze,triggerBars) == triggerBars and !highSqueeze[triggerBars] then 1 else 0;
plot signalHighLong = if triggerHigh and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and oscillator > 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and oscillator > oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator > oscillator[1] and oscillator < 0 )) then low-signalOffset else double.nan;
signalHighLong.SetPaintingStrategy(paintingStrategy.ARROW_UP);
signalHighLong.setDefaultColor(color.dark_orange);
signalHighLong.setLineWeight(5);
plot signalHighShort = if triggerHigh and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and oscillator <= 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and oscillator < oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator < oscillator[1] and oscillator > 0 )) then high+signalOffset else double.nan;
signalHighShort.SetPaintingStrategy(paintingStrategy.ARROW_Down);
signalHighShort.setDefaultColor(color.dark_orange);
signalHighShort.setLineWeight(5);
It looks like I cutoff some of the code. paste this at the bottom of my last post.
It's a lower study. The colors represent the dots on the squeeze.
My hope is to make a label - just like yours - that tells me what color dot the squeeze is at for a given timeframe.
(i.e. - if the 5 minute squeeze is a black dot, the 5M label would be black)
Code:
def midSqueeze = BolKelDelta_Mid <= 0;
def triggerMid = if sum(midSqueeze,triggerBars) == triggerBars and !midSqueeze[triggerBars] then 1 else 0;
plot signalMidLong = if triggerMid and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and oscillator > 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and oscillator > oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator > oscillator[1] and oscillator < 0 )) then low-signalOffset else double.nan;
signalMidLong.SetPaintingStrategy(paintingStrategy.ARROW_UP);
signalMidLong.setDefaultColor(color.red);
signalMidLong.setLineWeight(5);
plot signalMidShort = if triggerMid and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and oscillator <= 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and oscillator < oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator < oscillator[1] and oscillator > 0 )) then high+signalOffset else double.nan;
signalMidShort.SetPaintingStrategy(paintingStrategy.ARROW_Down);
signalMidShort.setDefaultColor(color.red);
signalMidShort.setLineWeight(5);
def highSqueeze = BolKelDelta_High <= 0;
def triggerHigh = if sum(highSqueeze,triggerBars) == triggerBars and !highSqueeze[triggerBars] then 1 else 0;
plot signalHighLong = if triggerHigh and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and oscillator > 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and oscillator > oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator > oscillator[1] and oscillator < 0 )) then low-signalOffset else double.nan;
signalHighLong.SetPaintingStrategy(paintingStrategy.ARROW_UP);
signalHighLong.setDefaultColor(color.dark_orange);
signalHighLong.setLineWeight(5);
plot signalHighShort = if triggerHigh and ((LongShortDefinition == LongShortDefinition.HistAboveBelowZero and oscillator <= 0) or (LongShortDefinition == LongShortDefinition.HistRisingFalling and oscillator < oscillator[1]) or (LongShortDefinition == LongShortDefinition.HistRisingFromBelowFallingFromAbove and oscillator < oscillator[1] and oscillator > 0 )) then high+signalOffset else double.nan;
signalHighShort.SetPaintingStrategy(paintingStrategy.ARROW_Down);
signalHighShort.setDefaultColor(color.dark_orange);
signalHighShort.setLineWeight(5);
Can the dots in the multi-time frame be indicated if the TTM fired to the upside or to the down side. I would like to see the red to the down side and green to the upside and orange when it in the squeeze. Otherwise you have to check each time frame which direction it fired to. Thank you
All multi-timeframe (MTF) indicators present a type of repainting behavior.
Think about it. You have a 30-min overlay on a five-min chart. There is no way of predicting at what price that 30min candle is going to close until it closes. So for 30 minutes, it will continually repaint the 6 bars with the most recent 30min bar tick price.
Then, when the 30min candle finally closes, it will do a final repaint of the previous 6 bars with the 30min close price.
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.
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.