'Pine script : why are these two scripts behaving differently?

The following two scripts based on my understanding should behave identically and yet at lower timeframe (e.g. 1 minuyte) that the 1D they do not and I can't grasp why

I would have expected last and index to keep their value unchanged in both scripts but this is occurring only in the second one. What is it that I'm missing or do not understand?

Script 1

//@version=5
indicator("My script 1", overlay=false)

t = ticker.new("NASDAQ", "MSFT", session.extended, adjustment.none)
msft_close = request.security(t, "1D", close[1], lookahead=barmerge.lookahead_off)

var last = 0.0
var index = 0

if barstate.islast
    last := msft_close
    index := bar_index
    
if barstate.islast
    var table panel = table.new(position.top_center, 1, 10)
    table.cell(panel, 0, 0, str.tostring(last), bgcolor=#FFFFFF)
    table.cell(panel, 0, 1, str.tostring(index), bgcolor=#FFFFFF)

Script 2

//@version=5
indicator("My script 2", overlay=false)

t = ticker.new("NASDAQ", "MSFT", session.extended, adjustment.none)
msft_close = request.security(t, "1D", close[1], lookahead=barmerge.lookahead_off)

if barstate.islast
    var float last = msft_close
    var index = bar_index

    var table panel = table.new(position.top_center, 1, 10)
    table.cell(panel, 0, 0, str.tostring(last), bgcolor=#FFFFFF)
    table.cell(panel, 0, 1, str.tostring(index), bgcolor=#FFFFFF)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source