Expected Liquidity Range for ThinkOrSwim

samer800

Conversion Expert
VIP
Lifetime
QpOyBax.png

Creator Message:
Simple but effective script that displays Liquidity Premium/ Discount areas in an adaptive way based on key Fibonacci levels.
You can increase or decrease the 'Period' value in the Settings to adjust the gap between the lines as you see fit.
By default the value is '46' which should suit most markets.

CODE:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © RickSimpson
#indicator('Expected Liquidity', 'Expected Liquidity Range', true, max_lines_count=500, max_labels_count=500)
# Converted and mod by Sam4Cok@Samer800 - 01/2023
#//Inputs
input period = 46;       # 'Period' minval=15, maxval=60
input extendLine =  yes; # 'Lines Extension'
input fibLevel1 = 0.236;
input fibLevel2 = 0.382;
input fibLevel3 = 0.618;
input fibLevel4 = 0.764;

def na = Double.NaN;
script nz {
    input data  = close;
    input repl  = 0;
    def ret_val = if !IsNaN(data) then data else repl;
    plot return = ret_val;
}

def i_period = if period<15 then 15 else if period>60 then 60 else period;
def Extend = if extendLine then 0 else isNaN(close);
#//Constants Variables Declaration
def highbar;
def highfractal;
def lowfractal;
def closefractal;

#//Lines Style String Function
#//Pivots Definition

def hb   = Highest(high, i_period);
def lb   = Lowest(low,   i_period);
def dist = hb - lb;

#//Premium Fibonacci Levels Calculation

def hf  = hb - dist * fibLevel1;
def chf = hb - dist * fibLevel2;

#//Discount Fibonacci Levels Calculation

def clf = hb - dist * fibLevel3;
def lf  = hb - dist * fibLevel4;

#//High/Low Fractals Scalling

def pfractal            = high  >  hb[1];
def dfractal            = low   <  lb[1];
def premiumexpectstart  = hb[3] == hb[2] and hb[2] == hb[1] and pfractal;
def discountexpectstart = lb[3] == lb[2] and lb[2] == lb[1] and dfractal;

#//Liquidity Range Calculation

def highexpect = premiumexpectstart  or high[1] == hb;
def lowexpect = discountexpectstart or low[1]  == lb;
highbar       = if highexpect then yes else if lowexpect then no else nz(highbar[1], yes);
def barexp  = if (close > hf) then barexp[1] + 1 else 0;
def barexpin = barexp == 1;
def barexpot = if (close < hf) then barexpot[1] + 1 else 0;
def barexpout = barexpot == 1;
highfractal   = if barexpin then yes else if barexpout then no else nz(highfractal[1], yes);
def fractexp = if (close < lf) then fractexp[1] + 1 else 0;
def fractexpin = fractexp == 1;
def fractexpot = if (close > lf) then fractexpot[1] + 1 else 0;
def fractexpout = fractexpot == 1;
lowfractal    = if fractexpin then yes else if fractexpout then no else nz(lowfractal[1], yes);
closefractal  = if !highfractal and !lowfractal then yes else no;

#//Drawing Calculation
def isintraday = GetAggregationPeriod() < AggregationPeriod.DAY;
def bar = IsNaN(BarNumber());
def isrealtime =  IsNaN(close[-1]) and !IsNaN(close);
def stateislast = if isrealtime and isintraday then !IsNaN(close[1]) else isrealtime;
def hbdtrue     = stateislast and highfractal;
def lbdtrue     = stateislast and lowfractal;
def chfdtrue    = stateislast and closefractal and highbar;
def clfdtrue    = stateislast and closefractal and !highbar;

#/Expected Liquidity Range Conditions

def hbexpect;#  = hb
hbexpect = if hbdtrue then hb else if lbdtrue then lf else if chfdtrue then hf  else if clfdtrue then chf else na;
def lbexpect;#  = lb
lbexpect = if hbdtrue then hf else if lbdtrue then lb else if chfdtrue then clf else if clfdtrue then lf else na;

