Add moving average to TTM Squeeze


Category:
0
0

Hi Pete,

Can you help me on the average Histogram on TTM Squeeze for the past 20 candle bars.

I have attached a screenshot, i believe that Histogram number? Example this number current is -15.30, how can i get the average of past 20 bars?

 

Thanks

 

Attachments:
Marked as spam
Posted by (Questions: 3, Answers: 5)
Asked on January 25, 2021 2:38 pm
308 views
0
Private answer

In order to do this properly I will have to recreate the entire chart study by referencing the plots from the original. In this way I can replicate the appearance of the original without having to access the source code (which is not available on Thinkorswim). I will also include user inputs to adjust the length of the moving average as well as the type.

Having done all of that in lines 1 through 19, I then add the moving average plot as the final line in the code.

The only detail missing from this is the alert that is included with the original. (I simply ran out of time and was not able to included that feature with this solution).

Here is the code that displays the TTM_Squeeze and adds the moving average plot:

declare lower;
input price = CLOSE;
input length = 20;
input nK = 1.5;
input nBB = 2.0;
input alertLine = 1.0;
input maLengthOne = 20;
input maTypeOne = AverageType.EXPONENTIAL;
plot sqzHistogram = TTM_Squeeze(price, length, nK, nBB, alertLine).Histogram;
sqzHistogram.AssignValueColor(if sqzHistogram < 0 then if sqzHistogram > sqzHistogram[1] then Color.YELLOW else Color.RED else
if sqzHistogram > sqzHistogram[1] then Color.CYAN else Color.BLUE);
sqzHistogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
sqzHistogram.SetLineWeight(3);
def sqzAlert = TTM_Squeeze(price, length, nK, nBB, alertLine).SqueezeAlert;
plot volComp = TTM_Squeeze(price, length, nK, nBB, alertLine).VolComp;
volComp.AssignValueColor(if sqzAlert then Color.GREEN else Color.RED);
volComp.SetPaintingStrategy(PaintingStrategy.POINTS);
volComp.SetLineWeight(3);
plot histogramAverage = MovingAverage(maTypeOne, sqzHistogram, maLengthOne);

The screenshot below shows the end result. (I have included the built-in version of TTM_Squeeze along with the custom version displayed in the bottom of the chart. This allows viewers to confirm everything matches the original).

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on January 25, 2021 3:43 pm
0
Thank so much Pete.
( at January 25, 2021 6:51 pm)