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.
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);
period (Integer):
period of 20 calculates the ALMA based on the last 20 data points.offset (Float):
offset of 0.86 centers the weighting closer to the end of the period.sigma (Float):
src (String):
"close", "open", "high", "low", or other applicable fields."close"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.
To access the current values of the ALMA indicator:
const iv = HFS.indicatorValues(state);
const almaValue = iv.alma; // Retrieve the most recent ALMA value
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
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.");
}