Developing a Squeeze Histogram Formula

Status
Not open for further replies.

trouble56

New member

I am looking for help developing the formula for the Squeeze Histogram value so I can create a multi-timeframe indicator for Squeeze. This is what I was using for my formula but this formula only works if the time frame on my chart matches the timeframe I am assessing.

input higher_time_frame_1 = AggregationPeriod.two_days;

def squeezeHist1 = reference TTM_Squeeze(close(period = higher_time_frame_1), 20, 1.5, 2.0, 1.0).Histogram;

If it is a different timeframe then the formula is not correct. I believe it means that I need to actually calculate Squeeze without referencing the building indicator but I don't know how to do this. Any help would be greatly appreciated.

Thank you,

Aaron
 
Last edited by a moderator:
Hello,

Below is the code for SQueezePRO and can anyone help me with the updating it to MTF .. Thanks in advance

declare lower;

def nBB = 2.0;
def Length = 20.0;
def nK_High = 1.0;
def nK_Mid = 1.5;
def nK_Low = 2.0;
def price = close;

def momentum = TTM_Squeeze(price = price, length = length, nk = nk_Mid, nbb = nbb)."Histogram";
plot oscillator = momentum;
def BolKelDelta_Mid = reference BollingerBands("num_dev_up" = nBB, "length" = Length )."upperband" - KeltnerChannels("factor" = nK_Mid, "length" = Length)."Upper_Band";
def BolKelDelta_Low = reference BollingerBands("num_dev_up" = nBB, "length" = Length )."upperband" - KeltnerChannels("factor" = nK_Low, "length" = Length)."Upper_Band";
def BolKelDelta_High = reference BollingerBands("num_dev_up" = nBB, "length" = Length )."upperband" - KeltnerChannels("factor" = nK_High, "length" = Length)."Upper_Band";
oscillator.DefineColor("Up", CreateColor(0, 255, 255));
oscillator.DefineColor("UpDecreasing", CreateColor(0, 0, 255));
oscillator.DefineColor("Down", CreateColor(255, 0, 0));
oscillator.DefineColor("DownDecreasing", CreateColor(255, 255, 0));
oscillator.AssignValueColor(
if oscillator[1] < oscillator then if oscillator[0] >= 0
then oscillator.Color("Up")
else oscillator.Color("DownDecreasing")
else if oscillator >= 0
then oscillator.Color("UpDecreasing")
else oscillator.Color("Down") );
oscillator.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
oscillator.SetLineWeight(5);

plot squeeze = If(IsNaN(close), Double.NaN, 0);
squeeze.DefineColor("NoSqueeze", Color.GREEN);
squeeze.DefineColor("SqueezeLow", Color.black);
squeeze.DefineColor("SqueezeMid", Color.RED);
squeeze.DefineColor("SqueezeHigh", Color.orange);
squeeze.AssignValueColor(if BolKelDelta_High <= 0 then squeeze.Color("SqueezeHigh") else if BolKelDelta_Mid <= 0 then squeeze.Color("SqueezeMid") else if BolKelDelta_Low <= 0 then squeeze.Color("SqueezeLow") else squeeze.color("noSqueeze"));
squeeze.SetPaintingStrategy(PaintingStrategy.POINTS);
squeeze.SetLineWeight(3);
 
If no one happens to take on this project. Here are some of the already existing MTF squeezes:
https://usethinkscript.com/threads/developing-a-squeeze-histogram-formula.3408/#post-31512
Wow, what a coincidence. I've been working on this on my own and came on here to post some code for help and found that you are looking to have the same thing! MTF Squeeze Pro in Labels. So i need some help. here's a snippet of the MTF Squeeze Pro Labels code. For some reason, the labels only populate on time-frames GREATER THAN the time-frame of the labels. For instance, all squeeze pro labels populate on the monthly timeframe but NONE of them populate on the 1minute time frame. In addition, if I'm using a 5min chart, the 5min squeeze pro label doesn't populate. Can somebody help me out here? I've compared the code to a few other MTF label codes and have tried a few different things but nothing seems to work. You can see in the code provided that I've coded the labels in 2 different ways. I've tried 3 or 4 but have only attached 2. Thank you!
Code:
### MTF Squeeze Pro LABELS
##Global Variables
def length = 20;
def AlertLine = 1;
def nk1 = 1;
def nk2 = 1.5;
def nk3 = 2;
def nBB = 2;
def averageType = AverageType.SIMPLE;
def displace = 0;
def trueRangeAverageType = AverageType.SIMPLE;

########################################

## FIVE_MIN Aggregation Period Variables

########################################

