• Get $40 off VIP by signing up for a free account! Sign Up

TTM Squeeze Histogram Color Based on Plot

PAYtience

New member
VIP
If someone can please help me change the color based on the plots that I have created below -

plot Max_Momentum_Down = -1.0;
plot Max_Momentum_Up = 1.0;

Below -1.0 histogram color changes to dark red.
Above +1.0 histogram color changes to dark green.View attachment 22016

Thank You!!

Code:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © Beardy_Fred
#indicator('Beardy Squeeze Pro', shorttitle='Squeeze', overlay=false, precision=2)
# Converted by Sam4Cok@Samer800        - 05/2023
declare lower;
input ShowLabel = yes;        # "Alert Price Action Squeeze"
input MovAvgType   = AverageType.SIMPLE;
input length       = 20;      # "TTM Squeeze Length"
input BB_mult      = 2.0;     # "Bollinger Band STD Multiplier"
input KC_mult_high = 1.0;     # "Keltner Channel #1"
input KC_mult_mid  = 1.5;     # "Keltner Channel #2"
input KC_mult_low  = 2.0;     # "Keltner Channel #3"

def na = Double.NaN;
def last = IsNaN(close);

#--- Color
DefineGlobalColor("up1", CreateColor(0, 188, 212));
DefineGlobalColor("dn2", CreateColor(41, 98, 255));
DefineGlobalColor("dn1", CreateColor(255, 50, 82));
DefineGlobalColor("up2", CreateColor(255, 75, 59));
#------
DefineGlobalColor("sqz1", CreateColor(255, 152, 0));
DefineGlobalColor("sqz2", CreateColor(255, 82, 82));
DefineGlobalColor("sqz3", Color.GRAY);#CreateColor(54,58,69));
DefineGlobalColor("sqz4", Color.GREEN);
#//BOLLINGER BANDS
def BB_basis = MovingAverage(MovAvgType, close, length);
def dev      = BB_mult * StDev(close, length);
def BB_upper = BB_basis + dev;
def BB_lower = BB_basis - dev;

#//KELTNER CHANNELS
def tr = TrueRange(high, close, low);
def KC_basis = MovingAverage(MovAvgType, close, length);
def devKC    = MovingAverage(MovAvgType, tr, length);
def KC_upper_high = KC_basis + devKC * KC_mult_high;
def KC_lower_high = KC_basis - devKC * KC_mult_high;
def KC_upper_mid  = KC_basis + devKC * KC_mult_mid;
def KC_lower_mid  = KC_basis - devKC * KC_mult_mid;
def KC_upper_low  = KC_basis + devKC * KC_mult_low;
def KC_lower_low  = KC_basis - devKC * KC_mult_low;

#//SQUEEZE CONDITIONS
def NoSqz   = BB_lower < KC_lower_low or BB_upper > KC_upper_low;# //NO SQUEEZE: GREEN
def LowSqz  = BB_lower >= KC_lower_low or BB_upper <= KC_upper_low;# //LOW COMPRESSION: BLACK
def MidSqz  = BB_lower >= KC_lower_mid or BB_upper <= KC_upper_mid;# //MID COMPRESSION: RED
def HighSqz = BB_lower >= KC_lower_high or BB_upper <= KC_upper_high;# //HIGH COMPRESSION: ORANGE

#//MOMENTUM OSCILLATOR
def hh = Highest(high, length);
def ll = Lowest(low, length);
def avg = (hh + ll) / 2;
def avgSMA = (avg + KC_basis) / 2;
def mom = Inertia(close - avgSMA, length);

#//MOMENTUM HISTOGRAM COLOR
def iff_1 = if mom > mom[1] then  2 else  1;
def iff_2 = if mom < mom[1] then -2 else -1;
def mom_color = if mom > 0 then iff_1 else iff_2;

#//SQUEEZE DOTS COLOR
def sq_color = if HighSqz then 3 else
               if MidSqz then 2 else
               if LowSqz then 1 else 0;
#//ALERTS

AddLabel(ShowLabel, if sq_color == 0 then "NO SQUEEZE" else
                    if sq_color == 1 then "LOW COMPRESSION" else
                    if sq_color == 2 then "MID COMPRESSION" else "HIGH COMPRESSION",
                    if sq_color == 3 then GlobalColor("sqz1") else
                    if sq_color == 2 then GlobalColor("sqz2") else
                    if sq_color == 1 then GlobalColor("sqz3") else GlobalColor("sqz4"));