#---Plotting
def R_extendout = if !IsNaN(hbexpect) then hbexpect else nz(R_extendout[1],hb);
def R_extendin  = if !IsNaN(lbexpect) then lbexpect else nz(R_extendin[1],lb);

plot premium  = if R_extendout == 0 or Extend then na else R_extendout;
premium.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
premium.SetDefaultColor(Color.RED);
plot discount =  if R_extendin == 0 or Extend then na else R_extendin;
discount.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
discount.SetDefaultColor(Color.GREEN);

def mid = (premium + discount) / 2;

plot midLine = mid;
midLine.SetStyle(Curve.SHORT_DASH);
midLine.SetDefaultColor(Color.GRAY);

AddCloud(premium,  discount,  Color.DARK_GRAY);


#---- END CODE ---
 
Last edited by a moderator:

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

@samer800 how do we use this indicator? thank you so much
This uses Fibonacci Levels
input fibLevel1 = 0.236;
input fibLevel2 = 0.382;
input fibLevel3 = 0.618;
input fibLevel4 = 0.764;

You would apply it in the same manner as you apply your other Fibonacci Indicators.

Providing a deep dive into what is and how to use Fibonacci indicators is beyond the scope of this thread. However, it is well worth the effort of studying the intricacies of the fascinating Fibs
 
Last edited:
This uses Fibonacci Levels
input fibLevel1 = 0.236;
input fibLevel2 = 0.382;
input fibLevel3 = 0.618;
input fibLevel4 = 0.764;

You would apply it in the same manner as you apply your other Fibonacci Indicators.

Providing a deep dive into what is and how to use Fibonacci indicators is beyond the scope of this thread. However, it is well worth the effort of studying the intricacies of the fascinating Fibs
Thank you, yes I am well versed in the Fibs no worries.
 
QpOyBax.png

Creator Message:
Simple but effective script that displays Liquidity Premium/ Discount areas in an adaptive way based on key Fibonacci levels.
You can increase or decrease the 'Period' value in the Settings to adjust the gap between the lines as you see fit.
By default the value is '46' which should suit most markets.

CODE:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © RickSimpson
#indicator('Expected Liquidity', 'Expected Liquidity Range', true, max_lines_count=500, max_labels_count=500)
# Converted and mod by Sam4Cok@Samer800 - 01/2023
#//Inputs
input period = 46;       # 'Period' minval=15, maxval=60
input extendLine =  yes; # 'Lines Extension'
input fibLevel1 = 0.236;
input fibLevel2 = 0.382;
input fibLevel3 = 0.618;
input fibLevel4 = 0.764;

def na = Double.NaN;
script nz {
    input data  = close;
    input repl  = 0;
    def ret_val = if !IsNaN(data) then data else repl;
    plot return = ret_val;
}

def i_period = if period<15 then 15 else if period>60 then 60 else period;
def Extend = if extendLine then 0 else isNaN(close);
#//Constants Variables Declaration
def highbar;
def highfractal;
def lowfractal;
def closefractal;

#//Lines Style String Function
#//Pivots Definition

def hb   = Highest(high, i_period);
def lb   = Lowest(low,   i_period);
def dist = hb - lb;

#//Premium Fibonacci Levels Calculation

def hf  = hb - dist * fibLevel1;
def chf = hb - dist * fibLevel2;

#//Discount Fibonacci Levels Calculation

def clf = hb - dist * fibLevel3;
def lf  = hb - dist * fibLevel4;

#//High/Low Fractals Scalling

def pfractal            = high  >  hb[1];
def dfractal            = low   <  lb[1];
def premiumexpectstart  = hb[3] == hb[2] and hb[2] == hb[1] and pfractal;
def discountexpectstart = lb[3] == lb[2] and lb[2] == lb[1] and dfractal;

#//Liquidity Range Calculation

