Pine 脚本中带有两个参数的颜色条件格式

问题描述 投票:0回答:1

尝试使用两个参数创建 bgcolor 格式,但出现错误。有人会解决这个问题吗? 此外,希望知道使用 table.cell_set_text() 时如何进行颜色格式化。

//Delta Table

Table_Def = table.new(position = position.bottom_right, columns = 30, rows = 1, frame_color = color.black, frame_width = 1, border_color = color.black, border_width = 1)

table.cell(Table_Def, column = 0, row = 2, text = "CumDelta", text_color = color.black, text_size = size.auto, text_halign = text.align_left)

table.cell(Table_Def, column = 1, row = 2, text = str.tostring(cumdelta\[29\]), text_color = color.black, bgcolor = if cumdelta\[29\]\>0 and cumdelta\[29\]\>cvdAverage\[29\] \* 1.05 ? color.new(color.lime, 0) : if cumdelta\[29\]\>0 and cumdelta\[29\]\>cvdAverage\[29\] \* 1.025 ? color.new(color.lime, 50) : if cumdelta\[29\]\<0 and cumdelta\[29\]\<cvdAverage\[29\]\*1.05) ? color.new(color.fuchsia, 0) : if cumdelta\[29\]\<0 and cumdelta\[29\]\<cvdAverage\[29\]\*1.05) ? color.new(color.fuchsia, 50) : color.new(color.gray, 50), text_size = size.auto, text_halign = text.align_right)
pine-script background-color
1个回答
0
投票

三元不需要“if”

试试这个:

//Delta Table

Table_Def = table.new(position = position.bottom_right, columns = 30, rows = 1, frame_color = color.black, frame_width = 1, border_color = color.black, border_width = 1)

table.cell(Table_Def, column = 0, row = 2, text = "CumDelta", text_color = color.black, text_size = size.auto, text_halign = text.align_left)

cumdeltaCol = cumdelta > 0 and cumdelta > cvdAverage * 1.05  ? color.new(color.lime, 0)     :
              cumdelta > 0 and cumdelta > cvdAverage * 1.025 ? color.new(color.lime, 50)    :
              cumdelta < 0 and cumdelta < cvdAverage * 1.05  ? color.new(color.fuchsia, 0)  :
              cumdelta < 0 and cumdelta < cvdAverage * 1.05  ? color.new(color.fuchsia, 50) :
              color.new(color.gray, 50)

table.cell(Table_Def, column = 1, row = 2, text = str.tostring(cumdelta), text_color = color.black, bgcolor = cumdeltaCol, text_size = size.auto, text_halign = text.align_right)
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.