Overview

Script Metadata

Define script properties including name, chart placement, axis configuration, and title customization for professional indicator presentation.

• Chart placement control • Custom titles • Axis configuration

User Inputs

Create configurable parameters that users can adjust, including numbers, colors, booleans, and constrained selections for flexible indicators.

• Multiple input types • Default values • Validation constraints

Data Management

Access market data sources, manage data feeds, and implement debugging tools for robust indicator development and troubleshooting.

• OHLCV data access • Multi-source support • Debug output

Functions Reference

define - set script metadata and chart placement

define(title: string, position: 'onchart' | 'offchart', axis: boolean, customTitle?: string): void

Parameters:

  • title (string) - Display name of the indicator
  • position ('onchart' | 'offchart') - Chart placement - 'onchart' or 'offchart'
  • axis (boolean) - Show price axis for the indicator
  • customTitle (string) - Optional suffix appended to the title to display dynamic values (e.g., input parameters). Use variable interpolation like " ($period)" to show current settings in the chart title.

Returns:

void (configures the script)

Code Example:

input - create user-configurable parameters

input(name: string, type: string, defaultValue?: any, label?: string, constraints?: any, options?: string[]): any

Parameters:

  • name (string) - Unique parameter identifier used internally
  • type (string) - Input type: 'number' (numeric values), 'boolean' (true/false), 'color' (hex color picker), 'color[]' (array of colors), 'string' (text values), 'text' (multi-line text), 'select' (dropdown selection)
  • defaultValue (any) - Default value
  • label (string) - User-friendly display name in settings panel
  • constraints (object) - Validation rules for number inputs: {min: number, max: number}. Limits the valid range of numeric inputs. Only applicable for type="number".
  • options (string[]) - Array of choices for select type (required when type='select')

Returns:

any (current parameter value set by user)

Visual Example:

input - create user-configurable parameters example

Code Example:

source - create data source from market data

source(src: string, symbol: string, exchange: string): TimeSeries

Parameters:

  • src (string) - Data source type (e.g., 'ohlcv'). See Data Sources for all available types and aliases.
  • symbol (string) - Symbol for the data
  • exchange (string) - Exchange for the data

Returns:

TimeSeries (source data series)

Code Example:

print - output debug information to console

print(message: any): void

Parameters:

  • message (any) - Value to output to console for debugging

Returns:

void (outputs to console)

Visual Example:

print - output debug information to console example

Code Example:

printTimeSeries - output time series data to console

printTimeSeries(source: TimeSeries, priceIndex?: number): void

Parameters:

  • source (TimeSeries) - Time series data to output
  • priceIndex (number) - Index of price data to extract (optional)

Returns:

void (outputs time series data to console)

Code Example:

Best Practices

🎯

Naming Convention

Use descriptive names for scripts and inputs. Good names make your indicators more professional and user-friendly.

📊

Chart Placement

Use 'onchart' for price-related indicators, 'offchart' for oscillators and volume indicators. Consider independent axes for different scales.

📖
Introduction
Overview of kScript language
🔍
Overview
Complete technical documentation
🚀
Quick Start
Get started with kScript basics
📋
Function Reference
Complete API reference guide
📚
Type System
Understanding kScript data types
General FAQ
Frequently asked questions about kScript
Best Practices
Guidelines for writing efficient kScript code
⚠️
Limitations
Known constraints and workarounds
🆕
Updates
v1 vs v2 differences and improvements
🔧
Core Concepts
Variables, data types & data sources
⚙️
Execution Model
Per-bar execution lifecycle and phases
🏷️
Keyword Arguments
Named parameters for clear function calls
🔗
Field Accessors
Dot notation for timeseries field access
🛠️
User-Defined Functions
Create custom reusable functions
🔗
Script Definition
Defining inputs and metadata
TimeSeries Management
Working with time-aligned data
🎯
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
📊
Data Subscriptions
Subscribe to OHLCV, trades, and orderbook data
🔄
Loops
For loops and while loops for iteration
🧮
Math Functions
Mathematical functions and constants
🏠
Go Home
Return to main landing page