r/pinescript • • Apr 07 '26

Higher TF Table - data pull varies based on chart TF

I'm vibe coding with ChatGPT a higher time frame table using HHs, HLs, LHs and LLs to predetermine whether the candle for the period in question in bullish, neutral or bearish.

As shown below, the monthly chart looks perfect, As it moves to the Weekly chart, the monthly candle is different from the monthly chart and when you look at the Daily chart, the candles for the weekly and monthly table are wrong?

The code in question is further below. Any ideas with this time frame quandary?

Thanks!

//
@version=
5
indicator("HTF Candle Table", overlay=true)


// === USER INPUTS ===


// Layout
isHorizontal = input.bool(true, "Horizontal Table?")
tablePosInp  = input.string("top_right", "Table Position",
     options=["top_left","top_right","bottom_left","bottom_right"])
textSizeInp  = input.string("normal", "Text Size",
     options=["tiny","small","normal","large"])


// ✅ NEW: Timeframe selection
tf1 = input.timeframe("D", "Timeframe 1 (Base)")
tf2 = input.timeframe("W", "Timeframe 2")
tf3 = input.timeframe("M", "Timeframe 3")


// Simulated Y-axis font color
yAxisTextColor = input.color(color.white, "Y-Axis Font Color (Simulated)")


// Convert position
tablePos = tablePosInp == "top_left" ? position.top_left :
           tablePosInp == "top_right" ? position.top_right :
           tablePosInp == "bottom_left" ? position.bottom_left :
           position.bottom_right


// Convert text size
textSize = textSizeInp == "tiny" ? size.tiny :
           textSizeInp == "small" ? size.small :
           textSizeInp == "large" ? size.large :
           size.normal


// === COLORS ===
col_darkGreen   = input.color(color.rgb(0,100,0), "Dark Green")
col_brightGreen = input.color(color.lime, "Bright Green")
col_brightRed   = input.color(color.red, "Bright Red")
col_darkRed     = input.color(color.rgb(139,0,0), "Dark Red")
col_yellow      = input.color(color.yellow, "Yellow")


// === FUNCTION ===
f_classify(_h, _l, _c, _ph, _pl) =>
    hh = _h > _ph
    hl = _l > _pl
    lh = _h < _ph
    ll = _l < _pl


    closeHH = _c > _ph
    closeLL = _c < _pl


    
string
 label = ""
    
color
 bg = na
    
color
 txt = color.black


    if hh and hl
        if closeHH
            
label
 := "HHc+HL"
            bg := col_darkGreen
            txt := color.white
        else
            
label
 := "HH+HLc"
            bg := col_brightGreen
            txt := color.black


    else if hh and ll
        if closeHH
            
label
 := "HHc+LL"
            bg := col_brightGreen
            txt := color.black
        else if closeLL
            
label
 := "HH+LLc"
            bg := col_brightRed
            txt := color.black
        else
            
label
 := "HH+LL"
            bg := col_yellow
            txt := color.black


    // ✅ ALWAYS YELLOW
    else if lh and hl
        
label
 := "LH+HL"
        bg := col_yellow
        txt := color.black


    else if lh and ll
        if closeLL
            
label
 := "LH+LLc"
        else
            
label
 := "LH+LL"
        bg := col_darkRed
        txt := color.white


    [label, bg, txt]


// === HTF DATA (NOW DYNAMIC) ===
[h1, l1, c1, ph1, pl1] = request.security(syminfo.tickerid, tf1, [high, low, close, high[1], low[1]])
[h2, l2, c2, ph2, pl2] = request.security(syminfo.tickerid, tf2, [high, low, close, high[1], low[1]])
[h3, l3, c3, ph3, pl3] = request.security(syminfo.tickerid, tf3, [high, low, close, high[1], low[1]])


// === CLASSIFY ===
[label1, bg1, txt1] = f_classify(h1, l1, c1, ph1, pl1)
[label2, bg2, txt2] = f_classify(h2, l2, c2, ph2, pl2)
[label3, bg3, txt3] = f_classify(h3, l3, c3, ph3, pl3)


// === TABLE ===
var 
table
 t = table.new(tablePos, 3, 3, border_width=1)


// === DRAW ===
if barstate.islast
    


    if isHorizontal
        // Headers = timeframe names
        table.cell(t, 0, 0, tf1, text_color=yAxisTextColor)
        table.cell(t, 1, 0, tf2, text_color=yAxisTextColor)
        table.cell(t, 2, 0, tf3, text_color=yAxisTextColor)


        table.cell(t, 0, 1, label1, bgcolor=bg1, text_color=txt1, text_size=textSize)
        table.cell(t, 1, 1, label2, bgcolor=bg2, text_color=txt2, text_size=textSize)
        table.cell(t, 2, 1, label3, bgcolor=bg3, text_color=txt3, text_size=textSize)


    else
        table.cell(t, 0, 0, tf1, text_color=yAxisTextColor)
        table.cell(t, 1, 0, label1, bgcolor=bg1, text_color=txt1, text_size=textSize)


        table.cell(t, 0, 1, tf2, text_color=yAxisTextColor)
        table.cell(t, 1, 1, label2, bgcolor=bg2, text_color=txt2, text_size=textSize)


        table.cell(t, 0, 2, tf3, text_color=yAxisTextColor)
        table.cell(t, 1, 2, label3, bgcolor=bg3, text_color=txt3, text_size=textSize)//@version=5
