Beardy Squeeze Pro For ThinkOrSwim

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
add this at the end of the code:

CSS:
input threshold = 1.0;
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
AddCloud(if mom>= threshold then pos else na, neg, Color.DARK_GREEN);
AddCloud(if mom<=-threshold then pos else na, neg, Color.DARK_RED);
 
Is it possible to add a divergence indicator line and an alert to the Beardy Squeeze Pro histogram
https://usethinkscript.com/threads/beardy-squeeze-pro-for-thinkorswim.15338/?
check the below:

Code:
#// This source code is subject to the terms of the Mozilla Publi
#// © Beardy_Fred
#indicator('Beardy Squeeze Pro', shorttitle='Squeeze', overlay=false, precision=2)
# Converted and mod By Sam4Cok@Samer800    - 10 / 2023
# Update - Added Divergences - 08/2024
declare lower;
input enabelAlerts   = yes;
input alertSound    = {default "NoSound", "Ding", "Bell", "Chimes", "Ring"};
input alertType  = Alert.BAR;
input showLabel = yes;
input colorBars = {Default "On Squeeze", "On Momentum", "Don't Color Bars"};
input movAvgType = AverageType.SIMPLE;
input source = close;
input length = 20;#, "TTM Squeeze Length")
input threshold = 1.0;
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);
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
def sqzBar = colorBars==colorBars."On Squeeze";
def momBar = colorBars==colorBars."On Momentum";

#--Colors
DefineGlobalColor("upGrow", CreateColor(0,188,212));
DefineGlobalColor("upFall", CreateColor(41,98,255));
DefineGlobalColor("dnGrow", CreateColor(255,235,59));
DefineGlobalColor("dnFall", CreateColor(255,82,82));

DefineGlobalColor("noSq", CreateColor(76,175,80));
DefineGlobalColor("loSq", Color.DARK_GRAY); #Color.GRAY);#CreateColor(54,58,69));
DefineGlobalColor("hiSq", Color.MAGENTA); #Color.RED); #CreateColor(255,82,82));
DefineGlobalColor("midSq",Color.PLUM); #CreateColor(255,152,0));
#//BOLLINGER BANDS
def BB_basis = MovingAverage(movAvgType, source, length);
def dev = BB_mult * StDev(source, length);
def BB_upper = BB_basis + dev;
def BB_lower = BB_basis - dev;

#//KELTNER CHANNELS
def KC_basis = BB_basis;#ta.sma(close, length)
def tr = TrueRange(high, close, low);
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 hlAvg = (hh + ll + KC_basis) / 3;
def mom = Inertia(source - hlAvg, length);

#//MOMENTUM HISTOGRAM COLOR
def mom_col = if mom > 0 then
              if mom > mom[1] then 2 else 1 else
              if mom > mom[1] then -2 else - 1;
#//SQUEEZE DOTS COLOR
def sq_col = if HighSqz then 3 else
             if MidSqz  then 2 else
             if LowSqz  then 1 else 0;

#//PLOTS
plot sqLine = if last then na else 0;    # 'SQZ'
plot momHist = mom;                      # 'MOM'

sqLine.SetLineWeight(2);
sqLine.SetPaintingStrategy(paintingStrategy.POINTS);
sqLine.AssignValueColor(if sq_col==3 then GlobalColor("hiSq") else
                        if sq_col==2 then GlobalColor("midSq") else
                        if sq_col==1 then GlobalColor("loSq") else  GlobalColor("noSq"));

momHist.SetPaintingStrategy(paintingStrategy.SQUARED_HISTOGRAM);
momHist.AssignValueColor(if mom_col== 2 then GlobalColor("upGrow") else
                         if mom_col== 1 then GlobalColor("upFall") else
                         if mom_col==-2 then GlobalColor("dnGrow") else GlobalColor("dnFall"));
#-- Label
AddLabel(showLabel and sq_col==3, "HIGH COMPRESSION", GlobalColor("hiSq"));
AddLabel(showLabel and sq_col==2, "MID COMPRESSION",  GlobalColor("midSq"));
AddLabel(showLabel and sq_col==1, "LOW COMPRESSION", GlobalColor("loSq"));
AddLabel(showLabel and sq_col==0, "NO SQUEEZE", GlobalColor("noSq"));

#-- Bar Color
AssignPriceColor(if !momBar then Color.CURRENT else
                 if mom_col== 2 then GlobalColor("upGrow") else
                 if mom_col== 1 then GlobalColor("upFall") else
                 if mom_col==-2 then GlobalColor("dnGrow") else GlobalColor("dnFall"));

