Global Context Variables

These variables are automatically available in every kScript and provide access to the current trading context.

currentSymbolstring

The current trading symbol (e.g., 'BTCUSDT')

Example:currentSymbol // Returns 'BTCUSDT'
currentExchangestring

The current exchange being used for trading (e.g., 'BINANCE', 'COINBASE')

Example: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.

colorcolor

The color to use for plotting (e.g., 'red', 'blue')

Example:plotLine(ema20, ["blue"], 2);
color[]color[]

Storing an array of color

Example:let colors = ["red", "green", "blue"];
📖
Introduction
Overview of kScript language
🚀
Quick Start
Get started with kScript basics
📋
Function Reference
Complete API reference guide
🔧
Variables
Core variables and data handling
📊
Data Sources
Subscribe to OHLCV, trades, and orderbook data
🔗
Script Definition
Defining inputs and metadata
🎯
Utility Functions
Helper functions and calculations
📈
Moving Averages
SMA, EMA and trend-following indicators
📊
Oscillators
RSI, Stochastic and momentum indicators
📈
Trend Indicators
Trend direction and strength analysis
📉
Volume Indicators
Volume-based analysis tools
📦
Orderbook Functions
Market depth analysis tools
🎨
Plotting & Visualization
Chart rendering and styling
🌈
Color Functions
Color manipulation and styling
🏠
Go Home
Return to main landing page