I just want to make my table even better but i couldnt

129 views Asked by At

I've created a dynamic table which includes OHLC and SMA(50) and SMA(200) , SMA's also dynamic too.

But when it comes to the colouring my table cell's , tables have turned and i couldnt do it. I just want "if my symbol.open*>symbol.open[1] color.green and else color.red"

*for an explanation obviously. When i use like this i get an error.

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

//@version=5
indicator("Tablo - 16-10-2023",overlay = true)
// input_for_rows=input.int(7,title="Rows Value",group="INPUT FOR ROWS")

symbol1=input.symbol("",title="Symbol 1",group="SYMBOLS")
symbol2=input.symbol("",title="Symbol 2",group="SYMBOLS")
symbol3=input.symbol("",title="Symbol 3",group = "SYMBOLS")
symbol4=input.symbol("",title="Symbol 4",group="SYMBOLS")
symbol5=input.symbol("",title="Symbol 5",group = "SYMBOLS")
symbol6=input.symbol("",title="Symbol 6",group="SYMBOLS")

src=input.source(close,title="Source",group="SOURCE")
value1=input.int(50,title="Value 1",group="VALUES")
value2=input.int(200,title="Value 2",group="VALUES")

input_timeframe=input.timeframe("15",title="Timeframe",group="TIMEFRAME")

sma_short_term=ta.sma(src,value1)
sma_long_term=ta.sma(src,value2)


smayaziDegisimi(variablee)=>
    yazi="Symbol"
    yazi := "SMA" + "(" + str.tostring(variablee,format.volume) + ")" 
    yazi

sembolyazidegisim(symbolss)=>
    secimsembol=input.symbol("")
    if symbolss==symbol1
        secimsembol:=symbol1
    if symbolss==symbol2
        secimsembol:=symbol2
    if symbolss==symbol3
        secimsembol:=symbol3
    if symbolss==symbol4
        secimsembol:=symbol4
    if symbolss==symbol5
        secimsembol:=symbol5
    if symbolss==symbol6
        secimsembol:=symbol6
    secimsembol

getrequestSecurity(symboll,timeframee,expr)=>
    a=request.security("","","")
    a:=str.tostring(request.security(symboll,timeframee,expr),format.mintick)
    a



var table1=table.new(position = position.top_right,columns=7 , rows=7, bgcolor=color.silver, border_width=3 , frame_color=color.silver , frame_width=3 , border_color= color.black)

table.cell(table1,column = 0,row=0 , text="follow omersabriklc",text_color = color.black)
table.cell(table1,column=1 ,row=0 , text="OPEN",text_color = color.black,bgcolor = color.silver)
table.cell(table1,column=2 ,row=0 , text="HIGH",text_color = color.black,bgcolor = color.silver)
table.cell(table1,column=3 ,row=0 , text="LOW",text_color = color.black,bgcolor = color.silver)
table.cell(table1,column=4 ,row=0 , text="CLOSE",text_color = color.black,bgcolor = color.silver)

table.cell(table1,column=5 ,row=0 , text=smayaziDegisimi(value1),text_color = color.black,bgcolor = color.silver)
table.cell(table1,column=6 ,row=0 , text=smayaziDegisimi(value2),text_color = color.black,bgcolor = color.silver)

table.cell(table1,column = 0 , row=1 , text=sembolyazidegisim(symbol1),text_color = color.black,bgcolor = color.silver)
table.cell(table1,column = 0 , row=2 , text=sembolyazidegisim(symbol2),text_color = color.black,bgcolor = color.silver)
table.cell(table1,column = 0 , row=3 , text=sembolyazidegisim(symbol3),text_color = color.black,bgcolor = color.silver)
table.cell(table1,column = 0 , row=4 , text=sembolyazidegisim(symbol4),text_color = color.black,bgcolor = color.silver)
table.cell(table1,column = 0 , row=5 , text=sembolyazidegisim(symbol5),text_color = color.black,bgcolor = color.silver)
table.cell(table1,column = 0 , row=6 , text=sembolyazidegisim(symbol6),text_color = color.black,bgcolor = color.silver)