#//PLOTS

plot SQZ = if last then na else 0;          # 'SQZ'
plot momentum = mom;                        # 'MOM'
momentum.SetLineWeight(4);
momentum.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
momentum.AssignValueColor(if mom_color == 2 then GlobalColor("up1") else
                          if mom_color == 1 then GlobalColor("up2") else
                          if mom_color == -2 then GlobalColor("dn1") else
                          if mom_color == -1 then GlobalColor("dn2") else Color.GRAY);
SQZ.SetLineWeight(2);
SQZ.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
SQZ.AssignValueColor(if sq_color == 3 then GlobalColor("sqz1") else
                     if sq_color == 2 then GlobalColor("sqz2") else
                     if sq_color == 1 then GlobalColor("sqz3") else GlobalColor("sqz4"));

plot Max_Momentum_Down = -1.0;
plot Max_Momentum_Up = 1.0;

Max_Momentum_Down.SetDefaultColor(GetColor(5));
Max_Momentum_Down.SetDefaultColor(GetColor(6));



#--- END OF CODE
 
Solution
If someone can please help me change the color based on the plots that I have created below -

plot Max_Momentum_Down = -1.0;
plot Max_Momentum_Up = 1.0;

Below -1.0 histogram color changes to dark red.
Above +1.0 histogram color changes to dark green.View attachment 22016

Thank You!!

Code:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © Beardy_Fred
#indicator('Beardy Squeeze Pro', shorttitle='Squeeze', overlay=false, precision=2)
# Converted by Sam4Cok@Samer800        - 05/2023
declare lower;
input ShowLabel = yes;        # "Alert Price Action Squeeze"
input MovAvgType   = AverageType.SIMPLE;
input length       = 20;      # "TTM Squeeze Length"
input BB_mult      = 2.0...
If someone can please help me change the color based on the plots that I have created below -

plot Max_Momentum_Down = -1.0;
plot Max_Momentum_Up = 1.0;

Below -1.0 histogram color changes to dark red.
Above +1.0 histogram color changes to dark green.View attachment 22016

Thank You!!

Code:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © Beardy_Fred
#indicator('Beardy Squeeze Pro', shorttitle='Squeeze', overlay=false, precision=2)
# Converted by Sam4Cok@Samer800        - 05/2023
declare lower;
input ShowLabel = yes;        # "Alert Price Action Squeeze"
input MovAvgType   = AverageType.SIMPLE;
input length       = 20;      # "TTM Squeeze Length"
input BB_mult      = 2.0;     # "Bollinger Band STD Multiplier"
input KC_mult_high = 1.0;     # "Keltner Channel #1"
input KC_mult_mid  = 1.5;     # "Keltner Channel #2"
input KC_mult_low  = 2.0;     # "Keltner Channel #3"

def na = Double.NaN;
def last = IsNaN(close);

#--- Color
DefineGlobalColor("up1", CreateColor(0, 188, 212));
DefineGlobalColor("dn2", CreateColor(41, 98, 255));
DefineGlobalColor("dn1", CreateColor(255, 50, 82));
DefineGlobalColor("up2", CreateColor(255, 75, 59));
#------
DefineGlobalColor("sqz1", CreateColor(255, 152, 0));
DefineGlobalColor("sqz2", CreateColor(255, 82, 82));
DefineGlobalColor("sqz3", Color.GRAY);#CreateColor(54,58,69));
DefineGlobalColor("sqz4", Color.GREEN);
#//BOLLINGER BANDS
def BB_basis = MovingAverage(MovAvgType, close, length);
def dev      = BB_mult * StDev(close, length);
def BB_upper = BB_basis + dev;
def BB_lower = BB_basis - dev;

#//KELTNER CHANNELS
def tr = TrueRange(high, close, low);
def KC_basis = MovingAverage(MovAvgType, close, length);
def devKC    = MovingAverage(MovAvgType, tr, length);
def KC_upper_high = KC_basis + devKC * KC_mult_high;
def KC_lower_high = KC_basis - devKC * KC_mult_high;
def KC_upper_mid  = KC_basis + devKC * KC_mult_mid;
def KC_lower_mid  = KC_basis - devKC * KC_mult_mid;
def KC_upper_low  = KC_basis + devKC * KC_mult_low;
def KC_lower_low  = KC_basis - devKC * KC_mult_low;