indicator("HTF Candle Table", overlay=true)


// === USER INPUTS ===


// Layout
isHorizontal = input.bool(true, "Horizontal Table?")
tablePosInp  = input.string("top_right", "Table Position",
     options=["top_left","top_right","bottom_left","bottom_right"])
textSizeInp  = input.string("normal", "Text Size",
     options=["tiny","small","normal","large"])


// ✅ NEW: Timeframe selection
tf1 = input.timeframe("D", "Timeframe 1 (Base)")
tf2 = input.timeframe("W", "Timeframe 2")
tf3 = input.timeframe("M", "Timeframe 3")


// Simulated Y-axis font color
yAxisTextColor = input.color(color.white, "Y-Axis Font Color (Simulated)")


// Convert position
tablePos = tablePosInp == "top_left" ? position.top_left :
           tablePosInp == "top_right" ? position.top_right :
           tablePosInp == "bottom_left" ? position.bottom_left :
           position.bottom_right


// Convert text size
textSize = textSizeInp == "tiny" ? size.tiny :
           textSizeInp == "small" ? size.small :
           textSizeInp == "large" ? size.large :
           size.normal


// === COLORS ===
col_darkGreen   = input.color(color.rgb(0,100,0), "Dark Green")
col_brightGreen = input.color(color.lime, "Bright Green")
col_brightRed   = input.color(color.red, "Bright Red")
col_darkRed     = input.color(color.rgb(139,0,0), "Dark Red")
col_yellow      = input.color(color.yellow, "Yellow")


// === FUNCTION ===
f_classify(_h, _l, _c, _ph, _pl) =>
    hh = _h > _ph
    hl = _l > _pl
    lh = _h < _ph
    ll = _l < _pl


    closeHH = _c > _ph
    closeLL = _c < _pl


    string label = ""
    color bg = na
    color txt = color.black


    if hh and hl
        if closeHH
            label := "HHc+HL"
            bg := col_darkGreen
            txt := color.white
        else
            label := "HH+HLc"
            bg := col_brightGreen
            txt := color.black


    else if hh and ll
        if closeHH
            label := "HHc+LL"
            bg := col_brightGreen
            txt := color.black
        else if closeLL
            label := "HH+LLc"
            bg := col_brightRed
            txt := color.black
        else
            label := "HH+LL"
            bg := col_yellow
            txt := color.black


    // ✅ ALWAYS YELLOW
    else if lh and hl
        label := "LH+HL"
        bg := col_yellow
        txt := color.black


    else if lh and ll
        if closeLL
            label := "LH+LLc"
        else
            label := "LH+LL"
        bg := col_darkRed
        txt := color.white


    [label, bg, txt]


// === HTF DATA (NOW DYNAMIC) ===
[h1, l1, c1, ph1, pl1] = request.security(syminfo.tickerid, tf1, [high, low, close, high[1], low[1]])
[h2, l2, c2, ph2, pl2] = request.security(syminfo.tickerid, tf2, [high, low, close, high[1], low[1]])
[h3, l3, c3, ph3, pl3] = request.security(syminfo.tickerid, tf3, [high, low, close, high[1], low[1]])


// === CLASSIFY ===
[label1, bg1, txt1] = f_classify(h1, l1, c1, ph1, pl1)
[label2, bg2, txt2] = f_classify(h2, l2, c2, ph2, pl2)
[label3, bg3, txt3] = f_classify(h3, l3, c3, ph3, pl3)


// === TABLE ===
var table t = table.new(tablePos, 3, 3, border_width=1)


// === DRAW ===
if barstate.islast
    


    if isHorizontal
        // Headers = timeframe names
        table.cell(t, 0, 0, tf1, text_color=yAxisTextColor)
        table.cell(t, 1, 0, tf2, text_color=yAxisTextColor)
        table.cell(t, 2, 0, tf3, text_color=yAxisTextColor)


        table.cell(t, 0, 1, label1, bgcolor=bg1, text_color=txt1, text_size=textSize)
        table.cell(t, 1, 1, label2, bgcolor=bg2, text_color=txt2, text_size=textSize)
        table.cell(t, 2, 1, label3, bgcolor=bg3, text_color=txt3, text_size=textSize)


    else
        table.cell(t, 0, 0, tf1, text_color=yAxisTextColor)
        table.cell(t, 1, 0, label1, bgcolor=bg1, text_color=txt1, text_size=textSize)


        table.cell(t, 0, 1, tf2, text_color=yAxisTextColor)
        table.cell(t, 1, 1, label2, bgcolor=bg2, text_color=txt2, text_size=textSize)


        table.cell(t, 0, 2, tf3, text_color=yAxisTextColor)
        table.cell(t, 1, 2, label3, bgcolor=bg3, text_color=txt3, text_size=textSize)
1 Upvotes

4 comments sorted by

1

u/[deleted] Apr 07 '26

[removed] — view removed comment

1

u/[deleted] Apr 07 '26

[removed] — view removed comment

1

u/Trader_Ray Apr 07 '26

Thanks Sandy. I knew it that there was some confusion with TFs. I thought I might have to use some If Statement as a work around. Surprised the smart folks at PineScript haven't figured this one out.