AssignPriceColor(if !sqzBar then Color.CURRENT else
                 if sq_col==3 then GlobalColor("hiSq") else
                 if sq_col==2 then GlobalColor("midSq") else
                 if sq_col==1 then GlobalColor("loSq") else  GlobalColor("noSq"));

AddCloud(if mom>= threshold then pos else na, neg, Color.DARK_GREEN);
AddCloud(if mom<=-threshold then pos else na, neg, Color.DARK_RED);
#-- END of CODE

#----Div-----------
input showDivergences = yes;
input LookBackRight  = 5; # "Pivot Lookback Right"
input LookBackLeft  = 5;  # "Pivot Lookback Left"
input MaxLookback = 60;   # "Max of Lookback Range"
input MinLookback = 5;    # "Min of Lookback Range"

def divSrc = mom;

def h = high;
def l = low;

Script Pivot {
    input series    = close;
    input leftBars  = 10;
    input rightBars = 10;
    input isHigh = yes;
    def na = Double.NaN;
    def HH = series == Highest(series, leftBars + 1);
    def LL = series == Lowest(series, leftBars + 1);
    def pivotRange = (leftBars + rightBars + 1);
    def leftEdgeValue = if series[pivotRange] ==0 then na else series[pivotRange];
    def pvtCond = !isNaN(series) and leftBars > 0 and rightBars > 0 and !isNaN(leftEdgeValue);
    def barIndexH = if pvtCond then
                    fold i = 1 to rightBars + 1 with p=1 while p do
                    series > GetValue(series, - i) else na;
    def barIndexL = if pvtCond then
                    fold j = 1 to rightBars + 1 with q=1 while q do
                    series < GetValue(series, - j) else na;
    def PivotPoint;
if isHigh {
    PivotPoint = if HH and barIndexH then series else na;
    } else {
    PivotPoint = if LL and barIndexL then series else na;
    }
    plot pvt = PivotPoint;
}
#_inRange(cond) =>
script _inRange {
    input cond = yes;
    input rangeUpper = 60;
    input rangeLower = 5;
        def bars = if cond then 0 else bars[1] + 1;
        def inrange =  (rangeLower <= bars) and (bars <= rangeUpper);
plot retrun = inRange;
}
def pl_ = pivot(divSrc,LookBackLeft, LookBackRight, no);
def ph_ = pivot(divSrc,LookBackLeft, LookBackRight, yes);
def pl = !isNaN(pl_);
def ph = !isNaN(ph_);
def pll = lowest(divSrc,LookBackLeft +1);
def phh = highest(divSrc,LookBackLeft+1);
def sll = lowest(l, LookBackLeft +1);
def shh = highest(h, LookBackLeft+1);
#-- Pvt Low
def plStart  = if pl then yes else plStart[1];
def plFound  = if (plStart and pl) then 1 else 0;
def vlFound1 = if plFound then divSrc else vlFound1[1];
def vlFound_ = if vlFound1!=vlFound1[1] then vlFound1[1] else vlFound_[1];
def vlFound  = if !vlFound_ then pll else vlFound_;
def plPrice1 = if plFound then l else plPrice1[1];
def plPrice_ = if plPrice1!=plPrice1[1] then plPrice1[1] else plPrice_[1];
def plPrice  = if !plPrice_ then sll else plPrice_;
#-- Pvt High
def phStart = if ph then yes else phStart[1];
def phFound = if (phStart and ph) then 1 else 0;
def vhFound1 = if phFound then divSrc else vhFound1[1];
def vhFound_ = if vhFound1!=vhFound1[1] then vhFound1[1] else vhFound_[1];
def vhFound = if !vhFound_ then phh else vhFound_;
def phPrice1 = if phFound then h else phPrice1[1];
def phPrice_ = if phPrice1!=phPrice1[1] then phPrice1[1] else phPrice_[1];
def phPrice = if !phPrice_ then shh else phPrice_;
#// Regular Bullish
def inRangePl = _inRange(plFound[1],MaxLookback,MinLookback);
def oscHL = divSrc > vlFound and inRangePl;
def priceLL = l < plPrice and divSrc < 0;
def bullCond = plFound and oscHL and priceLL;
#// Regular Bearish
def inRangePh = _inRange(phFound[1],MaxLookback,MinLookback);
def oscLH   = divSrc < vhFound and inRangePh;
def priceHH = h > phPrice and divSrc > 0;
def bearCond = phFound and oscLH and priceHH;

#------ Bubbles
def bullBub  = showDivergences and bullCond;
def bearBub  = showDivergences and bearCond;

