overlaid studies in lower chart

candlestix

New member
I I have a question. I have 2 indicators layered on top of each other, but every time I zoom in or move my chart the indicators separate. Is there a code that you can add so they both are aligned at the 0 line?
 
I I have a question. I have 2 indicators layered on top of each other, but every time I zoom in or move my chart the indicators separate. Is there a code that you can add so they both are aligned at the 0 line?
It depends on what both of them are doing, can you give an example or a screenshot of what you putting together?
 

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

I I have a question. I have 2 indicators layered on top of each other, but every time I zoom in or move my chart the indicators separate. Is there a code that you can add so they both are aligned at the 0 line?

@candlestix : Sounds like a scaling issue...I just worked on a similar issue... What are the indicators that are "layered"?

If possible, post the names of the indicators and/or a screenshot, as @ApeX Predator requested...
 
@candlestix : Area 1 highlights the overlaying of the Squeeze indicator by the ErgodicOsc indicator. As a result of using the two default indicators without changing the code you get the scaling issue I mentioned previously. The Scale is in percentages instead of numbers. Also, the Zero Lines are off.

Area 2 shows the proper overlaying of the two indicators where the Scale should and does have values revolving around a common Zero Line. In my opinion, the merging of these two indicators makes the newly combined indicator difficult to read, due to using two histograms for display of the data...

a.png



Below are three options to choose from:

d.png



Option 1: The original merging of the two indicators complete with two histograms and the aforementioned readability issue...

Option 2 : Changes the ErgodicOsc from a histogram to a line with the original coloring intact. Once again, this can be difficult to read in spots...

Option 3: Keeps the ErgodicOsc as a line and changes the coloring to white for contrast, clarity and easy readability...


Below is the respective code for each of the options:

Option 1
Code:
declare lower;

script normalizer {
    input data   = close;
    input Min    = -1;
    input Max    = 1;
    input length = 50;

    def hhData   = Highest(data, length);
    def llData   = Lowest(data, length);

    plot resized = (((Max - Min) * (data - llData)) /

                       (hhData - llData)) + Min;
}


### ERGODIC OSCILLATOR ###
input longLength = 25;
input shortLength = 13;
input signalLength = 8;
input averageType = AverageType.EXPONENTIAL;

plot ErgodicOsc = normalizer(TrueStrengthIndex(longLength, shortLength, signalLength, averageType).TSI - TrueStrengthIndex(longLength, shortLength, signalLength, averageType).Signal);

ErgodicOsc.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
ErgodicOsc.SetLineWeight(3);
ErgodicOsc.DefineColor("Positive", Color.UPTICK);
ErgodicOsc.DefineColor("Negative", Color.DOWNTICK);
ErgodicOsc.AssignValueColor(if ErgodicOsc >= 0 then ErgodicOsc.Color("Positive") else ErgodicOsc.Color("Negative"));


### SQUEEZE ###
input length = 21; #hint length: Length for average calculation.
input price = close;
input SDmult = 2.0;
input ATRmult = 1.5;
def K = (Highest(high, length) + Lowest(low, length)) / 2 + ExpAverage(close, length);

plot Momo = normalizer(Inertia(price - K / 2, length));
Momo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Momo.SetLineWeight(3);
Momo.AssignValueColor(if Momo > Momo[1] and Momo > 0 then Color.CYAN
else if Momo > 0 and Momo < Momo[1] then Color.BLUE
else if Momo < 0 and Momo < Momo[1] then Color.RED
else Color.YELLOW);

#--------------- [ Metrics From Mobius ] ---------------

def SD = StDev(close, length);
def Avg = Average(close, length);
def ATR = Average(TrueRange(high, close, low), length);
def SDup = normalizer(Avg + (SDmult * SD));
def ATRup = normalizer(Avg + (ATRmult * ATR));

plot Squeeze = if SDup < ATRUp then 0 else Double.NaN;


#------------------------------------------------------------------------------------------
#  David M.(Some Random Alien) 10-6-2021
#  Don't blame Mobius... I made this mess :)
#  Code displays Squeeze Watch Prediction Index.
#  Depending on volume, a score of less then 25 could signal an impeding Squeeze.

def squeezePrediction = ((SDup - ATRup) / (SDup + ATRup) / 2) * 100;
def squeezeIndex = Round(squeezePrediction * 10000, 0);
def squeezeIndexDifference = (squeezeIndex - squeezeIndex[1]) / (squeezeIndex + squeezeIndex[1]) / 2 * 100;
def squeezeProgress = Round((squeezePrediction - squeezePrediction[1]) * 10000, 2);
def squeezeIndexOn = squeezeIndex <= 0;
rec counter = if squeezeIndexOn then counter[1] + 1 else 0;
def deepSqueeze = squeezeIndex <= -20;

