Strat FTFC Vip3rr
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/

//@version=5

indicator(title='Strat FTFC Vip3rr', shorttitle='FTFC Vip3rr', overlay=true)

_performanceGreenColor = input(color.rgb(38, 166, 154), title='Green Color')
_performanceRedColor = input(color.rgb(240, 83, 80), title='Red Color')
insideColor = input.color(color.yellow, title='Bearish color', group='Colors')
tfTableOpacity = input.int(80, title='Multi time frame table opacity', group='Colors')
tableposition = input.string(defval = position.top_right, title = "Table Position", options = [position.top_left, position.top_center, position.top_right, position.bottom_left, position.bottom_center, position.bottom_right])
isTfEnabled = input.bool(true, title='Enabled', group='Time frame continuation')
usePreviousClose = input.bool(false, title='Use previous close', group='Time frame continuation')
tf1 = input.timeframe('60', title='Time Frame 1', group='Time frame continuation')
tf2 = input.timeframe('D', title='Time Frame 2', group='Time frame continuation')
tf3 = input.timeframe('W', title='Time Frame 3', group='Time frame continuation')
tf4 = input.timeframe('1M', title='Time Frame 4', group='Time frame continuation')
tf5 = input.timeframe('1M', title='Time Frame 5', group='Time frame continuation')

cdayhigh = request.security(syminfo.tickerid, 'D', high)
cdaylow = request.security(syminfo.tickerid, 'D', low)
dAtr = request.security(syminfo.tickerid, 'D', ta.atr(14), lookahead=barmerge.lookahead_on)

tf1open = request.security(syminfo.tickerid, tf1, open)
tf1close = request.security(syminfo.tickerid, tf1, close)

tf2open = request.security(syminfo.tickerid, tf2, open)
tf2close = request.security(syminfo.tickerid, tf2, close)

tf3open = request.security(syminfo.tickerid, tf3, open)
tf3close = request.security(syminfo.tickerid, tf3, close)

tf4open = request.security(syminfo.tickerid, tf4, open)
tf4close = request.security(syminfo.tickerid, tf4, close)

tf5open = request.security(syminfo.tickerid, tf5, open)
tf5close = request.security(syminfo.tickerid, tf5, close)

var table tcTable = table.new(position = tableposition, columns = 7, rows = 2, border_width=1)

[tf1PrevClose, tf1Close] = request.security(syminfo.tickerid, tf1, [usePreviousClose ? close[1] : open[0], close[0]], barmerge.gaps_off)
[tf2PrevClose, tf2Close] = request.security(syminfo.tickerid, tf2, [usePreviousClose ? close[1] : open[0], close[0]], barmerge.gaps_off)
[tf3PrevClose, tf3Close] = request.security(syminfo.tickerid, tf3, [usePreviousClose ? close[1] : open[0], close[0]], barmerge.gaps_off)
[tf4PrevClose, tf4Close] = request.security(syminfo.tickerid, tf4, [usePreviousClose ? close[1] : open[0], close[0]], barmerge.gaps_off)
[tf5PrevClose, tf5Close] = request.security(syminfo.tickerid, tf4, [usePreviousClose ? close[1] : open[0], close[0]], barmerge.gaps_off)

h = high
l = low
c = close
o = open

onebar = h <= h[1] and l >= l[1]
twobar = h <= h[1] and l < l[1] or h > h[1] and l >= l[1]
threebar = h > h[1] and l < l[1]
greenbar = o <= c
red = o >= c
LIGHTTRANSP = 90
AVGTRANSP   = 80
HEAVYTRANSP = 70



if barstate.islast and isTfEnabled
    tf1Bullish = tf1open <= tf1close
    tf2Bullish = tf2open <= tf2close
    tf3Bullish = tf3open <= tf3close
    tf4Bullish = tf4open <= tf4close
	tf5Bullish = tf5open <= tf5close
	
	

    tf1Chg = (tf1close - tf1open) * 100.0 / math.abs(tf1open)
    tf1Color = tf1Chg >= 0 ? _performanceGreenColor : _performanceRedColor
    tf1opacity = math.abs(tf1Chg) > 2 ? HEAVYTRANSP : math.abs(tf1Chg) > 1 ? AVGTRANSP : LIGHTTRANSP
    

    tf2Chg = (tf2close - tf2open) * 100.0 / math.abs(tf2open)
    tf2Color = tf2Chg >= 0 ? _performanceGreenColor : _performanceRedColor
    tf2opacity = math.abs(tf2Chg) > 2 ? HEAVYTRANSP : math.abs(tf2Chg) > 1 ? AVGTRANSP : LIGHTTRANSP

    tf3Chg = (tf3close - tf3open) * 100.0 / math.abs(tf3open)
    tf3Color = tf3Chg >= 0 ? _performanceGreenColor : _performanceRedColor
    tf3opacity = math.abs(tf3Chg) > 2 ? HEAVYTRANSP : math.abs(tf3Chg) > 1 ? AVGTRANSP : LIGHTTRANSP

    tf4Chg = (tf4close - tf4open) * 100.0 / math.abs(tf4open)
    tf4Color = tf4Chg >= 0 ? _performanceGreenColor : _performanceRedColor
    tf4opacity = math.abs(tf4Chg) > 2 ? HEAVYTRANSP : math.abs(tf4Chg) > 1 ? AVGTRANSP : LIGHTTRANSP

    tf5Chg = (tf5close - tf5open) * 100.0 / math.abs(tf5open)
    tf5Color = tf5Chg >= 0 ? _performanceGreenColor : _performanceRedColor
    tf5opacity = math.abs(tf5Chg) > 2 ? HEAVYTRANSP : math.abs(tf5Chg) > 1 ? AVGTRANSP : LIGHTTRANSP

    table.cell(tcTable, 0, 0, tf1 + '\n' + str.tostring(tf1Chg, '#.##') + '%', bgcolor=color.new(tf1Color, tf1opacity), text_color=tf1Color, text_size=size.normal, width=0)
    table.cell(tcTable, 1, 0, tf2 + '\n' + str.tostring(tf2Chg, '#.##') + '%', bgcolor=color.new(tf2Color, tf2opacity), text_color=tf2Color, text_size=size.normal, width=0)
    table.cell(tcTable, 2, 0, tf3 + '\n' + str.tostring(tf3Chg, '#.##') + '%', bgcolor=color.new(tf3Color, tf3opacity), text_color=tf3Color, text_size=size.normal, width=0)
    table.cell(tcTable, 3, 0, tf4 + '\n' + str.tostring(tf4Chg, '#.##') + '%', bgcolor=color.new(tf4Color, tf4opacity), text_color=tf4Color, text_size=size.normal, width=0)
	table.cell(tcTable, 4, 0, tf5 + "\n" + str.tostring(tf5Chg, '#.##') + "%", bgcolor=color.new(tf5Color, tf5opacity), text_color=tf5Color, text_size=size.normal, width = 0)
    table.cell(tcTable, 5, 0, 'DTR' + '\n' + str.tostring(cdayhigh - cdaylow, '#.##'), bgcolor=color.new(color.gray, tfTableOpacity), text_color=color.white, text_size=size.normal, width=0)
    table.cell(tcTable, 6, 0, 'ATR' + '\n' + str.tostring(dAtr, '#.##'), bgcolor=color.new(color.gray, tfTableOpacity), text_color=color.white, text_size=size.normal, width=0)

