LowLag Channel Stoch
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © capam

//@version=5
indicator("LowLag Channel Stoch", overlay=true)
src = close
length = input.int(10,'emalength')
lengthATR = input.int(5,'ATRlength')
lengthStoch = input.int(14,'stochlength')
smoothK = input.int(5,'smoothK')
gain = input.float(1.0,'gain')
stochlimit = input.float(0.8,'stochlimit',maxval = 1.0)
hullEMA(src,len) =>
    out = ta.ema(2*ta.ema(src,len/2) - ta.ema(src,len),math.round(math.sqrt(len)))

hema = hullEMA(src,length)
ATRange = hullEMA(ta.tr(true),lengthATR)
yup = hema + ATRange
ydn = hema - ATRange
// stochastic
stoch1 = gain * (close - ta.lowest(low, lengthStoch)) / (ta.highest(high, lengthStoch) - ta.lowest(low, lengthStoch))
k = hullEMA(stoch1, smoothK)
hemacol = hema > hema[1] ? color.green : color.red
sellflag = hemacol==color.red and (ta.crossunder(k,0.8*gain) or ta.crossunder(k[1],stochlimit*gain) or ta.crossunder(k[2],0.8*gain))
buyflag = hemacol==color.green and (ta.crossover(k,0.2*gain) or ta.crossover(k[1],(1-stochlimit)*gain) or ta.crossover(k[2],0.2*gain))
plot(hema, color = hemacol,linewidth = 2)
// plot(yup, linewidth = 2)
// plot(ydn, linewidth = 2)
ytr = hullEMA(src*1.005,400)
plot(ytr+k, color=color.black, linewidth = 1)
plot(ytr+0.8*gain , linewidth = 1)
plot(ytr+0.2*gain, linewidth = 1)
plotshape(sellflag, location.abovebar, style=shape.labeldown, color=color.new(color.red,10) , size=size.small)
plotshape(buyflag, location.belowbar, style=shape.labelup, color=color.new(color.green,10) , size=size.small)