addchartbubble(bullBub, divSrc, "R", Color.GREEN, no);
addchartbubble(bearBub, divSrc, "R", Color.RED, yes);

##### Lines
def bar = BarNumber();
#-- Bear Line
def lastPhBar  = if ph then bar else lastPhBar[1];
def prePhBar   = if lastPhBar!=lastPhBar[1] then lastPhBar[1] else prePhBar[1];
def priorPHBar = if bearCond then prePhBar else priorPHBar[1];
#-- Bull Line
def lastPlBar = if pl then bar else lastPlBar[1];
def prePlBar  = if lastPlBar!=lastPlBar[1] then lastPlBar[1] else prePlBar[1];
def priorPLBar = if bullCond then prePlBar else priorPLBar[1];

def lastBullBar = if bullCond then bar else lastBullBar[1];
def lastBearBar = if bearCond then bar else lastBearBar[1];

def HighPivots = ph and bar >= HighestAll(priorPHBar) and bar <= HighestAll(lastBearBar);
def LowPivots  = pl and bar >= HighestAll(priorPLBar) and bar <= HighestAll(lastBullBar);

def pivotHigh = if HighPivots then divSrc else na;
def pivotLow  = if LowPivots  then divSrc else na;

plot PlotHline = if showDivergences then pivotHigh else na;
PlotHline.EnableApproximation();
PlotHline.SetDefaultColor(Color.RED);

plot PlotLline = if showDivergences then pivotLow else na;
PlotLline.EnableApproximation();
PlotLline.SetDefaultColor(Color.GREEN);

#---- Alerts
Alert(enabelAlerts and bullCond, "Bullish Div", alertType, alertSound);
Alert(enabelAlerts and bearCond, "Bearish Div", alertType, alertSound);

#-- END of CODE
 
check the below:

Code:
#// This source code is subject to the terms of the Mozilla Publi
#// © Beardy_Fred
#indicator('Beardy Squeeze Pro', shorttitle='Squeeze', overlay=false, precision=2)
# Converted and mod By Sam4Cok@Samer800    - 10 / 2023
# Update - Added Divergences - 08/2024
declare lower;
input enabelAlerts   = yes;
input alertSound    = {default "NoSound", "Ding", "Bell", "Chimes", "Ring"};
input alertType  = Alert.BAR;
input showLabel = yes;
input colorBars = {Default "On Squeeze", "On Momentum", "Don't Color Bars"};
input movAvgType = AverageType.SIMPLE;
input source = close;
input length = 20;#, "TTM Squeeze Length")
input threshold = 1.0;
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);
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
def sqzBar = colorBars==colorBars."On Squeeze";
def momBar = colorBars==colorBars."On Momentum";

#--Colors
DefineGlobalColor("upGrow", CreateColor(0,188,212));
DefineGlobalColor("upFall", CreateColor(41,98,255));
DefineGlobalColor("dnGrow", CreateColor(255,235,59));
DefineGlobalColor("dnFall", CreateColor(255,82,82));

DefineGlobalColor("noSq", CreateColor(76,175,80));
DefineGlobalColor("loSq", Color.DARK_GRAY); #Color.GRAY);#CreateColor(54,58,69));
DefineGlobalColor("hiSq", Color.MAGENTA); #Color.RED); #CreateColor(255,82,82));
DefineGlobalColor("midSq",Color.PLUM); #CreateColor(255,152,0));
#//BOLLINGER BANDS
def BB_basis = MovingAverage(movAvgType, source, length);
def dev = BB_mult * StDev(source, length);
def BB_upper = BB_basis + dev;
def BB_lower = BB_basis - dev;

#//KELTNER CHANNELS
def KC_basis = BB_basis;#ta.sma(close, length)
def tr = TrueRange(high, close, low);
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 hlAvg = (hh + ll + KC_basis) / 3;
def mom = Inertia(source - hlAvg, length);

#//MOMENTUM HISTOGRAM COLOR
def mom_col = if mom > 0 then
              if mom > mom[1] then 2 else 1 else
              if mom > mom[1] then -2 else - 1;
#//SQUEEZE DOTS COLOR
def sq_col = if HighSqz then 3 else
             if MidSqz  then 2 else
             if LowSqz  then 1 else 0;

#//PLOTS
plot sqLine = if last then na else 0;    # 'SQZ'
plot momHist = mom;                      # 'MOM'

sqLine.SetLineWeight(2);
sqLine.SetPaintingStrategy(paintingStrategy.POINTS);
sqLine.AssignValueColor(if sq_col==3 then GlobalColor("hiSq") else
                        if sq_col==2 then GlobalColor("midSq") else
                        if sq_col==1 then GlobalColor("loSq") else  GlobalColor("noSq"));

