Global Context Variables
These variables are automatically available in every kScript and provide access to the current trading context.
currentSymbol
stringThe current trading symbol (e.g., 'BTCUSDT')
currentSymbol // Returns 'BTCUSDT'
currentExchange
stringThe current exchange being used for trading (e.g., 'BINANCE', 'COINBASE')
currentExchange // Returns 'BINANCE'
Common Usage Patterns
Real-world examples of how to use core variables in your trading strategies.
Dynamic Data Source
Create flexible indicators that automatically use the current market context.
Best Practices
Always Use Current Context
Use currentSymbol and currentExchange instead of hardcoding values for maximum flexibility.
// Good: source("ohlcv", currentSymbol, currentExchange)
Cache Expensive Operations
Store references to commonly used data sources to improve performance.
timeseries ohlcv = source("ohlcv", currentSymbol, currentExchange);
Array Variables
Core variables that handle collections of data for multi-dimensional analysis.
color
colorThe color to use for plotting (e.g., 'red', 'blue')
plotLine(ema20, ["blue"], 2);
color[]
color[]Storing an array of color
let colors = ["red", "green", "blue"];