SuperTrend Momentum Chart
 // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © VonnyFX
//@version=5
indicator("SuperTrend Momentum Chart", shorttitle="SuperTrend Momentum Chart", max_bars_back=5000, overlay=true)
// User inputs
factor = input.float(1, "Factor", step = 0.05, group="Smart Momentum", inline="x")
atrLength = input.int(2, "ATR Length", step = 1, group="Smart Momentum", inline="x")
timeFrameAmount = input.int(title= "Amount of Time Frames", defval=8, group="Higher Time Frame Inputs", minval=0, maxval=8)
res         = input.timeframe(title= "TimeFrame #1", defval="3", group="Higher Time Frame Inputs", inline="x")
res2        = input.timeframe(title= "TimeFrame #2", defval="5", group="Higher Time Frame Inputs", inline="x")
res3        = input.timeframe(title= "TimeFrame #3", defval="15", group="Higher Time Frame Inputs", inline="x")
res4        = input.timeframe(title= "TimeFrame #4", defval="60", group="Higher Time Frame Inputs", inline="x")
res5        = input.timeframe(title= "TimeFrame #5", defval="240", group="Higher Time Frame Inputs", inline="x")
res6        = input.timeframe(title= "TimeFrame #6", defval="1D", group="Higher Time Frame Inputs", inline="x")
res7        = input.timeframe(title= "TimeFrame #7", defval="1W", group="Higher Time Frame Inputs", inline="x")
res8        = input.timeframe(title= "TimeFrame #8", defval="1M", group="Higher Time Frame Inputs", inline="x")
textColor   = input.color(title="HTF Text Color", defval=#000000, group="Display Inputs" , inline="y")
textSizex    = input.string(title="Text Size", group="Display Inputs", inline="y", defval="Normal", options=["Tiny", "Small", "Normal", "Large", "Huge"])
momentumSwitch  = input.bool(true, title="[Momentum Switch]", inline="y", group="Display Inputs")
bullColor   = input.color(title="Bullish Color", defval=#22ad23, group="Display Inputs" , inline="b")
bullSwitchColor   = input.color(title="Bullish Switch Color", defval=#ffe900, group="Display Inputs" , inline="b")
bearColor   = input.color(title="Bearish Color", defval=#e10000, group="Display Inputs" , inline="s")
bearSwitchColor   = input.color(title="Bearish Switch Color", defval=#0006ff, group="Display Inputs" , inline="s")
chartPositionx = input.string(title="Chart Position",group="Display Inputs", defval="Top Right",
     options=["Top Right", "Top Center", "Top Left", "Middle Right", "Middle Center", "Middle Left", "Bottom Right", "Bottom Center", "Bottom Left"])


// Dynamic TimeFrame Text change
timeFrameText = (res == "1" ? res +"m": res == "3" ? res +"m": res == "5" ? res +"m": res == "15" ? res +"m": res == "30" ? res +"m": res == "45" ? res +"m":
     res == "60" ? " 1" +"H ": res == "120" ? " 2" +"H ": res == "180" ? " 3" +"H ": res == "240" ? " 4" +"H ":
     res == "1D" ? " D ": res == "3D" ? " 3D ": res == "1W" ? " W ": res == "2W" ? " 2W ": res == "1M" ? " M ": res == "2M" ? " 2M ": res == "3M" ? " 3M ": res == "6M" ? " 6M ": res == "12M" ? " 12M ": res == "30" ? "30": "30s")
transparent = timeFrameAmount >= 1 ? 0 : 100
//--------------------------------------------------------------------------
timeFrameText2 = (res2 == "1" ? res2 +"m": res2 == "3" ? res2 +"m": res2 == "5" ? res2 +"m": res2 == "15" ? res2 +"m": res2 == "30" ? res2 +"m": res2 == "45" ? res2 +"m":
     res2 == "60" ? " 1" +"H ": res2 == "120" ? " 2" +"H ": res2 == "180" ? " 3" +"H ": res2 == "240" ? " 4" +"H ":
     res2 == "1D" ? " D ": res2 == "3D" ? " 3D ": res2 == "1W" ? " W ": res2 == "2W" ? " 2W ": res2 == "1M" ? " M ": res2 == "2M" ? " 2M ": res2 == "3M" ? " 3M ": res2 == "6M" ? " 6M ": res2 == "12M" ? " 12M ": res == "30S" ? " 30S ": na)
transparent2 = timeFrameAmount >=  2 ? 0 : 100
//--------------------------------------------------------------------------
timeFrameText3 = (res3 == "1" ? res3 +"m": res3 == "3" ? res3 +"m": res3 == "5" ? res3 +"m": res3 == "15" ? res3 +"m": res3 == "30" ? res3 +"m": res3 == "45" ? res3 +"m":
     res3 == "60" ? " 1" +"H ": res3 == "120" ? " 2" +"H ": res3 == "180" ? " 3" +"H ": res3 == "240" ? " 4" +"H ":
     res3 == "1D" ? " D ": res3 == "3D" ? " 3D ": res3 == "1W" ? " W ": res3 == "2W" ? " 2W ": res3 == "1M" ? " M ": res3 == "2M" ? " 2M ": res3 == "3M" ? " 3M ": res3 == "6M" ? " 6M ": res3 == "12M" ? " 12M ": res == "30S" ? " 30S ": na)
transparent3 = timeFrameAmount >=  3 ? 0 : 100
//--------------------------------------------------------------------------
timeFrameText4 = (res4 == "1" ? res4 +"m": res4 == "3" ? res4 +"m": res4 == "5" ? res4 +"m": res4 == "15" ? res4 +"m": res4 == "30" ? res4 +"m": res4 == "45" ? res4 +"m":
     res4 == "60" ? " 1" +"H ": res4 == "120" ? " 2" +"H ": res4 == "180" ? " 3" +"H ": res4 == "240" ? " 4" +"H ":
     res4 == "1D" ? " D ": res4 == "3D" ? " 3D ": res4 == "1W" ? " W ": res4 == "2W" ? " 2W ": res4 == "1M" ? " M ": res4 == "2M" ? " 2M ": res4 == "3M" ? " 3M ": res4 == "6M" ? " 6M ": res4 == "12M" ? " 12M ": res == "30S" ? " 30S ": na)
transparent4 = timeFrameAmount >=  4 ? 0 : 100
//--------------------------------------------------------------------------
timeFrameText5 = (res5 == "1" ? res5 +"m": res5 == "3" ? res5 +"m": res5 == "5" ? res5 +"m": res5 == "15" ? res5 +"m": res5 == "30" ? res5 +"m": res5 == "45" ? res5 +"m":
     res5 == "60" ? " 1" +"H ": res5 == "120" ? " 2" +"H ": res5 == "180" ? " 3" +"H ": res5 == "240" ? " 4" +"H ":
     res5 == "1D" ? " D ": res5 == "3D" ? " 3D ": res5 == "1W" ? " W ": res5 == "2W" ? " 2W ": res5 == "1M" ? " M ": res5 == "2M" ? " 2M ": res5 == "3M" ? " 3M ": res5 == "6M" ? " 6M ": res5 == "12M" ? " 12M ": res == "30S" ? " 30S ": na)
transparent5 = timeFrameAmount >=  5 ? 0 : 100
//--------------------------------------------------------------------------
timeFrameText6 = (res6 == "1" ? res6 +"m": res6 == "3" ? res6 +"m": res6 == "5" ? res6 +"m": res6 == "15" ? res6 +"m": res6 == "30" ? res6 +"m": res6 == "45" ? res6 +"m":
     res6 == "60" ? " 1" +"H ": res6 == "120" ? " 2" +"H ": res6 == "180" ? " 3" +"H ": res6 == "240" ? " 4" +"H ":
     res6 == "1D" ? " D ": res6 == "3D" ? " 3D ": res6 == "1W" ? " W ": res6 == "2W" ? " 2W ": res6 == "1M" ? " M ": res6 == "2M" ? " 2M ": res6 == "3M" ? " 3M ": res6 == "6M" ? " 6M ": res6 == "12M" ? " 12M ": res == "30S" ? " 30S ": na)
transparent6 = timeFrameAmount >=  6 ? 0 : 100
//--------------------------------------------------------------------------
timeFrameText7 = (res7 == "1" ? res7 +"m": res7 == "3" ? res7 +"m": res7 == "5" ? res7 +"m": res7 == "15" ? res7 +"m": res7 == "30" ? res7 +"m": res7 == "45" ? res7 +"m":
     res7 == "60" ? " 1" +"H ": res7 == "120" ? " 2" +"H ": res7 == "180" ? " 3" +"H ": res7 == "240" ? " 4" +"H ":
     res7 == "1D" ? " D ": res7 == "3D" ? " 3D ": res7 == "1W" ? " W ": res7 == "2W" ? " 2W ": res7 == "1M" ? " M ": res7 == "2M" ? " 2M ": res7 == "3M" ? " 3M ": res7 == "6M" ? " 6M ": res7 == "12M" ? " 12M ": res == "30S" ? " 30S ": na)
transparent7 = timeFrameAmount >=  7 ? 0 : 100
//--------------------------------------------------------------------------
timeFrameText8 = (res8 == "1" ? res8 +"m": res8 == "3" ? res8 +"m": res8 == "5" ? res8 +"m": res8 == "15" ? res8 +"m": res8 == "30" ? res8 +"m": res8 == "45" ? res8 +"m":
     res8 == "60" ? " 1" +"H ": res8 == "120" ? " 2" +"H ": res8 == "180" ? " 3" +"H ": res8 == "240" ? " 4" +"H ":
     res8 == "1D" ? " D ": res8 == "3D" ? " 3D ": res8 == "1W" ? " W ": res8 == "2W" ? " 2W ": res8 == "1M" ? " M ": res8 == "2M" ? " 2M ": res8 == "3M" ? " 3M ": res8 == "6M" ? " 6M ": res8 == "12M" ? " 12M ": res == "30S" ? " 30S ": na)
transparent8 = timeFrameAmount >=  8 ? 0 : 100
//--------------------------------------------------------------------------
// Dynamic Table Position using user input string
var chartPosition =  position.top_right

if chartPositionx == "Top Right"
    chartPosition := position.top_right

if chartPositionx == "Top Center"
    chartPosition := position.top_center

if chartPositionx == "Top Left"
    chartPosition := position.top_left

if chartPositionx == "Middle Right"
    chartPosition := position.middle_right

if chartPositionx == "Middle Center"
    chartPosition := position.middle_center

if chartPositionx == "Middle Left"
    chartPosition := position.middle_left

if chartPositionx == "Bottom Right"
    chartPosition := position.bottom_right

if chartPositionx == "Bottom Center"
    chartPosition := position.bottom_center

if chartPositionx == "Bottom Left"
    chartPosition := position.bottom_left
//--------------------------------------------------------------------------
// Dynamic Table Position using user input string
var textSize =  size.tiny

if textSizex == "Tiny"
    textSize := size.tiny

if textSizex == "Small"
    textSize := size.small

if textSizex == "Normal"
    textSize := size.normal

if textSizex == "Large"
    textSize := size.large

if textSizex == "Huge"
    textSize := size.huge

//--------------------------------------------------------------------------

//Wait for candle to close before you show signal or change in realtime
closeRrealtime = true
barState = (closeRrealtime == true) ? barstate.isconfirmed : barstate.isrealtime

// Get SuperTrend Values
[supertrend, direction] = ta.supertrend(factor, atrLength)

// Get Higher time Frame and insert SuperTrend
htfSuperTrend = request.security(syminfo.tickerid, res, supertrend[barState ? 0 : 1])
htfSuperTrend2 = request.security(syminfo.tickerid, res2, supertrend[barState ? 0 : 1])
htfSuperTrend3 = request.security(syminfo.tickerid, res3, supertrend[barState ? 0 : 1])
htfSuperTrend4 = request.security(syminfo.tickerid, res4, supertrend[barState ? 0 : 1])
htfSuperTrend5 = request.security(syminfo.tickerid, res5, supertrend[barState ? 0 : 1])
htfSuperTrend6 = request.security(syminfo.tickerid, res6, supertrend[barState ? 0 : 1])
htfSuperTrend7 = request.security(syminfo.tickerid, res7, supertrend[barState ? 0 : 1])
htfSuperTrend8 = request.security(syminfo.tickerid, res8, supertrend[barState ? 0 : 1])
htfClose = request.security(syminfo.tickerid, res, close[barState ? 0 : 1])
htfClose2 = request.security(syminfo.tickerid, res2, close[barState ? 0 : 1])
htfClose3 = request.security(syminfo.tickerid, res3, close[barState ? 0 : 1])
htfClose4 = request.security(syminfo.tickerid, res4, close[barState ? 0 : 1])
htfClose5 = request.security(syminfo.tickerid, res5, close[barState ? 0 : 1])
htfClose6 = request.security(syminfo.tickerid, res6, close[barState ? 0 : 1])
htfClose7 = request.security(syminfo.tickerid, res7, close[barState ? 0 : 1])
htfClose8 = request.security(syminfo.tickerid, res8, close[barState ? 0 : 1])

//Prepare a table
var table myHTFTable = table.new(chartPosition, 2, 4, border_width=1)

 //Draw table
if barState 
    table.cell(myHTFTable, column = 0, row = 0 ,text=timeFrameText, text_size=textSize, text_color=textColor, 
     bgcolor= htfClose > htfSuperTrend  and htfClose[1] < htfSuperTrend[1] and momentumSwitch ? color.new(bullSwitchColor,transparent) : htfClose < htfSuperTrend  and htfClose[1] > htfSuperTrend[1] and momentumSwitch ?  color.new(bearSwitchColor,transparent) :
     htfClose > htfSuperTrend ? color.new(bullColor,transparent) : color.new(bearColor,transparent))
    table.cell(myHTFTable, column = 0, row = 1 ,text=timeFrameText3, text_size=textSize, text_color=textColor,
     bgcolor= htfClose3 > htfSuperTrend3  and htfClose3[1] < htfSuperTrend3[1] and momentumSwitch ? color.new(bullSwitchColor,transparent3) : htfClose3 < htfSuperTrend3  and htfClose3[1] > htfSuperTrend3[1] and momentumSwitch ? color.new(bearSwitchColor,transparent3) : 
     htfClose3 > htfSuperTrend3 ? color.new(bullColor,transparent3) :color.new(bearColor,transparent3))
    table.cell(myHTFTable, column = 0, row = 2 ,text=timeFrameText5, text_size=textSize, text_color=textColor,
     bgcolor= htfClose5 > htfSuperTrend5  and htfClose5[1] < htfSuperTrend5[1] and momentumSwitch ? color.new(bullSwitchColor,transparent5) : htfClose2 < htfSuperTrend5  and htfClose5[1] > htfSuperTrend5[1] and momentumSwitch ? color.new(bearSwitchColor,transparent5) : 
     htfClose5 > htfSuperTrend5 ? color.new(bullColor,transparent5) : color.new(bearColor,transparent5))
    table.cell(myHTFTable, column = 0, row = 3 ,text=timeFrameText7, text_size=textSize, text_color=textColor,
     bgcolor= htfClose7 > htfSuperTrend7  and htfClose7[1] < htfSuperTrend7[1] and momentumSwitch ? color.new(bullSwitchColor,transparent7) : htfClose7 < htfSuperTrend7  and htfClose7[1] > htfSuperTrend7[1] and momentumSwitch ? color.new(bearSwitchColor,transparent7) :
     htfClose7 > htfSuperTrend7 ? color.new(bullColor,transparent7) : color.new(bearColor,transparent7))

if barState 
    table.cell(myHTFTable, column = 1, row = 0 ,text=timeFrameText2, text_size=textSize, text_color=textColor,
     bgcolor= htfClose2 > htfSuperTrend2  and htfClose2[1] < htfSuperTrend2[1] and momentumSwitch ? color.new(bullSwitchColor,transparent2) : htfClose2 < htfSuperTrend2  and htfClose2[1] > htfSuperTrend2[1] and momentumSwitch ? color.new(bearSwitchColor,transparent2) : 
     htfClose2 > htfSuperTrend2 ? color.new(bullColor,transparent2) : color.new(bearColor,transparent2))
    table.cell(myHTFTable, column = 1, row = 1 ,text=timeFrameText4, text_size=textSize, text_color=textColor,
     bgcolor=htfClose4 > htfSuperTrend4  and htfClose4[1] < htfSuperTrend4[1] and momentumSwitch ? color.new(bullSwitchColor,transparent4) : htfClose4 < htfSuperTrend4   and htfClose4[1] > htfSuperTrend4[1] and momentumSwitch ? color.new(bearSwitchColor,transparent4) : 
     htfClose4 > htfSuperTrend4 ? color.new(bullColor,transparent4) : color.new(bearColor,transparent4))
    table.cell(myHTFTable, column = 1, row = 2 ,text=timeFrameText6, text_size=textSize, text_color=textColor,
     bgcolor= htfClose6 > htfSuperTrend6  and htfClose6[1] < htfSuperTrend6[1] and momentumSwitch ? color.new(bullSwitchColor,transparent6) : htfClose6 < htfSuperTrend6  and htfClose6[1] > htfSuperTrend6[1] and momentumSwitch ? color.new(bearSwitchColor,transparent6) :
     htfClose6 > htfSuperTrend6 ? color.new(bullColor,transparent6) : color.new(bearColor,transparent6))
    table.cell(myHTFTable, column = 1, row = 3 ,text=timeFrameText8, text_size=textSize, text_color=textColor,
     bgcolor= htfClose8 > htfSuperTrend8  and htfClose8[1] < htfSuperTrend8[1] and momentumSwitch ? color.new(bullSwitchColor,transparent8) : htfClose8 < htfSuperTrend8  and htfClose8[1] > htfSuperTrend8[1] and momentumSwitch ? color.new(bearSwitchColor,transparent8) :
     htfClose8 > htfSuperTrend8 ? color.new(bullColor,transparent8) : color.new(bearColor,transparent8))