rec accumCounter = if squeezeIndex >= 0 then accumCounter[1] + 1 else 0;
rec historicalDifference = if squeezeIndexOn then Lowest(squeezeIndexDifference) else historicalDifference[1];


#---------------------------- [ Plots Some Dots ] -----------------------------

Squeeze.SetPaintingStrategy(PaintingStrategy.POINTS);
Squeeze.SetLineWeight(5);
Squeeze.AssignValueColor( if deepSqueeze then CreateColor(185, 30, 249) else color.RED);
Squeeze.SetDefaultColor(Color.RED);


#------------------------------------------------------------------------------
# Make the SI bar look pretty :)

#AddLabel(yes, " SQUEEZE INDEX: " + squeezeIndex + " [" + squeezeIndex[1] + "] " + "[" + AsText(squeezeIndexDifference, NumberFormat.TWO_DECIMAL_PLACES) + "%] " + "[" + (counter[1]) + "] | " + "[" + accumCounter + "] " + "[" + AsText(historicalDifference[1], NumberFormat.TWO_DECIMAL_PLACES) + "%] ", if squeezeIndex > squeezeIndex[1] and squeezeIndex > 50 and squeezeIndexDifference > 0 then CreateColor(16, 198, 226) else color.LIGHT_ORANGE);

def fixBug = if squeezeIndex >= 0 then counter[1] == counter[1] == 0  else Double.NaN;

#--------------------------------------------------------------------------------------------------


#---------------------------------------------------------------------------------------------------
#
# I changed this Mobius code to show orange during initial squeeze
# and then turns to red if >5 squeeze bars. John Carter believes that a squeeze of 5 is better
# than a squeeze of 2 or 3. He is correct. However, during my initial testing, a squeeze of more
# than 5 is not better. During my testing, a squeeze substantially greater than 20 is worse than a 5.
# Your mileage may vary. Consult your owner's manual for more information. Hands and feet inside the ride
# at  all times :) And because I am a self-taught coder, I messed up Mobius' pretty formatting to reflect
# my ignorance of the craft :)
#
#----------------------------------------------------------------------------------------------------

#AddLabel(!IsNaN(Squeeze), "  >>> Squeeze <<<  ", if IsAscending(Momo)
#then Color.GREEN else if counter[1] >= 5 then Color.RED else CreateColor(16, 198, 226));

def cleanup = if IsNaN(Squeeze) then counter[1] == 0 else 0;


plot zero = if IsNaN(close) or !IsNaN(Squeeze) then Double.NaN else 0;

zero.SetPaintingStrategy(PaintingStrategy.POINTS);
zero.SetLineWeight(5);
zero.SetDefaultColor(Color.GREEN);


Option 2
Code:
declare lower;

script normalizer {
    input data   = close;
    input Min    = -1;
    input Max    = 1;
    input length = 50;

    def hhData   = Highest(data, length);
    def llData   = Lowest(data, length);

    plot resized = (((Max - Min) * (data - llData)) /

                       (hhData - llData)) + Min;
}


### ERGODIC OSCILLATOR ###
input longLength = 25;
input shortLength = 13;
input signalLength = 8;
input averageType = AverageType.EXPONENTIAL;

plot ErgodicOsc = normalizer(TrueStrengthIndex(longLength, shortLength, signalLength, averageType).TSI - TrueStrengthIndex(longLength, shortLength, signalLength, averageType).Signal);

ErgodicOsc.SetPaintingStrategy(PaintingStrategy.LINE);
ErgodicOsc.SetLineWeight(3);
ErgodicOsc.DefineColor("Positive", Color.UPTICK);
ErgodicOsc.DefineColor("Negative", Color.DOWNTICK);
ErgodicOsc.AssignValueColor(if ErgodicOsc >= 0 then ErgodicOsc.Color("Positive") else ErgodicOsc.Color("Negative"));


### SQUEEZE ###
input length = 21; #hint length: Length for average calculation.
input price = close;
input SDmult = 2.0;
input ATRmult = 1.5;
def K = (Highest(high, length) + Lowest(low, length)) / 2 + ExpAverage(close, length);

plot Momo = normalizer(Inertia(price - K / 2, length));
Momo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Momo.SetLineWeight(5);
Momo.AssignValueColor(if Momo > Momo[1] and Momo > 0 then Color.CYAN
else if Momo > 0 and Momo < Momo[1] then Color.BLUE
else if Momo < 0 and Momo < Momo[1] then Color.RED
else Color.YELLOW);

#--------------- [ Metrics From Mobius ] ---------------

