Strategy · Pine Script v5 · On the chart

ESM2024 - ALMA Smoothed Gaussian Moving Average

by dearvn· code credited to thinhdangho

This strategy combines Arnaud Legoux Moving Average percentage price change calculations with an adaptive Gaussian Moving Average to generate trend-following signals.

View on GitHub

GitHub stars257on the repository
Pine versionv5runs as is
Lines of code117
Settings11inputs
LicenceNone statedfile: MPL-2.0
Last update6 weeks ago11 Sep 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

117 lines of Pine Script v5 from ESM2024.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

ESM2024.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © thinhdangho

//@version=5
strategy("ESM2024 - ALMA Smoothed Gaussian Moving Average", shorttitle = "ESM2024 - ALMA Moving Average", overlay=true, pyramiding=1, default_qty_type = strategy.fixed, default_qty_value = 1)

stopPerCall = input(0.08, title='Stop Loss Call %') / 100 
takePerCall = input(0.03, title='Take Profit Call %') / 100

stopPerPut = input(0.07, title='Stop Loss Put %') / 100 
takePerPut = input(0.02, title='Take Profit Put %') / 100

longStop = strategy.position_avg_price * (1 - stopPerCall)
shortStop = strategy.position_avg_price * (1 + stopPerPut)
shortTake = strategy.position_avg_price * (1 - takePerPut)
longTake = strategy.position_avg_price * (1 + takePerCall)


//ALMA Smoothing
src = input(close, title='Source', group = "ALMA Smoothing")
smooth = input.int(1, title='Smoothing', minval=1, group = "ALMA Smoothing")
length1 = input.int(25, title='Lookback', minval=1, group = "ALMA Smoothing")
offset = 0.85
sigma1 = 7
pchange = ta.change(src, smooth) / src * 100
avpchange = ta.alma(pchange, length1, offset, sigma1)

//RSI
rsi = ta.rsi(close, 14)
rsiL = rsi > rsi[1]
rsiS = rsi < rsi[1]

//Chande Momentum
length11 = 9
src1 = close
momm = ta.change(src1)
f1(m) => m >= 0.0 ? m : 0.0
f2(m) => m >= 0.0 ? 0.0 : -m
m1 = f1(momm)
m2 = f2(momm)
sm1 = math.sum(m1, length11)
sm2 = math.sum(m2, length11)
percent(nom, div) => 100 * nom / div
chandeMO = percent(sm1-sm2, sm1+sm2)
cL = chandeMO > chandeMO[1]
cS = chandeMO[1] < chandeMO[2]

//GAMA credit to author: © LeafAlgo https://www.tradingview.com/v/th7NZUPM/
length = input.int(26, minval=1, title="Length", group = "Gaussian Adaptive Moving Average")
adaptive = input.bool(true, title="Adaptive Parameters", group = "Gaussian Adaptive Moving Average")
volatilityPeriod = input.int(20, minval=1, title="Volatility Period", group = "Gaussian Adaptive Moving Average")

// Calculate Gaussian Moving Average
gma = 0.0 
sumOfWeights = 0.0
sigma = adaptive ? ta.stdev(open, volatilityPeriod) : input.float(1.0, minval=0.1, title="Standard Deviation", group = "Gaussian Adaptive Moving Average")

for i = 0 to length - 1
    weight = math.exp(-math.pow(((i - (length - 1)) / (2 * sigma)), 2) / 2)
    value = ta.highest(avpchange, i + 1) + ta.lowest(avpchange, i + 1)
    gma := gma + (value * weight)
    sumOfWeights := sumOfWeights + weight

gma := (gma / sumOfWeights) / 2
gma:= ta.ema(gma, 7)
gmaColor = avpchange >= gma ? color.rgb(0, 161, 5) : color.rgb(215, 0, 0)

// Color bars based on signals until the next signal occurs
var int currentSignal = 0
currentSignal := avpchange >= gma ? 1 : -1//le_final ? -1 : currentSignal

//var color barColor = na
//if currentSignal == 1
//    barColor := color.rgb(0, 186, 6)
//else if currentSignal == -1
//    barColor := color.rgb(176, 0, 0)

//barcolor(barColor)
//plotcandle(open, high, low, close, "Bar Color", barColor, barColor, bordercolor = barColor)

//Plotting
ema = ta.ema(close, 7)
plot(ema, color=gmaColor, linewidth=3, title="Gaussian Moving Average")

