You have to explicitly enable "dynamic requests": https://www.tradingview.com/pine-script-docs/concepts/other-timeframes-and-data/#dynamic-requests