GetRichOrDieTrying
Member
Anyone know if there's a way to create a multi-timeframe Moving Average Crossover indicator like this lower chart?
Looking for something like the bottom pane ?
Anyone know if there's a way to create a multi-timeframe Moving Average Crossover indicator like this lower chart?
Looking for something like the bottom pane ?
Yes. I did multiple searches. I don't see it anywhere. The closest thing to it is the TTM Squeeze, but that's not what I need.
input price = CLOSE;
input length = 20;
input nK = 1.5;
input nBB = 2.0;
input alertLine = 1.0;
def squeezeHistogram = TTM_Squeeze(price, length, nK, nBB, alertLine).Histogram;
AddLabel(yes, ”5M”, if squeezeHistogram >= 0 then
if squeezeHistogram > squeezeHistogram[1] then Color.CYAN else Color.BLUE
else if squeezeHistogram < squeezeHistogram[1] then Color.RED else Color.YELLOW);
Thanks @rad14733 this was a great help!@will1285 The AddLabel() call was the missing piece of the puzzle, plus you had the AssignBackgroundColor() call in place by mistake, which I commented out... You can simple remove those lines of code...
Here is the corrected code... Modify further as you see fit...
Edited to add: I went ahead and removed all of the unnecessary code... Also, I didn't verify your logic I only made the code work as coded...
Ruby:input price = CLOSE; input length = 20; input nK = 1.5; input nBB = 2.0; input alertLine = 1.0; def squeezeHistogram = TTM_Squeeze(price, length, nK, nBB, alertLine).Histogram; AddLabel(yes, ”5M”, if squeezeHistogram >= 0 then if squeezeHistogram > squeezeHistogram[1] then Color.CYAN else Color.BLUE else if squeezeHistogram < squeezeHistogram[1] then Color.RED else Color.YELLOW);
input dStr = AggregationPeriod.DAY;
input period = AggregationPeriod.DAY;
input price = CLOSE;
input length = 20;
input nK = 1.5;
input nBB = 2.0;
input alertLine = 1.0;
def squeezeHistogram = TTM_Squeeze(price, length, nK, nBB, alertLine).Histogram;
AddLabel(yes, if dStr == AggregationPeriod.MONTH then "M"
else
if dStr == AggregationPeriod.WEEK then "W"
else
if dStr == AggregationPeriod.FOUR_DAYS then "4D"
else
if dStr == AggregationPeriod.THREE_DAYS then "3D"
else
if dStr == AggregationPeriod.TWO_DAYS then "2D"
else
if dStr == AggregationPeriod.DAY then "D"
else
if dStr == AggregationPeriod.FOUR_HOURS then "4H"
else
if dStr == AggregationPeriod.TWO_HOURS then "2H"
else
if dStr == AggregationPeriod.HOUR then "60m"
else
if dStr == AggregationPeriod.THIRTY_MIN then "30m"
else
if dStr == AggregationPeriod.TWENTY_MIN then "20m"
else
if dStr == AggregationPeriod.FIFTEEN_MIN then "15m"
else
if dStr == AggregationPeriod.TEN_MIN then "10m"
else
if dStr == AggregationPeriod.FIVE_MIN then "5m"
else
if dStr == AggregationPeriod.FOUR_MIN then "4m"
else
if dStr == AggregationPeriod.THREE_MIN then "3m"
else
if dStr == AggregationPeriod.TWO_MIN then "2m"
else
if dStr == AggregationPeriod.MIN then "1m"
else
if squeezeHistogram >= 0 then
if squeezeHistogram > squeezeHistogram[1] then Color.CYAN else Color.BLUE
else if squeezeHistogram < squeezeHistogram[1] then Color.RED else Color.YELLOW);
Hello Everyone,Well I wanted to modify the squeeze code I had to include vertical lines that fire but I can't figure why it's not firing correctly. I had bolded the area that adds the vertical line but it's not firing. In the codes you've shared, the vertical Fire lines display, I was trying to replicate it for the code I pasted.
@Pelonsax - is there any way to make this dynamic to change in overall timeframe (e.g. vs manual input of changing time frame by modifying study).
All I was able to figure it out.. we can ignore this. If anyone was interested, happy to share.
Oof brother. Long time since I worked on this script. Can you help me out here? What specifically are we referring to?Hello Everyone,
new member here and finding some great content. Thankful for everyone being helpful in sharing and adding to the forum.
@ampersand / @Pelonsax - was there a solution to making this "Dynamic" change vs manually having to input the timeframes via the input selector on the study?
Oof brother. Long time since I worked on this script. Can you help me out here? What specifically are we referring
Code:
Code:declare lower; input AP1 = AggregationPeriod.DAY; input AP2 = AggregationPeriod.TWO_DAYS; input AP3 = AggregationPeriod.THREE_DAYS; input AP4 = AggregationPeriod.FOUR_DAYS; input AP5 = AggregationPeriod.WEEK; input AP6 = AggregationPeriod.MONTH; input vote = 3; def price1 = CLOSE(period = AP1); def price2 = CLOSE(period = AP2); def price3 = CLOSE(period = AP3); def price4 = CLOSE(period = AP4); def price5 = CLOSE(period = AP5); def price6 = CLOSE(period = AP6); def length = 20; def nK = 1.5; def nBB = 2.0; def alertLine = 1.0; def Sqz_Length = 3; def squeezeDots1 = TTM_Squeeze(price1, length, nK, nBB, alertLine).SqueezeAlert; def squeezeDots2 = TTM_Squeeze(price2, length, nK, nBB, alertLine).SqueezeAlert; def squeezeDots3 = TTM_Squeeze(price3, length, nK, nBB, alertLine).SqueezeAlert; def squeezeDots4 = TTM_Squeeze(price4, length, nK, nBB, alertLine).SqueezeAlert; def squeezeDots5 = TTM_Squeeze(price5, length, nK, nBB, alertLine).SqueezeAlert; def squeezeDots6 = TTM_Squeeze(price6, length, nK, nBB, alertLine).SqueezeAlert; def Top_Plot = (squeezeDots1 + squeezeDots2 + squeezeDots3 + squeezeDots4 + squeezeDots5 +squeezeDots6) >= Vote; plot MTF_Sqz = 7; MTF_Sqz.SetPaintingStrategy(PaintingStrategy.POINTS); MTF_Sqz.AssignValueColor(if Top_Plot == 1 then Color.BLACK else Color.DARK_RED); MTF_Sqz.SetLineWeight(5); plot Sqeezy1 = if squeezeDots1 == 1 then squeezeDots1 + 5 else 6; plot Sqeezy2 = if squeezeDots2 == 1 then squeezeDots2 + 4 else 5; plot Sqeezy3 = if squeezeDots3 == 1 then squeezeDots3 + 3 else 4; plot Sqeezy4 = if squeezeDots4 == 1 then squeezeDots4 + 2 else 3; plot Sqeezy5 = if squeezeDots5 == 1 then squeezeDots5 + 1 else 2; plot Sqeezy6 = if squeezeDots6 == 1 then squeezeDots6 else 1; Sqeezy1.SetPaintingStrategy(PaintingStrategy.POINTS); Sqeezy1.AssignValueColor(if squeezeDots1 == 1 then Color.DARK_GREEN else Color.DARK_RED); Sqeezy1.SetLineWeight(3); Sqeezy2.SetPaintingStrategy(PaintingStrategy.POINTS); Sqeezy2.AssignValueColor(if squeezeDots2 == 1 then Color.DARK_GREEN else Color.DARK_RED); Sqeezy2.SetLineWeight(3); Sqeezy3.SetPaintingStrategy(PaintingStrategy.POINTS); Sqeezy3.AssignValueColor(if squeezeDots3 == 1 then Color.DARK_GREEN else Color.DARK_RED); Sqeezy3.SetLineWeight(3); Sqeezy4.SetPaintingStrategy(PaintingStrategy.POINTS); Sqeezy4.AssignValueColor(if squeezeDots5 == 1 then Color.DARK_GREEN else Color.DARK_RED); Sqeezy4.SetLineWeight(3); Sqeezy5.SetPaintingStrategy(PaintingStrategy.POINTS); Sqeezy5.AssignValueColor(if squeezeDots5 == 1 then Color.DARK_GREEN else Color.DARK_RED); Sqeezy5.SetLineWeight(3); Sqeezy6.SetPaintingStrategy(PaintingStrategy.POINTS); Sqeezy6.AssignValueColor(if squeezeDots6 == 1 then Color.DARK_GREEN else Color.DARK_RED); Sqeezy6.SetLineWeight(3);
Not sure about the blank spots but this is my version of the squeeze with MORE DOTS!
There are 6 aggregations, you can pick the "vote" for the topline to show is "x" of 6 are in line with each other.
Code:declare lower; input AP1 = AggregationPeriod.DAY; input AP2 = AggregationPeriod.TWO_DAYS; input AP3 = AggregationPeriod.THREE_DAYS; input AP4 = AggregationPeriod.FOUR_DAYS; input AP5 = AggregationPeriod.WEEK; input AP6 = AggregationPeriod.MONTH; input vote = 3; def price1 = CLOSE(period = AP1); def price2 = CLOSE(period = AP2); def price3 = CLOSE(period = AP3); def price4 = CLOSE(period = AP4); def price5 = CLOSE(period = AP5); def price6 = CLOSE(period = AP6); def length = 20; def nK = 1.5; def nBB = 2.0; def alertLine = 1.0; def Sqz_Length = 3; def squeezeDots1 = TTM_Squeeze(price1, length, nK, nBB, alertLine).SqueezeAlert; def squeezeDots2 = TTM_Squeeze(price2, length, nK, nBB, alertLine).SqueezeAlert; def squeezeDots3 = TTM_Squeeze(price3, length, nK, nBB, alertLine).SqueezeAlert; def squeezeDots4 = TTM_Squeeze(price4, length, nK, nBB, alertLine).SqueezeAlert; def squeezeDots5 = TTM_Squeeze(price5, length, nK, nBB, alertLine).SqueezeAlert; def squeezeDots6 = TTM_Squeeze(price6, length, nK, nBB, alertLine).SqueezeAlert; def Top_Plot = (squeezeDots1 + squeezeDots2 + squeezeDots3 + squeezeDots4 + squeezeDots5 +squeezeDots6) >= Vote; plot MTF_Sqz = 7; MTF_Sqz.SetPaintingStrategy(PaintingStrategy.POINTS); MTF_Sqz.AssignValueColor(if Top_Plot == 1 then Color.BLACK else Color.DARK_RED); MTF_Sqz.SetLineWeight(5); plot Sqeezy1 = if squeezeDots1 == 1 then squeezeDots1 + 5 else 6; plot Sqeezy2 = if squeezeDots2 == 1 then squeezeDots2 + 4 else 5; plot Sqeezy3 = if squeezeDots3 == 1 then squeezeDots3 + 3 else 4; plot Sqeezy4 = if squeezeDots4 == 1 then squeezeDots4 + 2 else 3; plot Sqeezy5 = if squeezeDots5 == 1 then squeezeDots5 + 1 else 2; plot Sqeezy6 = if squeezeDots6 == 1 then squeezeDots6 else 1; Sqeezy1.SetPaintingStrategy(PaintingStrategy.POINTS); Sqeezy1.AssignValueColor(if squeezeDots1 == 1 then Color.DARK_GREEN else Color.DARK_RED); Sqeezy1.SetLineWeight(3); Sqeezy2.SetPaintingStrategy(PaintingStrategy.POINTS); Sqeezy2.AssignValueColor(if squeezeDots2 == 1 then Color.DARK_GREEN else Color.DARK_RED); Sqeezy2.SetLineWeight(3); Sqeezy3.SetPaintingStrategy(PaintingStrategy.POINTS); Sqeezy3.AssignValueColor(if squeezeDots3 == 1 then Color.DARK_GREEN else Color.DARK_RED); Sqeezy3.SetLineWeight(3); Sqeezy4.SetPaintingStrategy(PaintingStrategy.POINTS); Sqeezy4.AssignValueColor(if squeezeDots5 == 1 then Color.DARK_GREEN else Color.DARK_RED); Sqeezy4.SetLineWeight(3); Sqeezy5.SetPaintingStrategy(PaintingStrategy.POINTS); Sqeezy5.AssignValueColor(if squeezeDots5 == 1 then Color.DARK_GREEN else Color.DARK_RED); Sqeezy5.SetLineWeight(3); Sqeezy6.SetPaintingStrategy(PaintingStrategy.POINTS); Sqeezy6.AssignValueColor(if squeezeDots6 == 1 then Color.DARK_GREEN else Color.DARK_RED); Sqeezy6.SetLineWeight(3);
# 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
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, 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.DefineColor("ExtrSqueeze", Color.RED);
squeezeline.DefineColor("OriginalSqueeze", Color.RED);
squeezeline.DefineColor("PreSqueeze", Color.GREEN);
squeezeline.DefineColor("NoSqueeze", Color.GREEN);
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.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
Thank you so much for taking the time to do this.
I'm curious. Do you know why the histograms you created look different than the standard TTM Squeeze on the actual timeframe chart?
As an example, I added a 5 minute and 15 minute squeeze to my 1 minute chart from the script you created. Those histograms look different than the standard ttm squeeze histogram on the 5 and 15 charts on the side of my grid.
See screenshot below.
https://i.ibb.co/h7tjJtm/MTF-TTM.png
The screenshots you shared show the standard TTM Squeeze and your multi time frame Squeeze for the same timeframe as the chart. I acknowledge that works correctly.@GetRichOrDieTrying As you can see by the images below, the new indicator paints the same as the original with the exception that in the top image I had the dots set to Pro styling... Another difference is that I used Red instead of Dark_Red... I think what you may be seeing is image time compression... Look at the timelines at the bottoms of the three charts...
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
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.
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.