table.cell(table1,column = 1 , row=1 , text=getrequestSecurity((sembolyazidegisim(symbol1)),input_timeframe,open) ,text_color =color.black,bgcolor = open>open[1] ? color.green : color.red)
table.cell(table1,column = 2 , row=1 , text=getrequestSecurity((sembolyazidegisim(symbol1)),input_timeframe,high),text_color = color.black,bgcolor = high>high[1] ? color.green : color.red)
table.cell(table1,column = 3 , row=1 , text=getrequestSecurity((sembolyazidegisim(symbol1)),input_timeframe,low),text_color = color.black,bgcolor =low>low[1] ? color.green : color.red)
table.cell(table1,column = 4 , row=1 , text=getrequestSecurity((sembolyazidegisim(symbol1)),input_timeframe,close),text_color = color.black,bgcolor = close>close[1] ? color.green : color.red)
table.cell(table1,column = 5 , row=1 , text=getrequestSecurity((sembolyazidegisim(symbol1)),input_timeframe,sma_short_term),text_color = color.black,bgcolor = color.silver)
table.cell(table1,column = 6 , row=1 , text=getrequestSecurity((sembolyazidegisim(symbol1)),input_timeframe,sma_long_term),text_color = color.black,bgcolor = color.silver)

table.cell(table1,column = 1 , row=2 , text=getrequestSecurity((sembolyazidegisim(symbol2)),input_timeframe,open),text_color = color.black,bgcolor =open>open[1] ? color.green : color.red)
table.cell(table1,column = 2 , row=2 , text=getrequestSecurity((sembolyazidegisim(symbol2)),input_timeframe,high),text_color = color.black,bgcolor = high>high[1] ? color.green : color.red)
table.cell(table1,column = 3 , row=2 , text=getrequestSecurity((sembolyazidegisim(symbol2)),input_timeframe,low),text_color = color.black,bgcolor = low>low[1] ? color.green : color.red)
table.cell(table1,column = 4 , row=2 , text=getrequestSecurity((sembolyazidegisim(symbol2)),input_timeframe,close),text_color = color.black,bgcolor = close>close[1] ? color.green : color.red)
table.cell(table1,column = 5 , row=2 , text=getrequestSecurity((sembolyazidegisim(symbol2)),input_timeframe,sma_short_term),text_color = color.black,bgcolor = color.silver)
table.cell(table1,column = 6 , row=2 , text=getrequestSecurity((sembolyazidegisim(symbol2)),input_timeframe,sma_long_term),text_color = color.black,bgcolor = color.silver)

table.cell(table1,column = 1 , row=3 , text=getrequestSecurity((sembolyazidegisim(symbol3)),input_timeframe,open),text_color = color.black,bgcolor =open>open[1] ? color.green : color.red)
table.cell(table1,column = 2 , row=3 , text=getrequestSecurity((sembolyazidegisim(symbol3)),input_timeframe,high),text_color =color.black,bgcolor =high>high[1] ? color.green : color.red)
table.cell(table1,column = 3 , row=3 , text=getrequestSecurity((sembolyazidegisim(symbol3)),input_timeframe,low),text_color =color.black,bgcolor =low>low[1] ? color.green : color.red)
table.cell(table1,column = 4 , row=3 , text=getrequestSecurity((sembolyazidegisim(symbol3)),input_timeframe,close),text_color =color.black,bgcolor =close>close[1] ? color.green : color.red)
table.cell(table1,column = 5 , row=3 , text=getrequestSecurity((sembolyazidegisim(symbol3)),input_timeframe,sma_short_term),text_color = color.black,bgcolor = color.silver)
table.cell(table1,column = 6 , row=3 , text=getrequestSecurity((sembolyazidegisim(symbol3)),input_timeframe,sma_long_term),text_color = color.black,bgcolor = color.silver)

table.cell(table1,column = 1 , row=4 , text=getrequestSecurity((sembolyazidegisim(symbol4)),input_timeframe,open),text_color =color.black,bgcolor = open>open[1] ? color.green : color.red)
table.cell(table1,column = 2 , row=4 , text=getrequestSecurity((sembolyazidegisim(symbol4)),input_timeframe,high),text_color =color.black,bgcolor = high>high[1] ? color.green : color.red)
table.cell(table1,column = 3 , row=4 , text=getrequestSecurity((sembolyazidegisim(symbol4)),input_timeframe,low),text_color =color.black,bgcolor = low>low[1] ? color.green : color.red)
table.cell(table1,column = 4 , row=4 , text=getrequestSecurity((sembolyazidegisim(symbol4)),input_timeframe,close),text_color =color.black,bgcolor =close>close[1] ? color.green : color.red)
table.cell(table1,column = 5 , row=4 , text=getrequestSecurity((sembolyazidegisim(symbol4)),input_timeframe,sma_short_term),text_color = color.black,bgcolor = color.silver)
table.cell(table1,column = 6 , row=4 , text=getrequestSecurity((sembolyazidegisim(symbol4)),input_timeframe,sma_long_term),text_color = color.black,bgcolor = color.silver)