def SD = StDev(close, length);
def Avg = Average(close, length);
def ATR = Average(TrueRange(high, close, low), length);
def SDup = normalizer(Avg + (SDmult * SD));
def ATRup = normalizer(Avg + (ATRmult * ATR));

plot Squeeze = if SDup < ATRUp then 0 else Double.NaN;


#------------------------------------------------------------------------------------------
#  David M.(Some Random Alien) 10-6-2021
#  Don't blame Mobius... I made this mess :)
#  Code displays Squeeze Watch Prediction Index.
#  Depending on volume, a score of less then 25 could signal an impeding Squeeze.

def squeezePrediction = ((SDup - ATRup) / (SDup + ATRup) / 2) * 100;
def squeezeIndex = Round(squeezePrediction * 10000, 0);
def squeezeIndexDifference = (squeezeIndex - squeezeIndex[1]) / (squeezeIndex + squeezeIndex[1]) / 2 * 100;
def squeezeProgress = Round((squeezePrediction - squeezePrediction[1]) * 10000, 2);
def squeezeIndexOn = squeezeIndex <= 0;
rec counter = if squeezeIndexOn then counter[1] + 1 else 0;
def deepSqueeze = squeezeIndex <= -20;

rec accumCounter = if squeezeIndex >= 0 then accumCounter[1] + 1 else 0;
rec historicalDifference = if squeezeIndexOn then Lowest(squeezeIndexDifference) else historicalDifference[1];


#---------------------------- [ Plots Some Dots ] -----------------------------

Squeeze.SetPaintingStrategy(PaintingStrategy.POINTS);
Squeeze.SetLineWeight(5);
Squeeze.AssignValueColor( if deepSqueeze then CreateColor(185, 30, 249) else color.RED);
Squeeze.SetDefaultColor(Color.RED);


#------------------------------------------------------------------------------
# Make the SI bar look pretty :)

#AddLabel(yes, " SQUEEZE INDEX: " + squeezeIndex + " [" + squeezeIndex[1] + "] " + "[" + AsText(squeezeIndexDifference, NumberFormat.TWO_DECIMAL_PLACES) + "%] " + "[" + (counter[1]) + "] | " + "[" + accumCounter + "] " + "[" + AsText(historicalDifference[1], NumberFormat.TWO_DECIMAL_PLACES) + "%] ", if squeezeIndex > squeezeIndex[1] and squeezeIndex > 50 and squeezeIndexDifference > 0 then CreateColor(16, 198, 226) else color.LIGHT_ORANGE);

def fixBug = if squeezeIndex >= 0 then counter[1] == counter[1] == 0  else Double.NaN;

#--------------------------------------------------------------------------------------------------


#---------------------------------------------------------------------------------------------------
#
# I changed this Mobius code to show orange during initial squeeze
# and then turns to red if >5 squeeze bars. John Carter believes that a squeeze of 5 is better
# than a squeeze of 2 or 3. He is correct. However, during my initial testing, a squeeze of more
# than 5 is not better. During my testing, a squeeze substantially greater than 20 is worse than a 5.
# Your mileage may vary. Consult your owner's manual for more information. Hands and feet inside the ride
# at  all times :) And because I am a self-taught coder, I messed up Mobius' pretty formatting to reflect
# my ignorance of the craft :)
#
#----------------------------------------------------------------------------------------------------

#AddLabel(!IsNaN(Squeeze), "  >>> Squeeze <<<  ", if IsAscending(Momo)
#then Color.GREEN else if counter[1] >= 5 then Color.RED else CreateColor(16, 198, 226));

def cleanup = if IsNaN(Squeeze) then counter[1] == 0 else 0;


plot zero = if IsNaN(close) or !IsNaN(Squeeze) then Double.NaN else 0;

zero.SetPaintingStrategy(PaintingStrategy.POINTS);
zero.SetLineWeight(5);
zero.SetDefaultColor(Color.GREEN);


Option 3
Code:
declare lower;

script normalizer {
    input data   = close;
    input Min    = -1;
    input Max    = 1;
    input length = 50;

    def hhData   = Highest(data, length);
    def llData   = Lowest(data, length);

    plot resized = (((Max - Min) * (data - llData)) /

                       (hhData - llData)) + Min;
}


### ERGODIC OSCILLATOR ###
input longLength = 25;
input shortLength = 13;
input signalLength = 8;
input averageType = AverageType.EXPONENTIAL;

plot ErgodicOsc = normalizer(TrueStrengthIndex(longLength, shortLength, signalLength, averageType).TSI - TrueStrengthIndex(longLength, shortLength, signalLength, averageType).Signal);

ErgodicOsc.SetPaintingStrategy(PaintingStrategy.LINE);
ErgodicOsc.SetLineWeight(3);
ErgodicOsc.DefineColor("Positive", Color.WHITE); #Color.UPTICK);
ErgodicOsc.DefineColor("Negative", Color.WHITE); #Color.DOWNTICK);
ErgodicOsc.AssignValueColor(if ErgodicOsc >= 0 then ErgodicOsc.Color("Positive") else ErgodicOsc.Color("Negative"));


### SQUEEZE ###
input length = 21; #hint length: Length for average calculation.
input price = close;
input SDmult = 2.0;
input ATRmult = 1.5;
def K = (Highest(high, length) + Lowest(low, length)) / 2 + ExpAverage(close, length);

plot Momo = normalizer(Inertia(price - K / 2, length));
Momo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Momo.SetLineWeight(5);
Momo.AssignValueColor(if Momo > Momo[1] and Momo > 0 then Color.CYAN
else if Momo > 0 and Momo < Momo[1] then Color.BLUE
else if Momo < 0 and Momo < Momo[1] then Color.RED
else Color.YELLOW);

#--------------- [ Metrics From Mobius ] ---------------

def SD = StDev(close, length);
def Avg = Average(close, length);
def ATR = Average(TrueRange(high, close, low), length);
def SDup = normalizer(Avg + (SDmult * SD));
def ATRup = normalizer(Avg + (ATRmult * ATR));

plot Squeeze = if SDup < ATRUp then 0 else Double.NaN;


#------------------------------------------------------------------------------------------
#  David M.(Some Random Alien) 10-6-2021
#  Don't blame Mobius... I made this mess :)
#  Code displays Squeeze Watch Prediction Index.
#  Depending on volume, a score of less then 25 could signal an impeding Squeeze.

def squeezePrediction = ((SDup - ATRup) / (SDup + ATRup) / 2) * 100;
def squeezeIndex = Round(squeezePrediction * 10000, 0);
def squeezeIndexDifference = (squeezeIndex - squeezeIndex[1]) / (squeezeIndex + squeezeIndex[1]) / 2 * 100;
def squeezeProgress = Round((squeezePrediction - squeezePrediction[1]) * 10000, 2);
def squeezeIndexOn = squeezeIndex <= 0;
rec counter = if squeezeIndexOn then counter[1] + 1 else 0;
def deepSqueeze = squeezeIndex <= -20;

rec accumCounter = if squeezeIndex >= 0 then accumCounter[1] + 1 else 0;
rec historicalDifference = if squeezeIndexOn then Lowest(squeezeIndexDifference) else historicalDifference[1];


#---------------------------- [ Plots Some Dots ] -----------------------------

Squeeze.SetPaintingStrategy(PaintingStrategy.POINTS);
Squeeze.SetLineWeight(5);
Squeeze.AssignValueColor( if deepSqueeze then CreateColor(185, 30, 249) else color.RED);
Squeeze.SetDefaultColor(Color.RED);


#------------------------------------------------------------------------------
# Make the SI bar look pretty :)

#AddLabel(yes, " SQUEEZE INDEX: " + squeezeIndex + " [" + squeezeIndex[1] + "] " + "[" + AsText(squeezeIndexDifference, NumberFormat.TWO_DECIMAL_PLACES) + "%] " + "[" + (counter[1]) + "] | " + "[" + accumCounter + "] " + "[" + AsText(historicalDifference[1], NumberFormat.TWO_DECIMAL_PLACES) + "%] ", if squeezeIndex > squeezeIndex[1] and squeezeIndex > 50 and squeezeIndexDifference > 0 then CreateColor(16, 198, 226) else color.LIGHT_ORANGE);

def fixBug = if squeezeIndex >= 0 then counter[1] == counter[1] == 0  else Double.NaN;

#--------------------------------------------------------------------------------------------------


#---------------------------------------------------------------------------------------------------
#
# I changed this Mobius code to show orange during initial squeeze
# and then turns to red if >5 squeeze bars. John Carter believes that a squeeze of 5 is better
# than a squeeze of 2 or 3. He is correct. However, during my initial testing, a squeeze of more
# than 5 is not better. During my testing, a squeeze substantially greater than 20 is worse than a 5.
# Your mileage may vary. Consult your owner's manual for more information. Hands and feet inside the ride
# at  all times :) And because I am a self-taught coder, I messed up Mobius' pretty formatting to reflect
# my ignorance of the craft :)
#
#----------------------------------------------------------------------------------------------------

#AddLabel(!IsNaN(Squeeze), "  >>> Squeeze <<<  ", if IsAscending(Momo)
#then Color.GREEN else if counter[1] >= 5 then Color.RED else CreateColor(16, 198, 226));

def cleanup = if IsNaN(Squeeze) then counter[1] == 0 else 0;


plot zero = if IsNaN(close) or !IsNaN(Squeeze) then Double.NaN else 0;

zero.SetPaintingStrategy(PaintingStrategy.POINTS);
zero.SetLineWeight(5);
zero.SetDefaultColor(Color.GREEN);

Hope this helps...

Good Luck and Good Trading :cool:

Credits: Thanks to Mobius and Some Random Alien for the Squeeze portion of the code...
 
Last edited:
@candlestix : Area 1 highlights the overlaying of the Squeeze indicator by the ErgodicOsc indicator. As a result of using the two default indicators without changing the code you get the scaling issue I mentioned previously. The Scale is in percentages instead of numbers. Also, the Zero Lines are off.

Area 2 shows the proper overlaying of the two indicators where the Scale should and does have values revolving around a common Zero Line. In my opinion, the merging of these two indicators makes the newly combined indicator difficult to read, due to using two histograms for display of the data...

a.png



Below are three options to choose from:

d.png



Option 1: The original merging of the two indicators complete with two histograms and the aforementioned readability issue...

Option 2 : Changes the ErgodicOsc from a histogram to a line with the original coloring intact. Once again, this can be difficult to read in spots...

Option 3: Keeps the ErgodicOsc as a line and changes the coloring to white for contrast, clarity and easy readability...


Below is the respective code for each of the options:

Option 1
Code:
declare lower;

script normalizer {
    input data   = close;
    input Min    = -1;
    input Max    = 1;
    input length = 50;

    def hhData   = Highest(data, length);
    def llData   = Lowest(data, length);

    plot resized = (((Max - Min) * (data - llData)) /

                       (hhData - llData)) + Min;
}


### ERGODIC OSCILLATOR ###
input longLength = 25;
input shortLength = 13;
input signalLength = 8;
input averageType = AverageType.EXPONENTIAL;

plot ErgodicOsc = normalizer(TrueStrengthIndex(longLength, shortLength, signalLength, averageType).TSI - TrueStrengthIndex(longLength, shortLength, signalLength, averageType).Signal);

ErgodicOsc.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
ErgodicOsc.SetLineWeight(3);
ErgodicOsc.DefineColor("Positive", Color.UPTICK);
ErgodicOsc.DefineColor("Negative", Color.DOWNTICK);
ErgodicOsc.AssignValueColor(if ErgodicOsc >= 0 then ErgodicOsc.Color("Positive") else ErgodicOsc.Color("Negative"));


### SQUEEZE ###
input length = 21; #hint length: Length for average calculation.
input price = close;
input SDmult = 2.0;
input ATRmult = 1.5;
def K = (Highest(high, length) + Lowest(low, length)) / 2 + ExpAverage(close, length);

plot Momo = normalizer(Inertia(price - K / 2, length));
Momo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Momo.SetLineWeight(3);
Momo.AssignValueColor(if Momo > Momo[1] and Momo > 0 then Color.CYAN
else if Momo > 0 and Momo < Momo[1] then Color.BLUE
else if Momo < 0 and Momo < Momo[1] then Color.RED
else Color.YELLOW);

#--------------- [ Metrics From Mobius ] ---------------

def SD = StDev(close, length);
def Avg = Average(close, length);
def ATR = Average(TrueRange(high, close, low), length);
def SDup = normalizer(Avg + (SDmult * SD));
def ATRup = normalizer(Avg + (ATRmult * ATR));

plot Squeeze = if SDup < ATRUp then 0 else Double.NaN;


#------------------------------------------------------------------------------------------
#  David M.(Some Random Alien) 10-6-2021
#  Don't blame Mobius... I made this mess :)
#  Code displays Squeeze Watch Prediction Index.
#  Depending on volume, a score of less then 25 could signal an impeding Squeeze.

def squeezePrediction = ((SDup - ATRup) / (SDup + ATRup) / 2) * 100;
def squeezeIndex = Round(squeezePrediction * 10000, 0);
def squeezeIndexDifference = (squeezeIndex - squeezeIndex[1]) / (squeezeIndex + squeezeIndex[1]) / 2 * 100;
def squeezeProgress = Round((squeezePrediction - squeezePrediction[1]) * 10000, 2);
def squeezeIndexOn = squeezeIndex <= 0;
rec counter = if squeezeIndexOn then counter[1] + 1 else 0;
def deepSqueeze = squeezeIndex <= -20;

rec accumCounter = if squeezeIndex >= 0 then accumCounter[1] + 1 else 0;
rec historicalDifference = if squeezeIndexOn then Lowest(squeezeIndexDifference) else historicalDifference[1];


#---------------------------- [ Plots Some Dots ] -----------------------------

