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: