Notice!
This is documentation for kScript v1.0, which may not include the latest features. For up-to-date documentation, see the latest version.

Overview

Statistical Functions

Calculate statistical measures like standard deviation, highest/lowest values, and sums over specified periods for robust technical analysis.

• Standard deviation • Min/max values • Period sums

Cross Detection

Detect when time series cross above, below, or in either direction to identify trend changes and generate trading signals.

• Crossover detection • Crossunder detection • Bidirectional crosses

Support/Resistance Levels

Identify key price levels using mathematical functions that track highest highs and lowest lows over specified periods for breakout and reversal analysis.

• Dynamic channels • Breakout identification • Level confirmation

Functions Reference

lowest - find lowest value over specified period

lowest(barIndex: number, series: TimeSeries, priceIndex: number, length: number): number

Parameters:

  • barIndex (number) - Current bar index
  • series (TimeSeries) - Source data series
  • priceIndex (number) - Index of price data
  • length (number) - Number of bars to look back

Returns:

number (lowest value in the specified period)

Code Example:

highest - find highest value over specified period

highest(barIndex: number, series: TimeSeries, priceIndex: number, length: number): number

Parameters:

  • barIndex (number) - Current bar index
  • series (TimeSeries) - Source data series
  • priceIndex (number) - Index of price data
  • length (number) - Number of bars to look back

Returns:

number (highest value in the specified period)

Code Example:

sum - calculate sum of values over specified period

sum(barIndex: number, series: TimeSeries, priceIndex: number, length: number): number

Parameters:

  • barIndex (number) - Current bar index
  • series (TimeSeries) - Source data series
  • priceIndex (number) - Index of price data
  • period (number) - Number of periods to sum

Returns:

number (sum of values in the specified period)

Code Example:

stddev - calculate standard deviation of values

stddev(barIndex: number, series: TimeSeries, priceIndex: number, period: number, mean?: number): number

Parameters:

  • barIndex (number) - Current bar index
  • series (TimeSeries) - Source data series
  • priceIndex (number) - Index of price data
  • period (number) - Number of periods for calculation
  • mean (number) - Pre-calculated mean (optional)

Returns:

number (standard deviation value)

Code Example:

donchian - Donchian Channel midpoint calculation

donchian(barIndex: number, series: TimeSeries, period?: number = 12): number

Parameters:

  • barIndex (number) - Current bar index
  • series (TimeSeries) - Source data series
  • period (number) - Number of periods (default: 12)

Returns:

number (Donchian Channel midpoint value)

Code Example:

crossover - detect when series A crosses above series B

crossover(barIndex: number, seriesA: number[], seriesB: number[]): boolean

Parameters:

  • barIndex (number) - Current bar index to check for crossover
  • seriesA (number[]) - First series (e.g., fast moving average)
  • seriesB (number[]) - Second series (e.g., slow moving average)

Returns:

boolean (true if A crosses above B at the current bar)

Code Example:

crossunder - detect when series A crosses below series B

crossunder(barIndex: number, seriesA: number[], seriesB: number[]): boolean

Parameters:

  • barIndex (number) - Current bar index
  • seriesA (number[]) - First series
  • seriesB (number[]) - Second series

Returns:

boolean (true when A crosses below B)

Code Example:

cross - detect when series A crosses series B in either direction

cross(barIndex: number, seriesA: number[], seriesB: number[]): boolean

Parameters:

  • barIndex (number) - Current bar index
  • seriesA (number[]) - First series
  • seriesB (number[]) - Second series

Returns:

boolean (true when any cross occurs)

Code Example:

Common Usage Patterns

Bollinger Bands

Use statistical functions to create Bollinger Bands indicator

Best Practices

📊

Lookback Periods

Choose appropriate lookback periods based on your timeframe. Shorter periods for scalping, longer periods for swing trading.

Performance

Statistical functions can be computationally expensive. Cache results when calculating multiple statistics on the same data.

🎯

Cross Detection

Use crossover() for bullish signals, crossunder() for bearish signals, and cross() when you need to detect any direction change. Always combine with trend confirmation.

📈

Donchian Channels

Donchian channels work best in trending markets for breakout strategies. In ranging markets, use them as support/resistance levels rather than breakout signals.

⚠️

False Signals

Cross functions can generate false signals in choppy markets. Use additional filters like volume confirmation or trend direction to improve signal quality.

📖
Introduction
Overview of kScript language
🚀
Quick Start
Get started with kScript basics
📋
Function Reference
Complete API reference guide
🔧
Core Concepts
Variables, data types & data sources
🔗
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
🏠
Go Home
Return to main landing page