TTM Squeeze histogram bar count in label


Category:
0
0

I am wondering if a label can be created that counts the number of bars in the lower study, TTM Squeeze, based on  the histogram colors.  Say that the last 2 bars are Cyan color (positive and up per the histogram), the label would read 2 with the background color being Cyan. Next label would show the average number of Cyan bars in a row after the crossover occurred. The length of the periods could be say last 30 bars, or 60, really whatever the number we specify.

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on January 18, 2023 2:27 pm
394 views
0
Private answer

Since you are asking for a chart label I moved your question out of the "Alerts and Notifications" topic and into the "Chart Studies" topic. I also updated the title of your question to help other viewers locate this post using the search function.

I only allocate 15 minutes to each free solution I provide in this forum. Within that time I was just barely able to complete the section that counts bars and displays that in a chart label. The rest of your request is well beyond the complexity of solutions I can provide free of charge in this forum.

Here is the solution which adds a label to the chart which shows the color of the current bar and the number of consecutive bar in the current color:

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;
def sqzCyan = squeezeHistogram >= 0 and squeezeHistogram > squeezeHistogram[1];
def sqzBlue = squeezeHistogram >=0 and squeezeHistogram < squeezeHistogram[1];
def sqzRed = squeezeHistogram <= 0 and squeezeHistogram < squeezeHistogram[1];
def sqzYellow = squeezeHistogram <= 0 and squeezeHistogram > squeezeHistogram[1];
rec countCyan = if !sqzCyan then 0 else if sqzCyan and !sqzCyan[1] then 1 else if sqzCyan then countCyan[1] + 1 else countCyan[1];
rec countBlue = if !sqzBlue then 0 else if sqzBlue and !sqzBlue[1] then 1 else if sqzBlue then countBlue[1] + 1 else countBlue[1];
rec countRed = if !sqzRed then 0 else if sqzRed and !sqzRed[1] then 1 else if sqzRed then countRed[1] + 1 else countRed[1];
rec countYellow = if !sqzYellow then 0 else if sqzYellow and !sqzYellow[1] then 1 else if sqzYellow then countYellow[1] + 1 else countYellow[1];
def consecutiveBars = Max(countCyan, Max(countBlue, Max(countRed, countYellow)));
AddLabel(yes, Concat("Count: ", consecutiveBars), if sqzCyan then Color.CYAN else if sqzBlue then Color.BLUE else if sqzRed then Color.RED else if sqzYellow then Color.YELLOW else Color.CURRENT);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on January 18, 2023 3:33 pm
0
Amazing work. Please email me cost to develop rest of the code if possible.
( at January 18, 2023 3:48 pm)
0
If you are interested in paying for a professional quality solution you will find all of those details explained on the following webpage: https://www.hahn-tech.com/about/
( at January 18, 2023 3:51 pm)