user14554500
user14554500

Reputation: 15

Indicator not plotting lines or table for last bar

I am writing a strategy/indicator that has overlay = true. I have multiple lines being plotted and I use a table to display stats that is within an "if barstate.islast". They all work fine but for the last bar it doesn't draw the plots/lines or my stats table until the bar closes.

How can I get the indicator (plots) extended into the current bar even if it hasn't "closed" (ie is currently real time) and how do I display my table?

Obviously I want to be able to view the strategy/indicator during the day with the interval set to daily and want to see my summary table.

var table myTable = table.new(position = position.top_right, columns = 2, rows = 5, bgcolor = color.new(color.gray, 60))
if barstate.islast
    var msg_longConditions = array.new<string>(0)
    table.cell(myTable, 0, 0, "Analysis Summary", text_color = color.orange)
    table.cell(myTable, 0, 1, "Long alerts", text_color = color.orange)
    table.cell(myTable, 0, 2, "Short alerts", text_color = color.orange)
    table.cell(myTable, 0, 3, "stats", text_color = color.orange)
    txt_trend = switch trend_dir
        0 => "Horizontal channel"
        1 => "Up trend"
        -1 => "Down trend"
    table.cell(myTable, 1, 0, txt_trend, text_color = color.white, bgcolor = (trend_dir >0 ? color.green : (trend_dir < 0 ? color.red : color.black)))

The table doesn't display. I want the strategy/indicator to run with 1 day time interval but if I change the time interval to 1 minute the table does display once the current bar closes and a new bar is started but I also then get the table content repeated each time a new bar is started.

The other problem is that all of the plots that I'm doing are all great except they stop one bar before the end (ie they don't display for the current bar). I have added a screenshot just of the last few bars that shows some of the indicator plots coming up to the bar previous to the current bar but not extended to the current bar. None of the plots use an offset.

Chart:
Chart screenshot

Upvotes: 0

Views: 189

Answers (1)

user14554500
user14554500

Reputation: 15

OK I found the solution. In the Strategy statement at the start of the script I needed "calc_on_every_tick = true"

Upvotes: 0

Related Questions