def FIVE_MINPrice;
def FIVE_MINATR;
def FIVE_MINSDev;
def FIVE_MINDenom1;
def FIVE_MINDenom2;
def FIVE_MINDenom3;
def FIVE_MINBBSInd1;
def FIVE_MINBBSInd2;
def FIVE_MINBBSInd3;
def FIVE_MINPreSqueeze;
def FIVE_MINSqueeze;
def FIVE_MINExtraSqueeze;
def FIVE_MINAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.FIVE_MIN {

    FIVE_MINPrice = close(period = "FIVE_MIN");
    FIVE_MINATR = Average(TrueRange(high (period = "FIVE_MIN"), close(period = "FIVE_MIN"), low(period = "FIVE_MIN")), length);
    FIVE_MINSDev = StDev(FIVE_MINPrice, length);
    FIVE_MINDenom1 = (nk1 * FIVE_MINATR);
    FIVE_MINDenom2 = (nk2 * FIVE_MINATR);
    FIVE_MINDenom3 = (nk3 * FIVE_MINATR);
    FIVE_MINBBSInd1 = If (FIVE_MINDenom1 <> 0, ((nBB * FIVE_MINSDev) / FIVE_MINDenom1), 0);
    FIVE_MINBBSInd2 = If (FIVE_MINDenom2 <> 0, ((nBB * FIVE_MINSDev) / FIVE_MINDenom2), 0);
    FIVE_MINBBSInd3 = If (FIVE_MINDenom3 <> 0, ((nBB * FIVE_MINSDev) / FIVE_MINDenom3), 0);
    FIVE_MINPreSqueeze = if FIVE_MINBBSInd1 < AlertLine then 1 else 0;
    FIVE_MINSqueeze = if FIVE_MINBBSInd2 < AlertLine then 1 else 0;
    FIVE_MINExtraSqueeze = if FIVE_MINBBSInd3 < AlertLine then 1 else 0;
    FIVE_MINAggregationPeriod = 1;
}
else {
    FIVE_MINPrice = 0;
    FIVE_MINATR = 0;
    FIVE_MINSDev = 0;
    FIVE_MINDenom1 = 0;
    FIVE_MINDenom2 = 0;
    FIVE_MINDenom3 = 0;
    FIVE_MINBBSInd1 = 0;
    FIVE_MINBBSInd2 = 0;
    FIVE_MINBBSInd3 = 0;
    FIVE_MINPreSqueeze = 0;
    FIVE_MINSqueeze = 0;
    FIVE_MINExtraSqueeze = 0;
    FIVE_MINAggregationPeriod = 0;
}

AddLabel(yes, "5m", if FIVE_MINPreSqueeze then Color.BLACK else if  FIVE_MINSqueeze then Color.RED else if FIVE_MINExtraSqueeze then Color.YELLOW else Color.DARK_GREEN);

########################################

## FOUR_MIN Aggregation Period Variables

########################################

def FOUR_MINPrice;
def FOUR_MINATR;
def FOUR_MINSDev;
def FOUR_MINDenom1;
def FOUR_MINDenom2;
def FOUR_MINDenom3;
def FOUR_MINBBSInd1;
def FOUR_MINBBSInd2;
def FOUR_MINBBSInd3;
def FOUR_MINPreSqueeze;
def FOUR_MINSqueeze;
def FOUR_MINExtraSqueeze;
def FOUR_MINAggregationPeriod;

if GetAggregationPeriod() <= AggregationPeriod.FOUR_MIN {
    FOUR_MINPrice = close(period = "FOUR_MIN");
    FOUR_MINATR = Average(TrueRange(high (period = "FOUR_MIN"), close(period = "FOUR_MIN"), low(period = "FOUR_MIN")), length);
    FOUR_MINSDev = StDev(FOUR_MINPrice, length);
    FOUR_MINDenom1 = (nk1 * FOUR_MINATR);
    FOUR_MINDenom2 = (nk2 * FOUR_MINATR);
    FOUR_MINDenom3 = (nk3 * FOUR_MINATR);
    FOUR_MINBBSInd1 = If (FOUR_MINDenom1 <> 0, ((nBB * FOUR_MINSDev) / FOUR_MINDenom1), 0);
    FOUR_MINBBSInd2 = If (FOUR_MINDenom2 <> 0, ((nBB * FOUR_MINSDev) / FOUR_MINDenom2), 0);
    FOUR_MINBBSInd3 = If (FOUR_MINDenom3 <> 0, ((nBB * FOUR_MINSDev) / FOUR_MINDenom3), 0);
    FOUR_MINPreSqueeze = if FOUR_MINBBSInd1 < AlertLine then 1 else 0;
    FOUR_MINSqueeze = if FOUR_MINBBSInd2 < AlertLine then 1 else 0;
    FOUR_MINExtraSqueeze = if FOUR_MINBBSInd3 < AlertLine then 1 else 0;
    FOUR_MINAggregationPeriod = 1;
}
else {
    FOUR_MINPrice = 0;
    FOUR_MINATR = 0;
    FOUR_MINSDev = 0;
    FOUR_MINDenom1 = 0;
    FOUR_MINDenom2 = 0;
    FOUR_MINDenom3 = 0;
    FOUR_MINBBSInd1 = 0;
    FOUR_MINBBSInd2 = 0;
    FOUR_MINBBSInd3 = 0;
    FOUR_MINPreSqueeze = 0;
    FOUR_MINSqueeze = 0;
    FOUR_MINExtraSqueeze = 0;
    FOUR_MINAggregationPeriod = 0;
}

AddLabel(FOUR_MINPreSqueeze and Four_MinAggregationPeriod, "4m", color.black); AddLabel(FOUR_MINSqueeze and FOUR_MINAggregationPeriod, "4m", color.red); AddLabel(FOUR_MINExtraSqueeze and FOUR_MINAggregationPeriod, "4m", color.yellow);
AddLabel(Yes, "4m", color.dark_green);
 
Status
Not open for further replies.

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
490 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