Search code examples
pine-scriptpine-script-v5

Is it possible to only retrieve the latest/last value when using the request.security_lower_tf function in PineScript v5?


So here’s the code that I’m using to retrieve the second timeframes values:

secHighArr = request.security_lower_tf(syminfo.tickerid, “1S”, high)
aTable = table.new(position.top_center,2,2)
table.cell(aTable, 1,1, str.tostring(secHighArr))

If I’m on a 5 minute timeframe this is obviously returning all the second values in the 5 minute period, is it possible to only retrieve the latest/last secHighArr value instead of all of them?


Solution

  • request.security_lower_tf returns an array. You cannot get only one value out of this call.

    request.security_lower_tf(symbol, timeframe, expression, ignore_invalid_symbol, currency) → array<type>
    

    However, since it is an array, you can get the last value of that array with:

    len = secHighArr.size()
    float last_val = (len > 0) ? array.get(secHighArr, len - 1) : na