how to make security_lower_tf work in lower timeframe without issue?

185 Views Asked by At

I have a pinescript V5 code and it works fine in Daily

the code

//@version=5
indicator(title='test', shorttitle='test', overlay=true)


/////////////// Start security_lower_tf Daily close ///////////////
array<float> close_values = request.security_lower_tf(syminfo.tickerid, "D", close)
var float element = na

array_size = array.size(close_values)

if array_size
    last_element_index = array_size - 1
    element := array.get(close_values, last_element_index)

// shorter version
// element := array_size ? array.get(close_values, array_size-1) : na

plot (element, color=color.red)
/////////////// End security_lower_tf Daily close ///////////////



/////// Start Moving Average /////// 
fastAverage = ta.sma(close, 10)
slowAverage = ta.sma(close, 50)

plot(fastAverage, color=color.navy)
plot(slowAverage, color=color.fuchsia)

, but the indicator can't work in lower time frame than Daily

and show this message

Study Error 
The chart's timeframe must be greater or
equal to the 'D' timeframe used with
'request.security_lower_tf()'.

how to fix this to just show ( Moving average ) in timeframe lower than Daily?

1

There are 1 best solutions below

5
On

The request.security_lower_tf function places lower time frame data into an array. In your example, you are requesting the daily closes in your request, so you need to be on a daily time frame or higher, otherwise you would use the regular request.security call to get higher time frame data.

Change your request to a lower time frame, the example below would put the 5 minute closes into an array. If you are on a 30 minute chart each bars array would have 6 values. (6 5minute closes in a 30 minute candle)

request.security_lower_tf(syminfo.tickerid, "5", close)