#//SQUEEZE CONDITIONS
def NoSqz   = BB_lower < KC_lower_low or BB_upper > KC_upper_low;# //NO SQUEEZE: GREEN
def LowSqz  = BB_lower >= KC_lower_low or BB_upper <= KC_upper_low;# //LOW COMPRESSION: BLACK
def MidSqz  = BB_lower >= KC_lower_mid or BB_upper <= KC_upper_mid;# //MID COMPRESSION: RED
def HighSqz = BB_lower >= KC_lower_high or BB_upper <= KC_upper_high;# //HIGH COMPRESSION: ORANGE

#//MOMENTUM OSCILLATOR
def hh = Highest(high, length);
def ll = Lowest(low, length);
def avg = (hh + ll) / 2;
def avgSMA = (avg + KC_basis) / 2;
def mom = Inertia(close - avgSMA, length);

#//MOMENTUM HISTOGRAM COLOR
def iff_1 = if mom > mom[1] then  2 else  1;
def iff_2 = if mom < mom[1] then -2 else -1;
def mom_color = if mom > 0 then iff_1 else iff_2;

#//SQUEEZE DOTS COLOR
def sq_color = if HighSqz then 3 else
               if MidSqz then 2 else
               if LowSqz then 1 else 0;
#//ALERTS

AddLabel(ShowLabel, if sq_color == 0 then "NO SQUEEZE" else
                    if sq_color == 1 then "LOW COMPRESSION" else
                    if sq_color == 2 then "MID COMPRESSION" else "HIGH COMPRESSION",
                    if sq_color == 3 then GlobalColor("sqz1") else
                    if sq_color == 2 then GlobalColor("sqz2") else
                    if sq_color == 1 then GlobalColor("sqz3") else GlobalColor("sqz4"));

#//PLOTS

plot SQZ = if last then na else 0;          # 'SQZ'
plot momentum = mom;                        # 'MOM'
momentum.SetLineWeight(4);
momentum.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
momentum.AssignValueColor(if mom_color == 2 then GlobalColor("up1") else
                          if mom_color == 1 then GlobalColor("up2") else
                          if mom_color == -2 then GlobalColor("dn1") else
                          if mom_color == -1 then GlobalColor("dn2") else Color.GRAY);
SQZ.SetLineWeight(2);
SQZ.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
SQZ.AssignValueColor(if sq_color == 3 then GlobalColor("sqz1") else
                     if sq_color == 2 then GlobalColor("sqz2") else
                     if sq_color == 1 then GlobalColor("sqz3") else GlobalColor("sqz4"));

plot Max_Momentum_Down = -1.0;
plot Max_Momentum_Up = 1.0;

Max_Momentum_Down.SetDefaultColor(GetColor(5));
Max_Momentum_Down.SetDefaultColor(GetColor(6));



#--- END OF CODE


here you go:


Code:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © Beardy_Fred
#indicator('Beardy Squeeze Pro', shorttitle='Squeeze', overlay=false, precision=2)
# Converted by Sam4Cok@Samer800        - 05/2023
declare lower;
input ShowLabel = yes;        # "Alert Price Action Squeeze"
input MovAvgType   = AverageType.SIMPLE;
input length       = 20;      # "TTM Squeeze Length"
input BB_mult      = 2.0;     # "Bollinger Band STD Multiplier"
input KC_mult_high = 1.0;     # "Keltner Channel #1"
input KC_mult_mid  = 1.5;     # "Keltner Channel #2"
input KC_mult_low  = 2.0;     # "Keltner Channel #3"

def na = Double.NaN;
def last = IsNaN(close);

#--- Color
DefineGlobalColor("up1", CreateColor(0, 188, 212));
DefineGlobalColor("dn2", CreateColor(41, 98, 255));
DefineGlobalColor("dn1", CreateColor(255, 50, 82));
DefineGlobalColor("up2", CreateColor(255, 75, 59));
#------
DefineGlobalColor("sqz1", CreateColor(255, 152, 0));
DefineGlobalColor("sqz2", CreateColor(255, 82, 82));
DefineGlobalColor("sqz3", Color.GRAY);#CreateColor(54,58,69));
DefineGlobalColor("sqz4", Color.GREEN);
#//BOLLINGER BANDS
def BB_basis = MovingAverage(MovAvgType, close, length);
def dev      = BB_mult * StDev(close, length);
def BB_upper = BB_basis + dev;
def BB_lower = BB_basis - dev;