momHist.SetPaintingStrategy(paintingStrategy.SQUARED_HISTOGRAM);
momHist.AssignValueColor(if mom_col== 2 then GlobalColor("upGrow") else
                         if mom_col== 1 then GlobalColor("upFall") else
                         if mom_col==-2 then GlobalColor("dnGrow") else GlobalColor("dnFall"));
#-- Label
AddLabel(showLabel and sq_col==3, "HIGH COMPRESSION", GlobalColor("hiSq"));
AddLabel(showLabel and sq_col==2, "MID COMPRESSION",  GlobalColor("midSq"));
AddLabel(showLabel and sq_col==1, "LOW COMPRESSION", GlobalColor("loSq"));
AddLabel(showLabel and sq_col==0, "NO SQUEEZE", GlobalColor("noSq"));

#-- Bar Color
AssignPriceColor(if !momBar then Color.CURRENT else
                 if mom_col== 2 then GlobalColor("upGrow") else
                 if mom_col== 1 then GlobalColor("upFall") else
                 if mom_col==-2 then GlobalColor("dnGrow") else GlobalColor("dnFall"));

AssignPriceColor(if !sqzBar then Color.CURRENT else
                 if sq_col==3 then GlobalColor("hiSq") else
                 if sq_col==2 then GlobalColor("midSq") else
                 if sq_col==1 then GlobalColor("loSq") else  GlobalColor("noSq"));

AddCloud(if mom>= threshold then pos else na, neg, Color.DARK_GREEN);
AddCloud(if mom<=-threshold then pos else na, neg, Color.DARK_RED);
#-- END of CODE

#----Div-----------
input showDivergences = yes;
input LookBackRight  = 5; # "Pivot Lookback Right"
input LookBackLeft  = 5;  # "Pivot Lookback Left"
input MaxLookback = 60;   # "Max of Lookback Range"
input MinLookback = 5;    # "Min of Lookback Range"

def divSrc = mom;

def h = high;
def l = low;

Script Pivot {
    input series    = close;
    input leftBars  = 10;
    input rightBars = 10;
    input isHigh = yes;
    def na = Double.NaN;
    def HH = series == Highest(series, leftBars + 1);
    def LL = series == Lowest(series, leftBars + 1);
    def pivotRange = (leftBars + rightBars + 1);
    def leftEdgeValue = if series[pivotRange] ==0 then na else series[pivotRange];
    def pvtCond = !isNaN(series) and leftBars > 0 and rightBars > 0 and !isNaN(leftEdgeValue);
    def barIndexH = if pvtCond then
                    fold i = 1 to rightBars + 1 with p=1 while p do
                    series > GetValue(series, - i) else na;
    def barIndexL = if pvtCond then
                    fold j = 1 to rightBars + 1 with q=1 while q do
                    series < GetValue(series, - j) else na;
    def PivotPoint;
if isHigh {
    PivotPoint = if HH and barIndexH then series else na;
    } else {
    PivotPoint = if LL and barIndexL then series else na;
    }
    plot pvt = PivotPoint;
}
#_inRange(cond) =>
script _inRange {
    input cond = yes;
    input rangeUpper = 60;
    input rangeLower = 5;
        def bars = if cond then 0 else bars[1] + 1;
        def inrange =  (rangeLower <= bars) and (bars <= rangeUpper);
plot retrun = inRange;
}
def pl_ = pivot(divSrc,LookBackLeft, LookBackRight, no);
def ph_ = pivot(divSrc,LookBackLeft, LookBackRight, yes);
def pl = !isNaN(pl_);
def ph = !isNaN(ph_);
def pll = lowest(divSrc,LookBackLeft +1);
def phh = highest(divSrc,LookBackLeft+1);
def sll = lowest(l, LookBackLeft +1);
def shh = highest(h, LookBackLeft+1);
#-- Pvt Low
def plStart  = if pl then yes else plStart[1];
def plFound  = if (plStart and pl) then 1 else 0;
def vlFound1 = if plFound then divSrc else vlFound1[1];
def vlFound_ = if vlFound1!=vlFound1[1] then vlFound1[1] else vlFound_[1];
def vlFound  = if !vlFound_ then pll else vlFound_;
def plPrice1 = if plFound then l else plPrice1[1];
def plPrice_ = if plPrice1!=plPrice1[1] then plPrice1[1] else plPrice_[1];
def plPrice  = if !plPrice_ then sll else plPrice_;
#-- Pvt High
def phStart = if ph then yes else phStart[1];
def phFound = if (phStart and ph) then 1 else 0;
def vhFound1 = if phFound then divSrc else vhFound1[1];
def vhFound_ = if vhFound1!=vhFound1[1] then vhFound1[1] else vhFound_[1];
def vhFound = if !vhFound_ then phh else vhFound_;
def phPrice1 = if phFound then h else phPrice1[1];
def phPrice_ = if phPrice1!=phPrice1[1] then phPrice1[1] else phPrice_[1];
def phPrice = if !phPrice_ then shh else phPrice_;
#// Regular Bullish
def inRangePl = _inRange(plFound[1],MaxLookback,MinLookback);
def oscHL = divSrc > vlFound and inRangePl;
def priceLL = l < plPrice and divSrc < 0;
def bullCond = plFound and oscHL and priceLL;
#// Regular Bearish
def inRangePh = _inRange(phFound[1],MaxLookback,MinLookback);
def oscLH   = divSrc < vhFound and inRangePh;
def priceHH = h > phPrice and divSrc > 0;
def bearCond = phFound and oscLH and priceHH;

