Script Definition
Functions for defining script metadata, input parameters, data sources, and output formatting. Essential foundations for creating well-structured and user-friendly kScript indicators.
Overview
Script Metadata
Define script properties including name, chart placement, axis configuration, and title customization for professional indicator presentation.
User Inputs
Create configurable parameters that users can adjust, including numbers, colors, booleans, and constrained selections for flexible indicators.
Data Management
Access market data sources, manage data feeds, and implement debugging tools for robust indicator development and troubleshooting.
Functions Reference
define - set script metadata and chart placement
define(title: string, position: 'onchart' | 'offchart', showPriceAxis?: boolean, customTitle?: string): void
Parameters:
- title (string) - Display name of the indicator
- position ('onchart' | 'offchart') - Chart placement - 'onchart' or 'offchart'
- showPriceAxis (boolean) - Show price axis for off-chart indicators (default: false)
- customTitle (string) - Custom title override
Returns:
void (configures the study)
Code Example:
input - create user-configurable parameters
input(name: string, type: string, defaultValue?: any, label?: string, constraints?: any): any
Parameters:
- name (string) - Parameter identifier
- type (string) - Input type ('number', 'color[]', 'boolean', 'color')
- defaultValue (any) - Default value
- label (string) - User-friendly label
- constraints (any) - Validation constraints
Returns:
any (current parameter value)
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')
- 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)
Code Example:
Common Usage Patterns
Complete Indicator Setup
Proper script structure with metadata, inputs, and data sources
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.