pine-scripttradingview-apipine-script-v6

Why does this indicator only plot a limited number of days?


This indicator, when used on the M15 timeframe, only plots the boxes back to 4th April. Why is this? If I removed the second box, it plots as far back as Feb 26th.

I know TV indicators can only plot a limited number of graphics, but is it more limited for certain types of plot?

//@version=6
indicator("London Session Highlight", overlay=true)

// Note: Be sure to select "Pinned to right scale"


// === Background during London session (08:00–17:00 UTC+2) ===
startHour = 8
startMin = 0
endHour = 16
endMin = 15
sessionStart = timestamp('UTC', year, month, dayofmonth, startHour, startMin)
sessionEnd = timestamp('UTC', year, month, dayofmonth, endHour, endMin)

isInSession = sessionStart <= time and time <= sessionEnd
bgcolor(isInSession ? color.new(color.blue, 80) : na)


// === 9am M15 candle ===
var white = color.new(color.white, 80)
var yellow = color.new(color.yellow, 80)

isNineAM = (hour(time, 'UTC') == startHour) and (minute == 0)
isNineFifteenAM = (hour(time, 'UTC') == startHour) and (minute == 15)

bgcolor(isNineAM ? color.new(color.orange, 80) : na)

if isNineFifteenAM and not na(high[1]) and not na(low[1]) and high[1] != low[1] and barstate.isconfirmed
    startIndex = bar_index-1
    endIndex = bar_index + 32
    box.new(left=startIndex, right=endIndex, top=high[1]+(high[1]-low[1]), bottom=low[1]-(high[1]-low[1]), border_color=na, bgcolor=yellow)
    box.new(left=startIndex, right=endIndex, top=high[1], bottom=low[1], border_color=na, bgcolor=white)

enter image description here


Solution

  • Pine Script limits the number of boxes for server resources (similarly restricting lines, labels, and polylines).

    By default, it displays the last 50 boxes. You can explicitly increase this limit to 500 by passing the max_boxes_count parameter on your indicator declaration statement:

    indicator("London Session Highlight", overlay=true, max_boxes_count=500)