buy_signal = ta.crossover(avpchange,gma) and barstate.isconfirmed
sell_signal = ta.crossunder(avpchange,gma) and barstate.isconfirmed
plotshape(buy_signal ? low : na, "Buy Signal", text = "B", textcolor = color.white, style = shape.labelup, location = location.belowbar, color = color.rgb(0, 161, 5), offset = -1)
plotshape(sell_signal ? high : na, "Sell Signal", text = "S", textcolor = color.white, style = shape.labeldown, location = location.abovebar, color = color.rgb(215, 0, 0), offset = -1)

//bgcolor(ta.crossover(avpchange,gma) and barstate.isconfirmed and rsiL and cL ? color.rgb(0, 162, 5, 85): na, offset = -1)
//bgcolor(ta.crossunder(avpchange,gma) and barstate.isconfirmed and rsiS and cS ? color.rgb(207, 0, 0, 85): na, offset = -1)
//barcolor(gmaColor)

alertcondition(ta.crossover(avpchange,gma) and barstate.isconfirmed, title="Buy Signal", message="Go Long! {{exchange}}:{{ticker}}")
alertcondition(ta.crossunder(avpchange,gma) and barstate.isconfirmed, title="Sell Signal", message="Go Short! {{exchange}}:{{ticker}}")

hr = hour(time_close, 'UTC-8')
mi = minute(time_close, 'UTC-8')

if buy_signal 
    strategy.entry("call", strategy.long)
if sell_signal 
    strategy.entry("put", strategy.short)

if strategy.position_size > 0 and sell_signal and rsiS and cS
    strategy.close(id="call")
    //call_price := 0.0
if strategy.position_size < 0 and buy_signal and rsiL and cL
    strategy.close(id="put")


if(strategy.position_size > 0)
    strategy.exit(id='call', limit=longTake,stop = longStop)
    

if(strategy.position_size < 0)
    strategy.exit(id='put', limit=shortTake,stop = shortStop)

Overview

Long and short entries are triggered when the ALMA change calculation crosses above or below the Gaussian Moving Average on confirmed bars. The indicator overlay plots a 7-period exponential moving average colored by signal direction on the main price chart. Settings allow customization of smoothing inputs, Gaussian lookback periods, and percentage-based stop-loss and take-profit targets for both directions.

Details

Published by

dearvn on GitHub

Code credit

thinhdangho, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Moving averages, Oscillators & momentum, Trend

Markets

Indices

Timeframes

M15-H1

Risk Notes

  • The strategy can add several entries in the same direction

Topics

futures-markettradingviewtradovatetrading-futureses1best-indicator-tradingviewnq1trading-futurerus-stock-market

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Stop Loss Call %float0.08stopPerCall
Take Profit Call %float0.03takePerCall
Stop Loss Put %float0.07stopPerPut
Take Profit Put %float0.02takePerPut
Sourcesourceclosesrc
Smoothingint1smooth
Lookbackint25length1
Lengthint26length
Adaptive Parametersbooltrueadaptive
Volatility Periodint20volatilityPeriod
Standard Deviationfloat1.0Standard Deviation
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

330 stars

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy
218 stars

This strategy generates trading signals based on a selectable momentum engine, supporting MACD, RSI, Stochastic, or Rate of Change. Entries trigger on signal crosses, zero-line crosses, or threshold crosses, with an optional moving average trend filter. Risk m

Strategy v6 Oscillators & momentumTrend
Updated 3 months ago · None stated GitHub repository of Momentum Strategy Template

255 EMA Strategy

by hasnocool
106 stars

255 EMA Strategy combines an exponential moving average with Average True Range bands and standard MACD crossovers to generate entry signals. Drawn directly on the price chart, it plots the central 255 EMA along with upper and lower volatility envelopes. Trade

Strategy v4 Moving averagesOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 255 EMA Strategy

SMA RSI Strategy

by PythonForForex
64 stars

This strategy evaluates simple moving averages and the Relative Strength Index to generate trading signals. It calculates a 10-period SMA, a 30-period SMA, and a 14-period RSI. Long positions are entered when the fast SMA crosses above the slow SMA while RSI i

Strategy v5 TrendOscillators & momentum
Updated 4 years ago · None stated GitHub repository of SMA RSI Strategy

Momentum Rider DAILY FINAL

by greenpeas007
58 stars

This strategy combines exponential moving averages (EMA 9, 21, 50), RSI, MACD, and Supertrend indicators to enter long positions. It triggers trades using six dynamic setups based on momentum breakouts, EMA crossovers, and pullbacks. Position sizing is compute

Strategy v6 TrendOscillators & momentum Repaints
Updated 4 months ago · Custom licence GitHub repository of Momentum Rider DAILY FINAL

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers