Squeeze Index [LuxAlgo] For ThinkOrSwim

hazmat8039

New member
The Squeeze Index aims to measure the action of price being squeezed, and is expressed as a percentage, with higher values suggesting prices are subject to a higher degree of compression.

Settings
  • Convergence Factor: Convergence factor of exponential envelopes.
  • Length: Period of the indicator.
  • Src: Source input of the indicator.
Usage
Prices being squeezed refer to the action of price being compressed within a tightening area. Prices in a tight area logically indicate a period of stationarity, price breaking out of this area will generally indicate the trader whether to buy or sell depending on the breakout direction.

OzQHbCd.png

The convergence factor and length settings both play an important role in the returned indicator values. A convergence factor greater than the period value will detect more squeezed prices area, while a period greater than the convergence will return fewer detected squeezed areas.

We recommend using a convergence factor equal to the period setting or a convergence factor twice as high.

The above chart makes use of a convergence factor of 100 and a period of 10.

Due to the calculation method, it is possible to see retracements being interpreted as price squeezing. This effect can be emphasized with higher convergence factor values.

Details
In order to measure the effect of price being squeezed in a tighter area we refer to damping, where the oscillations' amplitude of a system decrease over time. If the envelopes of a damped system can be estimated, then getting the difference between the upper and lower extremity of these envelopes would return a decreasing series of values.

This approach is used here. First the difference between the exponential envelopes of extremities is obtained, the logarithm of this difference if obtained due to the extremities converging exponentially toward their input.

We then use the correlation oscillator to get a scaled measurement.



Im trying to convert this,
https://www.tradingview.com/script/Et6YD2t4-Squeeze-Index-LuxAlgo/
 
Last edited by a moderator:

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

Im trying to convert this,
https://www.tradingview.com/script/Et6YD2t4-Squeeze-Index-LuxAlgo/
but I am getting stuck, I know there are other squeeze detectors out there but this one is simple and I can adjust the length and convergence factor with inputs. if someone could help that would be great.

// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo

//@version=5
indicator("Squeeze Index [LuxAlgo]", "Squeeze Index [LuxAlgo]")
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
conv = input(50, 'Convergence Factor')

length = input(20)

src = input(close)

//Style
col_0 = input(#ffeb3b, 'Gradient'
, inline = 'inline0'
, group = 'Style')

col_1 = input(#ff5d00, ''
, inline = 'inline0'
, group = 'Style')

col_2 = input(#ff1100, ''
, inline = 'inline0'
, group = 'Style')

//-----------------------------------------------------------------------------}
//Squeeze index
//-----------------------------------------------------------------------------{
var max = 0.
var min = 0.

max := nz(math.max(src, max - (max - src) / conv), src)
min := nz(math.min(src, min + (src - min) / conv), src)
diff = math.log(max - min)

psi = -50 * ta.correlation(diff, bar_index, length) + 50

//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
css1 = color.from_gradient(psi, 0, 80, col_0, col_1)
css2 = color.from_gradient(psi, 80, 100, css1, col_2)

plot_0 = plot(psi, 'PSI', psi > 80 ? na : css2)
plot(psi, 'Dots', psi > 80 ? css2 : na, style = plot.style_cross)

plot_1 = plot(80, display = display.none, editable = false)

