Multi TF Trend Indicator
// This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © andrew173139

//@version=5
indicator("Multi TF Trend Indicator", shorttitle="MTFT", overlay=true)

_pullData(src, rs, rep) =>
    out = request.security(syminfo.tickerid, rs, src[rep ? 0 : barstate.isrealtime ? 1 : 0], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)[rep ? 0 : barstate.isrealtime ? 0 : 1]
    out
    
src = input.source(close, "Data source", group = "Multi TF")
tf = input.timeframe("5", "Multi TF resolution", group = "Multi TF")

rep = input.bool(false, "Allow repainting", group = "UI")
showTrendLine = input.bool(true, "Highlight trend line", group = "UI")
showTrendBack = input.bool(true, "Highlight background", group = "UI")

data = _pullData(src, tf, rep)
inc  = _pullData(src >= src[1], tf, rep)

plot(data, "Plot Multi TF trend", color = showTrendLine ? inc ? color.green : color.red : na, linewidth = 3)
bgcolor(color = showTrendBack ? inc ? color.new(color.green, 80) : color.new(color.red, 80) : na)

goLong = inc and ta.change(inc)
goShort = not inc and ta.change(inc)