how to get the specific value from and Array of Lower Time Frame Security function

Viewed 21

I am trying to get the value of 3:15 in 1 hour candle using request.security_lower_tf I got the array of data but I need to get 3rd candle close data to retrieve a value but when I try to access the value I am getting an error

arrClose = request.security_lower_tf(syminfo.tickerid, "5", close) data = array.get(arrClose,2)

keep getting message out of index when my size is 12

1 Answers

Not seeing your entire code I can only say this. Pine script is right.
You need to think about how or more precisely when it can be right.
The execution model executes your code. You're on an hourly timeframe so let's say pine is starting at 00:00. What you see is an initial hourly candle / full historic one. That's where the answer lies. There can be a circumstance where pine script does not have all the LTF data for your import yet, however you're just saying "give me the 3rd element" (00:10). On historical bars this should not be a problem but on the current one it can be.

Solution options:

  1. Check array.size(arrClose) first and do your logic then. On historical bars it makes no change but on the current you can skip/alter the part causing the error.
  2. Use for loop instead - depending on your use case it can be the solution but in a simple example like the one in your question I'd rather not choose this one
Related