fill(plot_0, plot_1, psi < 80 ? na : color.new(#ff1100, 80))

hline(80)

//-----------------------------------------------------------------------------}
YUBLSCK.png

find below
CODE:
CSS:
#// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
#// © LuxAlgo
#indicator("Squeeze Index [LUX]", "SI [LUX]")
# Converted by Sam4Cok@Samer800    - 04/2023
declare lower;

input conv   = 50;# 'Convergence Factor')
input length = 20;
input threshold = 80;
input src = close;

################
def na = Double.NaN;
def bar =  AbsValue(CompoundValue(1, BarNumber(), 1));

script correlationTS {
    input data1 = close;
    input data2 = close;
    input length = 12;
    plot CorrelationTS = Covariance(data1, data2, length) / ( StDev(data1, length) * StDev(data2, length) );
}

#//-----------------------------------------------------------------------------}
#//Squeeze index
#//-----------------------------------------------------------------------------{
def max;
def min;

max = Max(src, if(max[1]==0,src, max[1]) - (if(max[1]==0,src, max[1]) - src) / conv);
min = Min(src, if(min[1]==0,src[1], min[1]) + (src - if(min[1]==0,src[1], min[1])) / conv);

def diff = Log(max - min);

def psi = -50 * correlationTS(diff, bar, length) + 50;

#//-----------------------------------------------------------------------------}
#//Plots
#//-----------------------------------------------------------------------------{
plot psiLine = psi;#if bar <= length then na else psi;
psiLine.SetLineWeight(2);
psiLine.AssignValueColor(CreateColor(255, 255 - psi * 2.55, 0));
plot psiUpper = if psi < threshold or bar <= length then na else psi;
psiUpper.SetDefaultColor(Color.LIGHT_RED);
psiUpper.SetStyle(Curve.POINTS);
psiUpper.SetLineWeight(2);

plot line80 = if isNaN(close) then na else threshold;
line80.SetDefaultColor(Color.GRAY);
line80.SetStyle(Curve.MEDIUM_DASH);

AddCloud(psiUpper,  line80,  Color.DARK_RED);#psi < 80 ? na : color.new(#ff1100, 80))

input lowerThreshold  = 20;
plot psiLower = if psi < lowerThreshold  then psi else na;
psiLower.SetDefaultColor(Color.LIGHT_green);
psiLower.SetStyle(Curve.POINTS);
psiLower.SetLineWeight(2);

plot line20 = if isNaN(close) then na else lowerThreshold;
line20.SetDefaultColor(Color.GRAY);
line20.SetStyle(Curve.MEDIUM_DASH);

AddCloud(psilower,  line20,  Color.DARK_green, color.dark_green);

# End Of Code
 
Last edited by a moderator:
View attachment 18425
find below
CODE:
CSS:
#// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
#// © LuxAlgo
#indicator("Squeeze Index [LUX]", "SI [LUX]")
# Converted by Sam4Cok@Samer800    - 04/2023
declare lower;

input conv   = 50;# 'Convergence Factor')
input length = 20;
input threshold = 80;
input src = close;

################
def na = Double.NaN;
def bar =  AbsValue(CompoundValue(1, BarNumber(), 1));

script correlationTS {
    input data1 = close;
    input data2 = close;
    input length = 12;
    plot CorrelationTS = Covariance(data1, data2, length) / ( StDev(data1, length) * StDev(data2, length) );
}

#//-----------------------------------------------------------------------------}
#//Squeeze index
#//-----------------------------------------------------------------------------{
def max;
def min;

max = Max(src, if(max[1]==0,src, max[1]) - (if(max[1]==0,src, max[1]) - src) / conv);
min = Min(src, if(min[1]==0,src[1], min[1]) + (src - if(min[1]==0,src[1], min[1])) / conv);

def diff = Log(max - min);

def psi = -50 * correlationTS(diff, bar, length) + 50;

#//-----------------------------------------------------------------------------}
#//Plots
#//-----------------------------------------------------------------------------{
plot psiLine = psi;#if bar <= length then na else psi;
psiLine.SetLineWeight(2);
psiLine.AssignValueColor(CreateColor(255, 255 - psi * 2.55, 0));
plot psiUpper = if psi < threshold or bar <= length then na else psi;
psiUpper.SetDefaultColor(Color.LIGHT_RED);
psiUpper.SetStyle(Curve.POINTS);
psiUpper.SetLineWeight(2);

plot line80 = if isNaN(close) then na else threshold;
line80.SetDefaultColor(Color.GRAY);
line80.SetStyle(Curve.MEDIUM_DASH);

AddCloud(psiUpper,  line80,  Color.DARK_RED);#psi < 80 ? na : color.new(#ff1100, 80))

# End Of Code
#samer800 can you add a threshold gray dash at 20, a Light Green cloud and curve.points when line crosses 20 threshold?
 
#samer800 can you add a threshold gray dash at 20, a Light Green cloud and curve.points when line crosses 20 threshold?
Here ya go. Add the following code to the bottom of your study:
Ruby:
input lowerThreshold  = 20;
plot psiLower = if psi < lowerThreshold  then psi else na;
psiLower.SetDefaultColor(Color.LIGHT_green);
psiLower.SetStyle(Curve.POINTS);
psiLower.SetLineWeight(2);

plot line20 = if isNaN(close) then na else lowerThreshold;
line20.SetDefaultColor(Color.GRAY);
line20.SetStyle(Curve.MEDIUM_DASH);

AddCloud(psilower,  line20,  Color.DARK_green, color.dark_green);
CLAw8CD.png
 
Last edited by a moderator:
I'm getting an error with the additional code at the bottom did I miss something ?
 
Last edited by a moderator:
I'm getting an error with the additional code at the bottom did I miss something ?

Good Catch!

1. the script snippet has been fixed in the post above, you can re-cut and paste.
2. the script snippet has been added to @samer800 original script, you can just reload the entire indicator
3. the script was added to the shared chart link: http://tos.mx/!gabHbHwQ Click here for --> Easiest way to load shared links If you would like to add it that way.
rJXJnfm.png


Thanks for the heads up!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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