#------ Bubbles
def bullBub  = showDivergences and bullCond;
def bearBub  = showDivergences and bearCond;

addchartbubble(bullBub, divSrc, "R", Color.GREEN, no);
addchartbubble(bearBub, divSrc, "R", Color.RED, yes);

##### Lines
def bar = BarNumber();
#-- Bear Line
def lastPhBar  = if ph then bar else lastPhBar[1];
def prePhBar   = if lastPhBar!=lastPhBar[1] then lastPhBar[1] else prePhBar[1];
def priorPHBar = if bearCond then prePhBar else priorPHBar[1];
#-- Bull Line
def lastPlBar = if pl then bar else lastPlBar[1];
def prePlBar  = if lastPlBar!=lastPlBar[1] then lastPlBar[1] else prePlBar[1];
def priorPLBar = if bullCond then prePlBar else priorPLBar[1];

def lastBullBar = if bullCond then bar else lastBullBar[1];
def lastBearBar = if bearCond then bar else lastBearBar[1];

def HighPivots = ph and bar >= HighestAll(priorPHBar) and bar <= HighestAll(lastBearBar);
def LowPivots  = pl and bar >= HighestAll(priorPLBar) and bar <= HighestAll(lastBullBar);

def pivotHigh = if HighPivots then divSrc else na;
def pivotLow  = if LowPivots  then divSrc else na;

plot PlotHline = if showDivergences then pivotHigh else na;
PlotHline.EnableApproximation();
PlotHline.SetDefaultColor(Color.RED);

plot PlotLline = if showDivergences then pivotLow else na;
PlotLline.EnableApproximation();
PlotLline.SetDefaultColor(Color.GREEN);

#---- Alerts
Alert(enabelAlerts and bullCond, "Bullish Div", alertType, alertSound);
Alert(enabelAlerts and bearCond, "Bearish Div", alertType, alertSound);

#-- END of CODE

That is beautiful. Thank you so much, samer800. You are the best. 🙏(y)
 
If your question is:
Can this script be used in the Scan Hacker to find High Compression Squeeze Dots,
identified as:


The answer is, yes
Shared Scanner Link: http://tos.mx/MLNzoAn Click here for --> Easiest way to load shared links

kJ7Hzhg.png
This is great thanks. This gets me to the symbols I'm interested in. But what I really want to do is analyze the related options. I want to know things like which symbols have weekly options and the delta for the ATM call and put. I also need the 21 EMA for the symbol. Is there a way to run a scan to put all that in one spreadsheet to analyze? As is, it pulls up hundreds of symbols that I have to look at one by one.
 
what I really want to do is analyze the related options. I want to know things like which symbols have weekly options and the delta for the ATM call and put
The ToS Options Hacker Module doesn't allow the using of custom studies to scan against options related data.
Here is what is available:
https://usethinkscript.com/threads/options-scan-hacker-in-thinkorswim.5114/page-4#post-82892


. I also need the 21 EMA for the symbol.
Yes, you can add additional filters to the above scan.
1. click on add filter (top, right-side)
2. click on study
3. click on the pencil (to the right of the aggregation)
4. click on thinkScript editor
5. paste in the following code:
close >= expAverage(close,21)
6. click on ok
7. click on the right-hand menu (the one next to the flame-looking icon) and click on 'save scan query'
8. give it a new name
9. click on save

https://toslc.thinkorswim.com/center/howToTos/thinkManual/Scan/Stock-Hacker
 
Last edited by a moderator:

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