def highexpect = premiumexpectstart  or high[1] == hb;
def lowexpect = discountexpectstart or low[1]  == lb;
highbar       = if highexpect then yes else if lowexpect then no else nz(highbar[1], yes);
def barexp  = if (close > hf) then barexp[1] + 1 else 0;
def barexpin = barexp == 1;
def barexpot = if (close < hf) then barexpot[1] + 1 else 0;
def barexpout = barexpot == 1;
highfractal   = if barexpin then yes else if barexpout then no else nz(highfractal[1], yes);
def fractexp = if (close < lf) then fractexp[1] + 1 else 0;
def fractexpin = fractexp == 1;
def fractexpot = if (close > lf) then fractexpot[1] + 1 else 0;
def fractexpout = fractexpot == 1;
lowfractal    = if fractexpin then yes else if fractexpout then no else nz(lowfractal[1], yes);
closefractal  = if !highfractal and !lowfractal then yes else no;

#//Drawing Calculation
def isintraday = GetAggregationPeriod() < AggregationPeriod.DAY;
def bar = IsNaN(BarNumber());
def isrealtime =  IsNaN(close[-1]) and !IsNaN(close);
def stateislast = if isrealtime and isintraday then !IsNaN(close[1]) else isrealtime;
def hbdtrue     = stateislast and highfractal;
def lbdtrue     = stateislast and lowfractal;
def chfdtrue    = stateislast and closefractal and highbar;
def clfdtrue    = stateislast and closefractal and !highbar;

#/Expected Liquidity Range Conditions

def hbexpect;#  = hb
hbexpect = if hbdtrue then hb else if lbdtrue then lf else if chfdtrue then hf  else if clfdtrue then chf else na;
def lbexpect;#  = lb
lbexpect = if hbdtrue then hf else if lbdtrue then lb else if chfdtrue then clf else if clfdtrue then lf else na;

#---Plotting
def R_extendout = if !IsNaN(hbexpect) then hbexpect else nz(R_extendout[1],hb);
def R_extendin  = if !IsNaN(lbexpect) then lbexpect else nz(R_extendin[1],lb);

plot premium  = if R_extendout == 0 or Extend then na else R_extendout;
premium.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
premium.SetDefaultColor(Color.RED);
plot discount =  if R_extendin == 0 or Extend then na else R_extendin;
discount.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
discount.SetDefaultColor(Color.GREEN);

def mid = (premium + discount) / 2;

plot midLine = mid;
midLine.SetStyle(Curve.SHORT_DASH);
midLine.SetDefaultColor(Color.GRAY);

AddCloud(premium,  discount,  Color.DARK_GRAY);


#---- END CODE ---
Would this work on index...spx,es, mes, nq, mnq with " 46" value?.
 
Is there way to make this for the Whole days entire range from 9:30-4:15 for futures? Or is there just a period I need to set it to. I'm just looking for simplistic indicator like this that shows the days range and price is either above 50% in premium of the entire session range or below 50% of the sessions range and its in discount. Can anyone help with this, very appreciated.

Steve
 
View attachment 17151
Creator Message:
Simple but effective script that displays Liquidity Premium/ Discount areas in an adaptive way based on key Fibonacci levels.
You can increase or decrease the 'Period' value in the Settings to adjust the gap between the lines as you see fit.
By default the value is '46' which should suit most markets.

CODE:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © RickSimpson
#indicator('Expected Liquidity', 'Expected Liquidity Range', true, max_lines_count=500, max_labels_count=500)
# Converted and mod by Sam4Cok@Samer800 - 01/2023
#//Inputs
input period = 46;       # 'Period' minval=15, maxval=60
input extendLine =  yes; # 'Lines Extension'
input fibLevel1 = 0.236;
input fibLevel2 = 0.382;
input fibLevel3 = 0.618;
input fibLevel4 = 0.764;

def na = Double.NaN;
script nz {
    input data  = close;
    input repl  = 0;
    def ret_val = if !IsNaN(data) then data else repl;
    plot return = ret_val;
}

