'PineScript strange behaviour creating Table. Table is displayed as dot when using IF barstate.islast to create table.cells
Hello I isolated code which cause this strange behavior. It is caused by variable price. Is there way around?
//@version=5
strategy("My script",overlay=true)
testTable = table.new(position = position.top_right, columns = 2, rows = 1, border_width = 1,border_color = color.white,frame_width = 1,frame_color = color.white)
if barstate.islast
table.cell(table_id = testTable, column = 0, row = 0, text = "Text 1",text_size = size.large,text_color = color.white)
table.cell(table_id = testTable, column = 1, row = 0, text = "Text 2",text_size = size.large,text_color = color.white)
price = request.security(syminfo.tickerid,"D", high[1], lookahead=barmerge.lookahead_on)
crossover = (close > price)
strategy.entry("enter long", strategy.long, 1, when = crossover)
Solution 1:[1]
It is caused by barstate.islast. You creating table cells inside this local block. When cells are not created, with just table variable initialized with table.new() function there will be only a dot drawing (table borders without spacing between).
So barstate.islast is true for non ticking symbols, or after current last bar is closed (strategy calculates at close of each bar) for RT bars.
Use any other barstates, depending of your situation. E.g. barstate.islastconfirmedhistory will draw cells when bar is last historical bars. The barstate.isrealtime will redraw cells at realtime.
//@version=5
strategy("My script",overlay=true)
testTable = table.new(position = position.top_right, columns = 2, rows = 1, border_width = 1,border_color = color.white,frame_width = 1,frame_color = color.white)
if barstate.islastconfirmedhistory or barstate.isrealtime
table.cell(table_id = testTable, column = 0, row = 0, text = "Text 1",text_size = size.large,text_color = color.white)
table.cell(table_id = testTable, column = 1, row = 0, text = "Text 2",text_size = size.large,text_color = color.white)
price = request.security(syminfo.tickerid,"D", high[1], lookahead=barmerge.lookahead_on)
crossover = (close > price)
strategy.entry("enter long", strategy.long, 1, when = crossover)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Starr Lucky |
