Hui-Heubel Liquidity Ratio
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © potato_hedge
//@version=5
indicator("LHH",precision=4)

length = input.int(title="Lookback Window", defval=10) 
sma = input.int(title="SMA",defval=20)
sma2 = input.int(title="SMA2",defval=50)

// implementation of volume based liquidity metric https://www.imf.org/external/pubs/ft/wp/2002/wp02232.pdf 
lhh_function(source,length) =>
    pmax = ta.highest(source,length)
    pmin = ta.lowest(source,length)
    tdv = (high+low+close/3) * volume
    dv = math.sum(tdv,length)
    lhhsma = ta.sma(source,length)
    sa = ta.sma(volume,length)
    lhh = (((pmax - pmin)/pmin) / (dv/(sa*lhhsma)))*100

lhh = lhh_function(close,length)
lsma1 = ta.sma(lhh,sma)
lsma2 = ta.sma(lhh,sma2)
p0 = plot(lhh,color=color.white,linewidth=2)
p1 = plot(lsma1,color=lhh>lsma1?color.new(color.green,20):color.new(color.yellow,20))
p2 = plot(lsma2,color=lsma1>lsma2?color.new(color.yellow,20):color.new(color.red,20))
fill(p0,p1,color=lhh>lsma1?color.new(color.green,90):color.new(color.yellow,90))
fill(p1,p2,color=lsma1>lsma2?color.new(color.yellow,90):color.new(color.red,90))