#//KELTNER CHANNELS
def tr = TrueRange(high, close, low);
def KC_basis = MovingAverage(MovAvgType, close, length);
def devKC    = MovingAverage(MovAvgType, tr, length);
def KC_upper_high = KC_basis + devKC * KC_mult_high;
def KC_lower_high = KC_basis - devKC * KC_mult_high;
def KC_upper_mid  = KC_basis + devKC * KC_mult_mid;
def KC_lower_mid  = KC_basis - devKC * KC_mult_mid;
def KC_upper_low  = KC_basis + devKC * KC_mult_low;
def KC_lower_low  = KC_basis - devKC * KC_mult_low;

#//SQUEEZE CONDITIONS
def NoSqz   = BB_lower < KC_lower_low or BB_upper > KC_upper_low;# //NO SQUEEZE: GREEN
def LowSqz  = BB_lower >= KC_lower_low or BB_upper <= KC_upper_low;# //LOW COMPRESSION: BLACK
def MidSqz  = BB_lower >= KC_lower_mid or BB_upper <= KC_upper_mid;# //MID COMPRESSION: RED
def HighSqz = BB_lower >= KC_lower_high or BB_upper <= KC_upper_high;# //HIGH COMPRESSION: ORANGE

#//MOMENTUM OSCILLATOR
def hh = Highest(high, length);
def ll = Lowest(low, length);
def avg = (hh + ll) / 2;
def avgSMA = (avg + KC_basis) / 2;
def mom = Inertia(close - avgSMA, length);

#//MOMENTUM HISTOGRAM COLOR
def iff_1 = if mom > mom[1] then  2 else  1;
def iff_2 = if mom < mom[1] then -2 else -1;
def mom_color = if mom > 0 then iff_1 else iff_2;

#//SQUEEZE DOTS COLOR
def sq_color = if HighSqz then 3 else
               if MidSqz then 2 else
               if LowSqz then 1 else 0;
#//ALERTS

AddLabel(ShowLabel, if sq_color == 0 then "NO SQUEEZE" else
                    if sq_color == 1 then "LOW COMPRESSION" else
                    if sq_color == 2 then "MID COMPRESSION" else "HIGH COMPRESSION",
                    if sq_color == 3 then GlobalColor("sqz1") else
                    if sq_color == 2 then GlobalColor("sqz2") else
                    if sq_color == 1 then GlobalColor("sqz3") else GlobalColor("sqz4"));

#//PLOTS
plot Max_Momentum_Down = -1.0;
plot Max_Momentum_Up = 1.0;

plot SQZ = if last then na else 0;          # 'SQZ'
plot momentum = mom;                        # 'MOM'
momentum.SetLineWeight(4);
momentum.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
momentum.AssignValueColor(
if mom> 1 then color.dark_green else
if mom<-1 then color.dark_red else
if mom_color == 2 then GlobalColor("up1") else
                          if mom_color == 1 then GlobalColor("up2") else
                          if mom_color == -2 then GlobalColor("dn1") else
                          if mom_color == -1 then GlobalColor("dn2") else Color.GRAY);
SQZ.SetLineWeight(2);
SQZ.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
SQZ.AssignValueColor(if sq_color == 3 then GlobalColor("sqz1") else
                     if sq_color == 2 then GlobalColor("sqz2") else
                     if sq_color == 1 then GlobalColor("sqz3") else GlobalColor("sqz4"));


Max_Momentum_Down.SetDefaultColor(GetColor(5));
Max_Momentum_Down.SetDefaultColor(GetColor(6));



#--- END OF CODE

1717351039669.png
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

here you go:


Code:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © Beardy_Fred
#indicator('Beardy Squeeze Pro', shorttitle='Squeeze', overlay=false, precision=2)
# Converted by Sam4Cok@Samer800        - 05/2023
declare lower;
input ShowLabel = yes;        # "Alert Price Action Squeeze"
input MovAvgType   = AverageType.SIMPLE;
input length       = 20;      # "TTM Squeeze Length"
input BB_mult      = 2.0;     # "Bollinger Band STD Multiplier"
input KC_mult_high = 1.0;     # "Keltner Channel #1"
input KC_mult_mid  = 1.5;     # "Keltner Channel #2"
input KC_mult_low  = 2.0;     # "Keltner Channel #3"

def na = Double.NaN;
def last = IsNaN(close);

#--- Color
DefineGlobalColor("up1", CreateColor(0, 188, 212));
DefineGlobalColor("dn2", CreateColor(41, 98, 255));
DefineGlobalColor("dn1", CreateColor(255, 50, 82));
DefineGlobalColor("up2", CreateColor(255, 75, 59));
#------
DefineGlobalColor("sqz1", CreateColor(255, 152, 0));
DefineGlobalColor("sqz2", CreateColor(255, 82, 82));
DefineGlobalColor("sqz3", Color.GRAY);#CreateColor(54,58,69));
DefineGlobalColor("sqz4", Color.GREEN);
#//BOLLINGER BANDS
def BB_basis = MovingAverage(MovAvgType, close, length);
def dev      = BB_mult * StDev(close, length);
def BB_upper = BB_basis + dev;
def BB_lower = BB_basis - dev;

#//KELTNER CHANNELS
def tr = TrueRange(high, close, low);
def KC_basis = MovingAverage(MovAvgType, close, length);
def devKC    = MovingAverage(MovAvgType, tr, length);
def KC_upper_high = KC_basis + devKC * KC_mult_high;
def KC_lower_high = KC_basis - devKC * KC_mult_high;
def KC_upper_mid  = KC_basis + devKC * KC_mult_mid;
def KC_lower_mid  = KC_basis - devKC * KC_mult_mid;
def KC_upper_low  = KC_basis + devKC * KC_mult_low;
def KC_lower_low  = KC_basis - devKC * KC_mult_low;

#//SQUEEZE CONDITIONS
def NoSqz   = BB_lower < KC_lower_low or BB_upper > KC_upper_low;# //NO SQUEEZE: GREEN
def LowSqz  = BB_lower >= KC_lower_low or BB_upper <= KC_upper_low;# //LOW COMPRESSION: BLACK
def MidSqz  = BB_lower >= KC_lower_mid or BB_upper <= KC_upper_mid;# //MID COMPRESSION: RED
def HighSqz = BB_lower >= KC_lower_high or BB_upper <= KC_upper_high;# //HIGH COMPRESSION: ORANGE

#//MOMENTUM OSCILLATOR
def hh = Highest(high, length);
def ll = Lowest(low, length);
def avg = (hh + ll) / 2;
def avgSMA = (avg + KC_basis) / 2;
def mom = Inertia(close - avgSMA, length);

#//MOMENTUM HISTOGRAM COLOR
def iff_1 = if mom > mom[1] then  2 else  1;
def iff_2 = if mom < mom[1] then -2 else -1;
def mom_color = if mom > 0 then iff_1 else iff_2;

#//SQUEEZE DOTS COLOR
def sq_color = if HighSqz then 3 else
               if MidSqz then 2 else
               if LowSqz then 1 else 0;
#//ALERTS

AddLabel(ShowLabel, if sq_color == 0 then "NO SQUEEZE" else
                    if sq_color == 1 then "LOW COMPRESSION" else
                    if sq_color == 2 then "MID COMPRESSION" else "HIGH COMPRESSION",
                    if sq_color == 3 then GlobalColor("sqz1") else
                    if sq_color == 2 then GlobalColor("sqz2") else
                    if sq_color == 1 then GlobalColor("sqz3") else GlobalColor("sqz4"));

#//PLOTS
plot Max_Momentum_Down = -1.0;
plot Max_Momentum_Up = 1.0;

plot SQZ = if last then na else 0;          # 'SQZ'
plot momentum = mom;                        # 'MOM'
momentum.SetLineWeight(4);
momentum.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
momentum.AssignValueColor(
if mom> 1 then color.dark_green else
if mom<-1 then color.dark_red else
if mom_color == 2 then GlobalColor("up1") else
                          if mom_color == 1 then GlobalColor("up2") else
                          if mom_color == -2 then GlobalColor("dn1") else
                          if mom_color == -1 then GlobalColor("dn2") else Color.GRAY);
SQZ.SetLineWeight(2);
SQZ.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
SQZ.AssignValueColor(if sq_color == 3 then GlobalColor("sqz1") else
                     if sq_color == 2 then GlobalColor("sqz2") else
                     if sq_color == 1 then GlobalColor("sqz3") else GlobalColor("sqz4"));


Max_Momentum_Down.SetDefaultColor(GetColor(5));
Max_Momentum_Down.SetDefaultColor(GetColor(6));



#--- END OF CODE

View attachment 22020
Thank You!!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
230 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