Squeeze.SetPaintingStrategy(PaintingStrategy.POINTS);
Squeeze.SetLineWeight(5);
Squeeze.AssignValueColor( if deepSqueeze then CreateColor(185, 30, 249) else color.RED);
Squeeze.SetDefaultColor(Color.RED);


#------------------------------------------------------------------------------
# Make the SI bar look pretty :)

#AddLabel(yes, " SQUEEZE INDEX: " + squeezeIndex + " [" + squeezeIndex[1] + "] " + "[" + AsText(squeezeIndexDifference, NumberFormat.TWO_DECIMAL_PLACES) + "%] " + "[" + (counter[1]) + "] | " + "[" + accumCounter + "] " + "[" + AsText(historicalDifference[1], NumberFormat.TWO_DECIMAL_PLACES) + "%] ", if squeezeIndex > squeezeIndex[1] and squeezeIndex > 50 and squeezeIndexDifference > 0 then CreateColor(16, 198, 226) else color.LIGHT_ORANGE);

def fixBug = if squeezeIndex >= 0 then counter[1] == counter[1] == 0  else Double.NaN;

#--------------------------------------------------------------------------------------------------


#---------------------------------------------------------------------------------------------------
#
# I changed this Mobius code to show orange during initial squeeze
# and then turns to red if >5 squeeze bars. John Carter believes that a squeeze of 5 is better
# than a squeeze of 2 or 3. He is correct. However, during my initial testing, a squeeze of more
# than 5 is not better. During my testing, a squeeze substantially greater than 20 is worse than a 5.
# Your mileage may vary. Consult your owner's manual for more information. Hands and feet inside the ride
# at  all times :) And because I am a self-taught coder, I messed up Mobius' pretty formatting to reflect
# my ignorance of the craft :)
#
#----------------------------------------------------------------------------------------------------

#AddLabel(!IsNaN(Squeeze), "  >>> Squeeze <<<  ", if IsAscending(Momo)
#then Color.GREEN else if counter[1] >= 5 then Color.RED else CreateColor(16, 198, 226));

def cleanup = if IsNaN(Squeeze) then counter[1] == 0 else 0;


plot zero = if IsNaN(close) or !IsNaN(Squeeze) then Double.NaN else 0;

zero.SetPaintingStrategy(PaintingStrategy.POINTS);
zero.SetLineWeight(5);
zero.SetDefaultColor(Color.GREEN);


Option 2
Code:
declare lower;

script normalizer {
    input data   = close;
    input Min    = -1;
    input Max    = 1;
    input length = 50;

    def hhData   = Highest(data, length);
    def llData   = Lowest(data, length);

    plot resized = (((Max - Min) * (data - llData)) /

                       (hhData - llData)) + Min;
}


### ERGODIC OSCILLATOR ###
input longLength = 25;
input shortLength = 13;
input signalLength = 8;
input averageType = AverageType.EXPONENTIAL;

plot ErgodicOsc = normalizer(TrueStrengthIndex(longLength, shortLength, signalLength, averageType).TSI - TrueStrengthIndex(longLength, shortLength, signalLength, averageType).Signal);

ErgodicOsc.SetPaintingStrategy(PaintingStrategy.LINE);
ErgodicOsc.SetLineWeight(3);
ErgodicOsc.DefineColor("Positive", Color.UPTICK);
ErgodicOsc.DefineColor("Negative", Color.DOWNTICK);
ErgodicOsc.AssignValueColor(if ErgodicOsc >= 0 then ErgodicOsc.Color("Positive") else ErgodicOsc.Color("Negative"));


### SQUEEZE ###
input length = 21; #hint length: Length for average calculation.
input price = close;
input SDmult = 2.0;
input ATRmult = 1.5;
def K = (Highest(high, length) + Lowest(low, length)) / 2 + ExpAverage(close, length);

plot Momo = normalizer(Inertia(price - K / 2, length));
Momo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Momo.SetLineWeight(5);
Momo.AssignValueColor(if Momo > Momo[1] and Momo > 0 then Color.CYAN
else if Momo > 0 and Momo < Momo[1] then Color.BLUE
else if Momo < 0 and Momo < Momo[1] then Color.RED
else Color.YELLOW);

#--------------- [ Metrics From Mobius ] ---------------

def SD = StDev(close, length);
def Avg = Average(close, length);
def ATR = Average(TrueRange(high, close, low), length);
def SDup = normalizer(Avg + (SDmult * SD));
def ATRup = normalizer(Avg + (ATRmult * ATR));

plot Squeeze = if SDup < ATRUp then 0 else Double.NaN;


#------------------------------------------------------------------------------------------
#  David M.(Some Random Alien) 10-6-2021
#  Don't blame Mobius... I made this mess :)
#  Code displays Squeeze Watch Prediction Index.
#  Depending on volume, a score of less then 25 could signal an impeding Squeeze.

