CrazyLayKer
CrazyLayKer

Reputation: 1

Using the 'request.security_lower_tf' function, but the returned array size is 0

just like the code below, I was trying to get the lower timeframe data from 1 minute timeframe, but I got the error message:

In 'array.get()' function. Index 1 is out of bounds. array size is 0.

plot(array.get(request.security_lower_tf(syminfo.tickerid, '1', close), 1))

But if I change the code to get the array size, I can get the correct lower timeframe array size in the present timeframe, like if the present timeframe is 1 hour, I got the array size 60 , if 4 hours, I got 240.

plot(array.size(request.security_lower_tf(syminfo.tickerid, '1', close)))

And I noticed if the present timeframe is 1 minute , I got another error message(I set the index to 1 to find out if there is any array element.):

In 'array.get()' function. Index 1 is out of bounds. array size is 1.

If I understand correctly, 'request.security_lower_tf ' can and can only be used to get the lower timeframe data.

Why is this happening? What should I do to get the correct data?

Upvotes: 0

Views: 1932

Answers (1)

Rohit Agarwal
Rohit Agarwal

Reputation: 1368

  1. Index of first element of array is 0 and not 1.
  2. Secondly, total of 5000 bars are returned for lower timeframe so the array will be empty for previous bars of higher timeframe. So you should check array size before accessing its elements.

So use it like

arr=request.security_lower_tf(syminfo.tickerid, '1', close)
plot(array.size(arr)>0?array.get(arr,0):na)

Upvotes: 1

Related Questions