0

struggling to fix this. I want avgDailyRange to be displayed on ALL timeframes. Idea is to show ADRD for daily and lower timeframes, and replace ADRD with ADR on higher timeframes.

Currently I get an error on lower than Daily timeframes (see screenshot). It shows ADR and ADRD values on higher than daily timeframes, although ADRD acts strangely (changes its value few seconds after initial display).

Can anyone suggest neat solution?

ADRD = request.security(syminfo.tickerid, "D", avgDailyRange)
float[] ADR = timeframe.in_seconds() > timeframe.in_seconds("D")? request.security_lower_tf(syminfo.tickerid, "1D", avgDailyRange) : na

I_get_this

Tried resources online, pinescript manual.

geleone
  • 1
  • 1
  • It means that your chart timeframe is lower than 1D, while `security.lower_tf()` should used with timeframes <= current timeframe. Either use another timeframe in `security.lower_tf()`, or another chart timeframe, or use `request.security()` instead of `request.secity_lower_tf()` – Starr Lucky Jul 31 '23 at 10:58
  • I understand that. I'll ask differently: how can I successfully run a script across all timeframes with two calls in the same script? Calls are: _request.security(syminfo.tickerid, "D", avgDailyRange)_ _request.security_lower_tf(syminfo.tickerid, "D", avgDailyRange)_ – geleone Aug 01 '23 at 07:09
  • Currently there is no way to do that. Redirected this request to the Pine Team. – Starr Lucky Aug 02 '23 at 12:28
  • Thanks for your answers and initiative about the request. – geleone Aug 02 '23 at 16:07
  • actually there is a crunchy way to achieve that, see answer – Starr Lucky Aug 03 '23 at 06:09

1 Answers1

0

We can use same timeframe as in the chart, if requested timeframe is higher:

//@version=5
indicator("My script")

secTf = input.timeframe("1D")

ishigher = timeframe.in_seconds(timeframe.period) >= timeframe.in_seconds(secTf) 


getHigherTfData()=>
    request.security(syminfo.tickerid, secTf, close)

getLowerTfData()=>
    request.security_lower_tf(syminfo.tickerid, ishigher ? secTf : timeframe.period, close)
    


if ishigher
    label.new(bar_index, 0, str.tostring(getLowerTfData()))
else if not ishigher
    label.new(bar_index, 0, str.tostring(getHigherTfData()))
    
Starr Lucky
  • 1,578
  • 1
  • 7
  • 8