Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © RickSimpson
- //@version=5
- indicator('Expected Liquidity', 'Expected Liquidity', true, max_lines_count=500, max_labels_count=500)
- //Inputs
- i_period = input.int(46, 'Period', minval=15, maxval=60, group='Expected Liquidity Settings')
- //Constants Variables Declaration
- highbar = true
- highfractal = true
- lowfractal = true
- closefractal = true
- //Pivots Definition
- hb = ta.highest(high, i_period)
- lb = ta.lowest(low, i_period)
- dist = hb - lb
- //Fibonacci Levels Calculation
- hf = hb - dist * 0.236
- chf = hb - dist * 0.382
- clf = hb - dist * 0.618
- lf = hb - dist * 0.764
- //Premium/Discount Type Definition
- pfractal = high > hb[1]
- dfractal = low < lb[1]
- //Liquidity Levels Calculation
- premiumexpectstart = hb[3] == hb[2] and hb[2] == hb[1] and pfractal
- discountexpectstart = lb[3] == lb[2] and lb[2] == lb[1] and dfractal
- //Liquidity Range Calculation
- highexpect = premiumexpectstart or high[1] == hb
- lowexpect = discountexpectstart or low[1] == lb
- highbar := highexpect ? true : lowexpect ? false : highbar[1]
- barexpin = ta.crossover(close, hf)
- barexpout = ta.crossunder(close, hf)
- highfractal := barexpin ? true : barexpout ? false : highfractal[1]
- fractexpin = ta.crossunder(close, lf)
- fractexpout = ta.crossover(close, lf)
- lowfractal := fractexpin ? true : fractexpout ? false : lowfractal[1]
- closefractal := not highfractal and not lowfractal ? true : false
- //Drawing Calculation
- stateislast = barstate.islast
- stateislast := barstate.isrealtime and timeframe.isintraday ? not barstate.isconfirmed : barstate.islast
- hbdtrue = stateislast and highfractal
- lbdtrue = stateislast and lowfractal
- chfdtrue = stateislast and closefractal and highbar
- clfdtrue = stateislast and closefractal and not highbar
- //Conditions
- hbexpect = hb
- hbexpect := hbdtrue ? hb : lbdtrue ? lf : chfdtrue ? hf : clfdtrue ? chf : na
- lbexpect = lb
- lbexpect := hbdtrue ? hf : lbdtrue ? lb : chfdtrue ? clf : clfdtrue ? lf : na
- //Plotting
- plot(hbexpect, 'Premium Liquidity Level', color.red, linewidth=3, offset=3)
- plot(lbexpect, 'Discount Liquidity Level', color.green, linewidth=3, offset=3)
- //Alerts
- if ta.cross(close, hbexpect)
- alert('Premium Liquidity Break! • ' + str.tostring(math.round_to_mintick(high)), alert.freq_once_per_bar)
- if ta.cross(close, lbexpect)
- alert('Discount Liquidity Break! • ' + str.tostring(math.round_to_mintick(low)), alert.freq_once_per_bar)
Advertisement
Add Comment
Please, Sign In to add comment