Skip to main content

Global Variables in Pine Script

· 10 min read
Pineify Team
Pine Script and AI trading workflow research team
Pineify | Best Pine Script Editor

Global variables in Pine Script are declared in the script's top-level scope. Scope determines where a name can be used; declaration mode determines when its value is initialized. A global variable does not automatically preserve its value across bars. Use var when a counter, running total, or state needs that persistence.

request.security() in Pine Script: Multi-Timeframe Without Surprises

· 8 min read
Pineify Team
Pine Script and AI trading workflow research team
Pine Script request.security function example showing multi-timeframe analysis

request.security() is a Pine Script function that fetches data from any symbol or timeframe, not just the one on your current chart. You can pull OHLCV values, custom calculations, or entire indicator outputs from another context and display them in your active script.

Ever found yourself on a 1-minute chart needing the daily trend? Or trading SPY but wanting to watch what the VIX is doing at the same time? That's what this function supports.

The requested context has its own bars and confirmation timing. An expression that compiles can still use an invalid timeframe or produce changing values on realtime bars.