table.cell(table1,column = 1 , row=5 , text=getrequestSecurity((sembolyazidegisim(symbol5)),input_timeframe,open),text_color =color.black,bgcolor = open>open[1] ? color.green : color.red)
table.cell(table1,column = 2 , row=5 , text=getrequestSecurity((sembolyazidegisim(symbol5)),input_timeframe,high),text_color =color.black,bgcolor = high>high[1] ? color.green : color.red)
table.cell(table1,column = 3 , row=5 , text=getrequestSecurity((sembolyazidegisim(symbol5)),input_timeframe,low),text_color = color.black,bgcolor =low>low[1] ? color.green : color.red)
table.cell(table1,column = 4 , row=5 , text=getrequestSecurity((sembolyazidegisim(symbol5)),input_timeframe,close),text_color =color.black,bgcolor =close>close[1] ? color.green : color.red)
table.cell(table1,column = 5 , row=5 , text=getrequestSecurity((sembolyazidegisim(symbol5)),input_timeframe,sma_short_term),text_color = color.black,bgcolor = color.silver)
table.cell(table1,column = 6 , row=5 , text=getrequestSecurity((sembolyazidegisim(symbol5)),input_timeframe,sma_long_term),text_color = color.black,bgcolor = color.silver)

table.cell(table1,column = 1 , row=6 , text=getrequestSecurity((sembolyazidegisim(symbol6)),input_timeframe,open),text_color =color.black,bgcolor =open>open[1] ? color.green : color.red)
table.cell(table1,column = 2 , row=6 , text=getrequestSecurity((sembolyazidegisim(symbol6)),input_timeframe,high),text_color =color.black,bgcolor = high>high[1] ? color.green : color.red)
table.cell(table1,column = 3 , row=6 , text=getrequestSecurity((sembolyazidegisim(symbol6)),input_timeframe,low),text_color = color.black,bgcolor =low>low[1] ? color.green : color.red)
table.cell(table1,column = 4 , row=6 , text=getrequestSecurity((sembolyazidegisim(symbol6)),input_timeframe,close),text_color =color.black,bgcolor =close>close[1] ? color.green : color.red)
table.cell(table1,column = 5 , row=6 , text=getrequestSecurity((sembolyazidegisim(symbol6)),input_timeframe,sma_short_term),text_color = color.black,bgcolor = color.silver)
table.cell(table1,column = 6 , row=6 , text=getrequestSecurity((sembolyazidegisim(symbol6)),input_timeframe,sma_long_term),text_color = color.black,bgcolor = color.silver)


// bgcolor(open>open[1] ? color.green:color.red)
// grafiktenbagimsizyap()=>
    // chart.bg_color
// foropen()=>
    
//     arkarenkdinamik=color.silver
//     arkarenkdinamik:= if open>open[1]
//         dinamik=color.green
//     else if open[1] > open
//         dinamik=color.red
//     else
//         dinamik=arkarenkdinamik
//     arkarenkdinamik


// forclose()=>
//     arkarenkdinamik2=color.silver
//     arkarenkdinamik2:= if close>close[1]
//         dinamik2=color.green
//     else
//         dinamik2=color.red

// forhigh()=>
//     arkarenkdinamik3=color.silver
//     arkarenkdinamik3:= if high>high[1]
//         dinamik2=color.green
//     else
//         dinamik2=color.red

// forlow()=>
//     arkarenkdinamik4=color.silver
//     arkarenkdinamik4:= if low>low[1]
//         dinamik2=color.green
//     else
//         dinamik2=color.red

// getrequestSecurityColor(symboll,timeframee,expr)=>
//     b=request.security("","","")
//     b:=str.tostring(request.security(symboll,timeframee,expr),format.mintick)
//     b
//     col= if open>open[1]
//         dinamik=color.green
//     else
//         dinamik=color.red
//     col
//renk adımı kaldı son olarak
// 
1

There are 1 answers

1
karatedog On

You are updating the table cells on each and every candle which is useless.

Try putting the entire table.cell updating block under an if barstate.islast block, like:

if barstate.islast
    table.cell(table1,column = 0,row=0 , text="follow omersabriklc",text_color = color.black)
    ...
    ...
    ...

This way it will run only once, on the last candle and maybe this helps to clear the glitches.