Overview

The Arnoud Legoux Moving Average (ALMA) is a type of moving average that applies a Gaussian distribution weighting to price data, smoothing it while minimizing lag and noise. It is designed to enhance responsiveness while reducing false signals, making it effective for trend-following strategies.

Syntax

const period = 20; // Lookback period for the ALMA calculation
const offset = 0.86; // Offset for the center of the Gaussian weighting
const sigma = 6; // Controls the width of the Gaussian curve
const src = "close"; // Source data for the calculation (e.g., "close", "open", "high", "low")
const alma = new I.ALMA([period, offset, sigma], src);

Parameters

  1. period (Integer):
  2. offset (Float):
  3. sigma (Float):
  4. src (String):

Returns

The ALMA object provides a series of smoothed values representing the Arnoud Legoux Moving Average. Initial values may be undefined if insufficient data points exist to calculate the specified period.

Accessing Indicator Values

To access the current values of the ALMA indicator:

const iv = HFS.indicatorValues(state);
const almaValue = iv.alma; // Retrieve the most recent ALMA value

Example Usage

Basic Implementation

const period = 20;
const offset = 0.86;
const sigma = 6;
const src = "close";

const alma = new I.ALMA([period, offset, sigma], src);

const iv = HFS.indicatorValues(state);
const almaValue = iv.alma;

console.log(almaValue); // Outputs the most recent ALMA value

Trend Detection

Use ALMA to detect market trends:

if (currentPrice > almaValue) {
    console.log("Price is above ALMA: Uptrend detected.");
} else if (currentPrice < almaValue) {
    console.log("Price is below ALMA: Downtrend detected.");
} else {
    console.log("Price is at ALMA: Neutral trend.");
}