Overview

Simple Moving Average (SMA)

Arithmetic mean of prices over a specified period. Equal weight given to all data points.

• Smooth trend identification • Support/resistance levels • Crossover signals

Exponential Moving Average (EMA)

Weighted average giving more importance to recent prices. More responsive to price changes.

• Faster trend detection • Reduced lag • Better for volatile markets

Running Moving Average (RMA)

Modified exponential moving average using alpha = 1/period. Also known as Wilder's smoothing method.

• Smoother than EMA • Less sensitive to outliers • Used in RSI calculations

Functions Reference

sma - Simple Moving Average helper function

sma(source: TimeSeries, period?: number = 12, priceIndex?: number = 1): number

Parameters:

  • source (TimeSeries) - Source data series
  • period (number) - Number of periods for calculation (default: 12)
  • priceIndex (number) - Index of price data (default: 1)

Returns:

number (moving average value at specific bar)

Code Example:

ema - Exponential Moving Average helper function

ema(source: TimeSeries, period?: number = 12, priceIndex?: number = 1): number

Parameters:

  • source (TimeSeries) - Source data series
  • period (number) - Number of periods for calculation (default: 12)
  • priceIndex (number) - Index of price data (default: 1)

Returns:

number (exponential moving average value at specific bar)

Code Example:

rma - Running Moving Average helper function

rma(source: TimeSeries, period?: number = 12, priceIndex?: number = 1): number

Parameters:

  • source (TimeSeries) - Source data series
  • period (number) - Number of periods for calculation (default: 12)
  • priceIndex (number) - Index of price data (default: 1)

Returns:

number (running moving average value at specific bar)

Code Example:

Best Practices

💡

Period Selection

Common periods: 20 (short-term), 50 (medium-term), 200 (long-term). Adjust based on trading timeframe and market volatility.

EMA vs SMA

Use EMA for faster signals in trending markets, SMA for smoother signals in ranging markets. EMA reacts quicker to price changes.

📊

Confirmation

Combine moving averages with volume, RSI, or other indicators for stronger signal confirmation. Never rely on MA alone.

🎯

False Signals

Moving averages lag price action. In choppy markets, use additional filters to reduce whipsaws and false breakouts.

📖
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