This Pine Script provides a robust, customizable framework for trend detection and signal generation using the Arnaud Legoux Moving Average.
The Arnaud Legoux Moving Average (ALMA) is a modern moving average designed to provide both smoothness and responsiveness, reducing lag and filtering out market noise more effectively than traditional moving averages.
ALMA achieves this by applying a Gaussian filter and a unique weighting system, making it especially useful for identifying trends and potential reversals in financial markets. Traders often use ALMA to spot buy and sell opportunities by observing the relationship between price and the ALMA line, or by combining multiple ALMAs of different lengths for crossover strategies.
The indicator is highly customizable, allowing users to adjust its sensitivity and smoothness to fit their trading style
//@version=6
indicator("ALMA Trend & Signal Detector", overlay=true, shorttitle="ALMA Signals")
// === INPUTS ===
almaLen = input.int(20, "ALMA Length", minval=1)
almaOffset = input.float(0.85, "ALMA Offset", step=0.01)
almaSigma = input.float(6, "ALMA Sigma", minval=1)
showCrossover = input.bool(true, "Show ALMA/Price Cross Signals")
showDualALMA = input.bool(false, "Enable Dual ALMA Crossover")
almaLen2 = input.int(50, "Second ALMA Length", minval=1, group="Dual ALMA Settings")
almaOffset2 = input.float(0.85, "Second ALMA Offset", step=0.01, group="Dual ALMA Settings")
almaSigma2 = input.float(6, "Second ALMA Sigma", minval=1, group="Dual ALMA Settings")
// === ALMA CALCULATION ===
alma = ta.alma(close, almaLen, almaOffset, almaSigma)
alma2 = showDualALMA ? ta.alma(close, almaLen2, almaOffset2, almaSigma2) : na
// === SIGNALS ===
// Price/ALMA cross
buyPriceCross = showCrossover and ta.crossover(close, alma)
sellPriceCross = showCrossover and ta.crossunder(close, alma)
// Dual ALMA cross
buyAlmaCross = showDualALMA and ta.crossover(alma, alma2)
sellAlmaCross = showDualALMA and ta.crossunder(alma, alma2)
// === PLOTTING ===
plot(alma, color=color.blue, linewidth=2, title="ALMA")
plot(showDualALMA ? alma2 : na, color=color.orange, linewidth=2, title="ALMA 2")
plotshape(buyPriceCross, title="Buy (Price/ALMA)", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, text="Buy")
plotshape(sellPriceCross, title="Sell (Price/ALMA)", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, text="Sell")
plotshape(buyAlmaCross, title="Buy (ALMA/ALMA)", style=shape.triangleup, location=location.belowbar, color=color.lime, size=size.tiny, text="XBuy")
plotshape(sellAlmaCross, title="Sell (ALMA/ALMA)", style=shape.triangledown, location=location.abovebar, color=color.maroon, size=size.tiny, text="XSell")
bgcolor(close > alma ? color.new(color.green, 92) : color.new(color.red, 92), title="Trend Background")
// === ALERTS ===
alertcondition(buyPriceCross, title="Buy Signal (Price/ALMA)", message="ALMA Buy Signal: Price crossed above ALMA")
alertcondition(sellPriceCross, title="Sell Signal (Price/ALMA)", message="ALMA Sell Signal: Price crossed below ALMA")
alertcondition(buyAlmaCross, title="Buy Signal (ALMA/ALMA)", message="ALMA Buy Signal: Fast ALMA crossed above Slow ALMA")
alertcondition(sellAlmaCross, title="Sell Signal (ALMA/ALMA)", message="ALMA Sell Signal: Fast ALMA crossed below Slow ALMA")