LabTrend SSL [Loxx]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © loxx

//@version=5
indicator("LabTrend SSL [Loxx]",
     shorttitle='LTSSL [Loxx]', 
     overlay = true, 
     timeframe="", 
     timeframe_gaps = true)
     
greencolor = #2DD204
redcolor = #D2042D 

_iT3(src, per, hot, org)=>
    a = hot
    _c1 = -a * a * a
    _c2 = 3 * a * a + 3 * a * a * a
    _c3 = -6 * a * a - 3 * a - 3 * a * a * a
    _c4 = 1 + 3 * a + a * a * a + 3 * a * a
    
    alpha = 0.
    if (org)
        alpha := 2.0 / (1.0 + per)
    else
        alpha := 2.0 / (2.0 + (per - 1.0) / 2.0)

    _t30 = src, _t31 = src
    _t32 = src, _t33 = src
    _t34 = src, _t35 = src
    
    _t30 := nz(_t30[1]) + alpha * (src -  nz(_t30[1]))
    _t31 := nz(_t31[1]) + alpha * (_t30 - nz(_t31[1]))
    _t32 := nz(_t32[1]) + alpha * (_t31 - nz(_t32[1]))
    _t33 := nz(_t33[1]) + alpha * (_t32 - nz(_t33[1]))
    _t34 := nz(_t34[1]) + alpha * (_t33 - nz(_t34[1]))
    _t35 := nz(_t35[1]) + alpha * (_t34 - nz(_t35[1]))
    out =
         _c1 * _t35 + _c2 * _t34 +
         _c3 * _t33 +  _c4 * _t32
    out
    
per = input.int(14, "Hilo Period", group = "Basic Settings")
Risk = input.int(3, "Risk", group = "Basic Settings")
atrper = input.int(10, "ATR Period", group = "Basic Settings")

sslper = input.int(10, "SSL Period", group = "SSL Settings")
t3hot = input.float(0.7, "T3 Factor", step = 0.01, maxval = 1, minval = 0, group = "SSL Settings")
t3swt = input.bool(false, "T3 Original?", group = "SSL Settings")

colorbars = input.bool(true, "Color bars?", group = "UI Options")
showsignals = input.bool(true, "Show signals?", group = "UI Options")

smin = 0., smax = 0.
smin := ta.lowest(low, per) 
smax := ta.highest(high, per) 

bsmax = smax - (smax - smin) * (33.0 - Risk) / 100.0
bsmin = smin + (smax - smin) * (33.0 - Risk) / 100.0

trend = 0., trens = 0.
trens := nz(trens[1])

varHigh =_iT3(high, sslper, t3hot, t3swt)
varLow = _iT3(low, sslper, t3hot, t3swt)

if (close > bsmax)
    trend := 1
    trens := 1
if (close < bsmin)
    trend := -1
    trens := -1

barUp = 0., barDn = 0., arrUp = 0., arrDn = 0.
if (trend == 1) 
    barUp := varHigh
    barDn := varLow
if (trend == -1) 
    barUp := varLow
    barDn := varHigh

atr = ta.atr(atrper)
if (trens != nz(trens[1])) 
    if (trens == 1) 
        arrUp := 1
    if (trens == -1) 
        arrDn := 1
        
plotshape(showsignals ? arrUp : na, title = "Long", color = color.yellow, textcolor = color.yellow, text = "L", style = shape.triangleup, location = location.belowbar, size = size.tiny)
plotshape(showsignals ? arrDn : na, title = "Short", color = color.fuchsia, textcolor = color.fuchsia, text = "S", style = shape.triangledown, location = location.abovebar, size = size.tiny)

colorout = trend == 1 ? greencolor : trend == -1 ? redcolor: color.white

plot(barUp ? barUp : na, color = greencolor, linewidth = 3)
plot(barDn ? barDn : na, color = redcolor, linewidth = 3)

barcolor(colorbars ? colorout : na)

alertcondition(arrUp, title="Long", message="LabTrend SSL [Loxx]: Long\nSymbol: {{ticker}}\nPrice: {{close}}")
alertcondition(arrDn, title="Short", message="LabTrend SSL [Loxx]: Short\nSymbol: {{ticker}}\nPrice: {{close}}")






