Switch between request.security() and request.security_lower_tf()?

Viewed 27

I understand that request.security() is optimized for higher timeframe data calls and for lower the request.security_lower_tf(). However in the inputs section i want to show only one input.timeframe and code the strategy to toggle between higher and lower security calls by itself automatically.

longMTF_HT = request.security(syminfo.tickerid, inputTimeframe, longCondition[1], barmerge.gaps_off, barmerge.lookahead_on)
shortMTF_HT =  request.security(syminfo.tickerid, inputTimeframe, shortCondition[1], barmerge.gaps_off, barmerge.lookahead_on)

longMTF_LT = request.security_lower_tf(syminfo.tickerid, inputTimeframe, longCondition)
shortMTF_LT = request.security_lower_tf(syminfo.tickerid, inputTimeframe, shortCondition)

longMTF = timeframe.period < inputTimeframe ? longMTF_HT : longMTF_LT
shortMTF = timeframe.period < inputTimeframe ? shortMTF_HT: shortMTF_LT

The above code returns the error:

line 39: Cannot call 'operator ?:' with argument 'expr2'='shortMTF_LT'. An argument of 'bool[]' type was used but a 'series bool' is expected

Looking for a solution

1 Answers

It's because they return you different values. Unfortunatelly it is not documented well by TradingView.
request.security() - will return you eg. a close value from a higher timeframe in that this simple value fits easily into your timeframe | series float
request.security_ltf() - will return you an array of close values that, all grouped together, will fit into your current timeframe | array of series float
So less/equal amount of imported data vs. grouped, more detailed ltf data.

For ltf imports you are going to need some array operations/loops to process everything.

Related