如何使用单个布尔值在Pinescript中的两个表之间切换



我正试图在Pinescript v5:中这样的两个表之间切换

// live table
var table LEV_Display_mini = table.new(position.bottom_right, 14, 3)
var table LEV_Display = table.new(position.bottom_right, 14, 5)
color op_val_col = lev_sustain == max_lev ? color.green : lev_sustain >= lev_sustain[1] ? color.yellow : color.red
if barstate.islast
if not miniOn

table.cell(LEV_Display, 0, 0, 'New Positions:', text_color=color.white, text_size=size.auto, bgcolor=color.black)
table.cell(LEV_Display, 1, 0, str.format('{0}x', max_lev), text_color=color.white, text_size=size.auto, bgcolor=color.black)

table.cell(LEV_Display, 0, 1, 'Valid For:', text_color=color.white, text_size=size.auto, bgcolor=color.black)
table.cell(LEV_Display, 1, 1, str.format('{0} bars', tradelength), text_color=color.white, text_size=size.auto, bgcolor=color.black)

table.cell(LEV_Display, 0, 2, 'Est. Liq. Price:', text_color=color.white, text_size=size.auto, bgcolor=color.black)
table.cell(LEV_Display, 1, 2, str.format('{0} L | {1} S', math.round(long_liq,decim),math.round(short_liq,decim)), text_color=color.white, text_size=size.auto, bgcolor=color.black)

table.cell(LEV_Display, 0, 3, 'Open Positions:', text_color=color.yellow, text_size=size.auto, bgcolor=color.black)
table.cell(LEV_Display, 1, 3, str.format('{0}x', lev_sustain), text_color = op_val_col, text_size=size.auto, bgcolor=color.black)

table.cell(LEV_Display, 0, 4, 'Est. Liq. Price:', text_color=color.yellow, text_size=size.auto, bgcolor=color.black)
table.cell(LEV_Display, 1, 4, str.format('{0} L | {1} S', math.round(op_long_liq,decim),math.round(op_short_liq,decim)), text_color=color.white, text_size=size.auto, bgcolor=color.black)

else if miniOn

table.cell(LEV_Display_mini, 0, 0, 'New Positions:', text_color=color.white, text_size=size.auto, bgcolor=color.black)
table.cell(LEV_Display_mini, 1, 0, str.format('{0}x', max_lev), text_color=color.white, text_size=size.auto, bgcolor=color.black)

table.cell(LEV_Display_mini, 0, 1, 'Est. Liq. Price:', text_color=color.white, text_size=size.auto, bgcolor=color.black)
table.cell(LEV_Display_mini, 1, 1, str.format('{0} L | {1} S', math.round(long_liq,decim),math.round(short_liq,decim)), text_color=color.white, text_size=size.auto, bgcolor=color.black)

table.cell(LEV_Display_mini, 0, 2, 'Open Positions:', text_color=color.yellow, text_size=size.auto, bgcolor=color.black)
table.cell(LEV_Display_mini, 1, 2, str.format('{0}x', lev_sustain), text_color = op_val_col, text_size=size.auto, bgcolor=color.black)

当前的结果是,当miniOn为假时,表对象LEV_Display显示,而当miniOn为真时,不显示。这很好。

错误在于,无论布尔值是多少,表对象LEV_Display_mini都不会显示。起初,我认为这可能是某种重叠的图形,但遗憾的是,改变LEV_Display_mini在其他地方的位置并没有什么不同。我甚至尝试删除和清除与应该显示的表相对的表,但这也无济于事。

本质上,我需要一个布尔值,它将导致表a隐藏和表B显示,反之亦然。

您在一个图表位置只能有一个表,因此当您使用table.new()创建LEV_Display表时,它会覆盖之前创建的LEV_Display_mini。尝试填充LEV_Display_mini表中的单元格将一无所获,因为它已被替换,因此不存在。

简单的解决方法就是去掉LEV_Display_mini表。您可以创建一个单独的表,并根据您的布尔输入用完整信息或简短信息填充它。未填充的单元格不会显示,因此即使用5行创建了完整的表,只要不填充其余行,它在视觉上也只有3行。

最新更新