def squeezePrediction = ((SDup - ATRup) / (SDup + ATRup) / 2) * 100;
def squeezeIndex = Round(squeezePrediction * 10000, 0);
def squeezeIndexDifference = (squeezeIndex - squeezeIndex[1]) / (squeezeIndex + squeezeIndex[1]) / 2 * 100;
def squeezeProgress = Round((squeezePrediction - squeezePrediction[1]) * 10000, 2);
def squeezeIndexOn = squeezeIndex <= 0;
rec counter = if squeezeIndexOn then counter[1] + 1 else 0;
def deepSqueeze = squeezeIndex <= -20;

rec accumCounter = if squeezeIndex >= 0 then accumCounter[1] + 1 else 0;
rec historicalDifference = if squeezeIndexOn then Lowest(squeezeIndexDifference) else historicalDifference[1];


#---------------------------- [ Plots Some Dots ] -----------------------------

Squeeze.SetPaintingStrategy(PaintingStrategy.POINTS);
Squeeze.SetLineWeight(5);
Squeeze.AssignValueColor( if deepSqueeze then CreateColor(185, 30, 249) else color.RED);
Squeeze.SetDefaultColor(Color.RED);


#------------------------------------------------------------------------------
# Make the SI bar look pretty :)

#AddLabel(yes, " SQUEEZE INDEX: " + squeezeIndex + " [" + squeezeIndex[1] + "] " + "[" + AsText(squeezeIndexDifference, NumberFormat.TWO_DECIMAL_PLACES) + "%] " + "[" + (counter[1]) + "] | " + "[" + accumCounter + "] " + "[" + AsText(historicalDifference[1], NumberFormat.TWO_DECIMAL_PLACES) + "%] ", if squeezeIndex > squeezeIndex[1] and squeezeIndex > 50 and squeezeIndexDifference > 0 then CreateColor(16, 198, 226) else color.LIGHT_ORANGE);

def fixBug = if squeezeIndex >= 0 then counter[1] == counter[1] == 0  else Double.NaN;

#--------------------------------------------------------------------------------------------------


#---------------------------------------------------------------------------------------------------
#
# I changed this Mobius code to show orange during initial squeeze
# and then turns to red if >5 squeeze bars. John Carter believes that a squeeze of 5 is better
# than a squeeze of 2 or 3. He is correct. However, during my initial testing, a squeeze of more
# than 5 is not better. During my testing, a squeeze substantially greater than 20 is worse than a 5.
# Your mileage may vary. Consult your owner's manual for more information. Hands and feet inside the ride
# at  all times :) And because I am a self-taught coder, I messed up Mobius' pretty formatting to reflect
# my ignorance of the craft :)
#
#----------------------------------------------------------------------------------------------------

#AddLabel(!IsNaN(Squeeze), "  >>> Squeeze <<<  ", if IsAscending(Momo)
#then Color.GREEN else if counter[1] >= 5 then Color.RED else CreateColor(16, 198, 226));

def cleanup = if IsNaN(Squeeze) then counter[1] == 0 else 0;


plot zero = if IsNaN(close) or !IsNaN(Squeeze) then Double.NaN else 0;

zero.SetPaintingStrategy(PaintingStrategy.POINTS);
zero.SetLineWeight(5);
zero.SetDefaultColor(Color.GREEN);


Option 3
Code:
# filename: MR__EZ_Squeeze_ErgodicOsc_Combo_

declare lower;

script normalizer {
    input data   = close;
    input Min    = -1;
    input Max    = 1;
    input length = 50;

    def hhData   = Highest(data, length);
    def llData   = Lowest(data, length);

    plot resized = (((Max - Min) * (data - llData)) /

                       (hhData - llData)) + Min;
}


### ERGODIC OSCILLATOR ###
input longLength = 25;
input shortLength = 13;
input signalLength = 8;
input averageType = AverageType.EXPONENTIAL;

plot ErgodicOsc = normalizer(TrueStrengthIndex(longLength, shortLength, signalLength, averageType).TSI - TrueStrengthIndex(longLength, shortLength, signalLength, averageType).Signal);

ErgodicOsc.SetPaintingStrategy(PaintingStrategy.LINE);
ErgodicOsc.SetLineWeight(3);
ErgodicOsc.DefineColor("Positive", Color.WHITE); #Color.UPTICK);
ErgodicOsc.DefineColor("Negative", Color.WHITE); #Color.DOWNTICK);
ErgodicOsc.AssignValueColor(if ErgodicOsc >= 0 then ErgodicOsc.Color("Positive") else ErgodicOsc.Color("Negative"));