def i_period = if period<15 then 15 else if period>60 then 60 else period;
def Extend = if extendLine then 0 else isNaN(close);
#//Constants Variables Declaration
def highbar;
def highfractal;
def lowfractal;
def closefractal;

#//Lines Style String Function
#//Pivots Definition

def hb   = Highest(high, i_period);
def lb   = Lowest(low,   i_period);
def dist = hb - lb;

#//Premium Fibonacci Levels Calculation

def hf  = hb - dist * fibLevel1;
def chf = hb - dist * fibLevel2;

#//Discount Fibonacci Levels Calculation

def clf = hb - dist * fibLevel3;
def lf  = hb - dist * fibLevel4;

#//High/Low Fractals Scalling

def pfractal            = high  >  hb[1];
def dfractal            = low   <  lb[1];
def premiumexpectstart  = hb[3] == hb[2] and hb[2] == hb[1] and pfractal;
def discountexpectstart = lb[3] == lb[2] and lb[2] == lb[1] and dfractal;

#//Liquidity Range Calculation

def highexpect = premiumexpectstart  or high[1] == hb;
def lowexpect = discountexpectstart or low[1]  == lb;
highbar       = if highexpect then yes else if lowexpect then no else nz(highbar[1], yes);
def barexp  = if (close > hf) then barexp[1] + 1 else 0;
def barexpin = barexp == 1;
def barexpot = if (close < hf) then barexpot[1] + 1 else 0;
def barexpout = barexpot == 1;
highfractal   = if barexpin then yes else if barexpout then no else nz(highfractal[1], yes);
def fractexp = if (close < lf) then fractexp[1] + 1 else 0;
def fractexpin = fractexp == 1;
def fractexpot = if (close > lf) then fractexpot[1] + 1 else 0;
def fractexpout = fractexpot == 1;
lowfractal    = if fractexpin then yes else if fractexpout then no else nz(lowfractal[1], yes);
closefractal  = if !highfractal and !lowfractal then yes else no;

#//Drawing Calculation
def isintraday = GetAggregationPeriod() < AggregationPeriod.DAY;
def bar = IsNaN(BarNumber());
def isrealtime =  IsNaN(close[-1]) and !IsNaN(close);
def stateislast = if isrealtime and isintraday then !IsNaN(close[1]) else isrealtime;
def hbdtrue     = stateislast and highfractal;
def lbdtrue     = stateislast and lowfractal;
def chfdtrue    = stateislast and closefractal and highbar;
def clfdtrue    = stateislast and closefractal and !highbar;

#/Expected Liquidity Range Conditions

def hbexpect;#  = hb
hbexpect = if hbdtrue then hb else if lbdtrue then lf else if chfdtrue then hf  else if clfdtrue then chf else na;
def lbexpect;#  = lb
lbexpect = if hbdtrue then hf else if lbdtrue then lb else if chfdtrue then clf else if clfdtrue then lf else na;

#---Plotting
def R_extendout = if !IsNaN(hbexpect) then hbexpect else nz(R_extendout[1],hb);
def R_extendin  = if !IsNaN(lbexpect) then lbexpect else nz(R_extendin[1],lb);

plot premium  = if R_extendout == 0 or Extend then na else R_extendout;
premium.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
premium.SetDefaultColor(Color.RED);
plot discount =  if R_extendin == 0 or Extend then na else R_extendin;
discount.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
discount.SetDefaultColor(Color.GREEN);

def mid = (premium + discount) / 2;

plot midLine = mid;
midLine.SetStyle(Curve.SHORT_DASH);
midLine.SetDefaultColor(Color.GRAY);

AddCloud(premium,  discount,  Color.DARK_GRAY);


#---- END CODE ---

Anyone able to help with drawing out fib levels automatically as follows for top indicator:

****1 year chart with 1 day.
1) Fib levels with extensions from the center of the line (midline) to top
2) fib levels with extension center of the line( midline) to bottom.

I would like these levels to show up on 1min chart.

Thank you.
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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