T3-Filterd 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("T3-Filterd SSL [Loxx]", 
     shorttitle="T3FSSL [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

_ssl(per, clper, hot, org)=>
    varHigh =_iT3(high, per, hot, org)
    varLow = _iT3(low, per, hot, org)
    varClose = _iT3(close, clper, hot, org)
    Hlv = 0.
    Hlv := varClose > varHigh ? 1 : varClose < varLow ? -1 : Hlv[1]
    sslDown = Hlv < 0 ? varHigh : varLow
    sslUp = Hlv < 0 ? varLow : varHigh
    [sslUp, sslDown]
    
sslper = input.int(10, "SSL Period", group = "Basic Settings")
clsper = input.int(1, "Close Period", group = "Basic Settings", minval = 0)

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

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

[sslUp, sslDown] = _ssl(sslper, clsper, t3hot, t3swt)

plot(sslUp, color = greencolor, linewidth = 3)
plot(sslDown, color = redcolor, linewidth = 3)

barcolor(colorbars ? sslUp > sslDown ? greencolor : sslUp < sslDown ? redcolor : color.gray : na)
 
goUp = ta.crossover(sslUp, sslDown) 
goDown = ta.crossover(sslDown, sslUp) 

plotshape(showSigs and goUp, title = "Uptrend", color = color.yellow, textcolor = color.yellow, text = "UP", style = shape.triangleup, location = location.belowbar, size = size.tiny)
plotshape(showSigs and goDown, title = "Downtrend", color = color.fuchsia, textcolor = color.fuchsia, text = "DN", style = shape.triangledown, location = location.abovebar, size = size.tiny)

alertcondition(goUp, title = "Uptrend", message = "Variety-Filterd SSL [Loxx]: Uptrend\nSymbol: {{ticker}}\nPrice: {{close}}")
alertcondition(goDown, title = "Downtrend", message = "Variety-Filterd SSL [Loxx]: Downtrend\nSymbol: {{ticker}}\nPrice: {{close}}")