### SQUEEZE ###
input length = 21; #hint length: Length for average calculation.
input price = close;
input SDmult = 2.0;
input ATRmult = 1.5;
def K = (Highest(high, length) + Lowest(low, length)) / 2 + ExpAverage(close, length);

plot Momo = normalizer(Inertia(price - K / 2, length));
Momo.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Momo.SetLineWeight(5);
Momo.AssignValueColor(if Momo > Momo[1] and Momo > 0 then Color.CYAN
else if Momo > 0 and Momo < Momo[1] then Color.BLUE
else if Momo < 0 and Momo < Momo[1] then Color.RED
else Color.YELLOW);

#--------------- [ Metrics From Mobius ] ---------------

def SD = StDev(close, length);
def Avg = Average(close, length);
def ATR = Average(TrueRange(high, close, low), length);
def SDup = normalizer(Avg + (SDmult * SD));
def ATRup = normalizer(Avg + (ATRmult * ATR));

plot Squeeze = if SDup < ATRUp then 0 else Double.NaN;


#------------------------------------------------------------------------------------------
#  David M.(Some Random Alien) 10-6-2021
#  Don't blame Mobius... I made this mess :)
#  Code displays Squeeze Watch Prediction Index.
#  Depending on volume, a score of less then 25 could signal an impeding Squeeze.

def squeezePrediction = ((SDup - ATRup) / (SDup + ATRup) / 2) * 100;
def squeezeIndex = Round(squeezePrediction * 10000, 0);
def squeezeIndexDifference = (squeezeIndex - squeezeIndex[1]) / (squeezeIndex + squeezeIndex[1]) / 2 * 100;
def squeezeProgress = Round((squeezePrediction - squeezePrediction[1]) * 10000, 2);
def squeezeIndexOn = squeezeIndex <= 0;
rec counter = if squeezeIndexOn then counter[1] + 1 else 0;
def deepSqueeze = squeezeIndex <= -20;

rec accumCounter = if squeezeIndex >= 0 then accumCounter[1] + 1 else 0;
rec historicalDifference = if squeezeIndexOn then Lowest(squeezeIndexDifference) else historicalDifference[1];


#---------------------------- [ Plots Some Dots ] -----------------------------

Squeeze.SetPaintingStrategy(PaintingStrategy.POINTS);
Squeeze.SetLineWeight(5);
Squeeze.AssignValueColor( if deepSqueeze then CreateColor(185, 30, 249) else color.RED);
Squeeze.SetDefaultColor(Color.RED);


#------------------------------------------------------------------------------
# Make the SI bar look pretty :)

#AddLabel(yes, " SQUEEZE INDEX: " + squeezeIndex + " [" + squeezeIndex[1] + "] " + "[" + AsText(squeezeIndexDifference, NumberFormat.TWO_DECIMAL_PLACES) + "%] " + "[" + (counter[1]) + "] | " + "[" + accumCounter + "] " + "[" + AsText(historicalDifference[1], NumberFormat.TWO_DECIMAL_PLACES) + "%] ", if squeezeIndex > squeezeIndex[1] and squeezeIndex > 50 and squeezeIndexDifference > 0 then CreateColor(16, 198, 226) else color.LIGHT_ORANGE);

def fixBug = if squeezeIndex >= 0 then counter[1] == counter[1] == 0  else Double.NaN;

#--------------------------------------------------------------------------------------------------


#---------------------------------------------------------------------------------------------------
#
# I changed this Mobius code to show orange during initial squeeze
# and then turns to red if >5 squeeze bars. John Carter believes that a squeeze of 5 is better
# than a squeeze of 2 or 3. He is correct. However, during my initial testing, a squeeze of more
# than 5 is not better. During my testing, a squeeze substantially greater than 20 is worse than a 5.
# Your mileage may vary. Consult your owner's manual for more information. Hands and feet inside the ride
# at  all times :) And because I am a self-taught coder, I messed up Mobius' pretty formatting to reflect
# my ignorance of the craft :)
#
#----------------------------------------------------------------------------------------------------

#AddLabel(!IsNaN(Squeeze), "  >>> Squeeze <<<  ", if IsAscending(Momo)
#then Color.GREEN else if counter[1] >= 5 then Color.RED else CreateColor(16, 198, 226));

def cleanup = if IsNaN(Squeeze) then counter[1] == 0 else 0;


plot zero = if IsNaN(close) or !IsNaN(Squeeze) then Double.NaN else 0;

zero.SetPaintingStrategy(PaintingStrategy.POINTS);
zero.SetLineWeight(5);
zero.SetDefaultColor(Color.GREEN);

Hope this helps...

Good Luck and Good Trading :cool:

Credits: Thanks to Mobius and Some Random Alien for the Squeeze portion of the code...
Thank you so much. I understand what you are pointing out. Thank you
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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