Strategy · Pine Script v6 · On the chart

Triple EMA Strategy [trugurpala]

by trugurpala

This strategy trades momentum breakouts based on the alignment of three exponential moving averages.

View on GitHub

GitHub stars4on the repository
Pine versionv6current
Lines of code45
Settings6inputs
LicenceMIT
Last update2 months ago3 Aug 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

45 lines of Pine Script v6 from examples/strategies/08_triple_ema_strategy.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

08_triple_ema_strategy.pine
//@version=6
// Triple EMA 5/13/34 Alignment Strategy — github.com/trugurpala/pinescriptv6
// Author: Ugur Pala · mail@ugurpala.com
strategy("Triple EMA Strategy [trugurpala]",
    overlay=true, initial_capital=10000,
    default_qty_type=strategy.percent_of_equity, default_qty_value=10,
    commission_type=strategy.commission.percent, commission_value=0.1)

// ── Inputs ───────────────────────────────────────────────────────────────────
int   e1Len  = input.int(5,  "EMA 1", minval=1)
int   e2Len  = input.int(13, "EMA 2", minval=1)
int   e3Len  = input.int(34, "EMA 3", minval=1)
int   atrLen = input.int(14, "ATR",   minval=1)
float slMult = input.float(1.5, "SL Mult", step=0.1)
float tpMult = input.float(2.5, "TP Mult", step=0.1)

// ── Calculations ─────────────────────────────────────────────────────────────
float ema1   = ta.ema(close, e1Len)
float ema2   = ta.ema(close, e2Len)
float ema3   = ta.ema(close, e3Len)
float atrVal = ta.atr(atrLen)
bool  bullAlign  = ema1 > ema2 and ema2 > ema3
bool  bearAlign  = ema1 < ema2 and ema2 < ema3
bool  prevBull   = ema1[1] > ema2[1] and ema2[1] > ema3[1]
bool  prevBear   = ema1[1] < ema2[1] and ema2[1] < ema3[1]
bool  longEntry  = bullAlign and not prevBull
bool  shortEntry = bearAlign and not prevBear

// ── Entries ──────────────────────────────────────────────────────────────────
if longEntry
    strategy.entry("Long", strategy.long)
    strategy.exit("Long Exit", "Long", stop=close - slMult * atrVal, limit=close + tpMult * atrVal)
if shortEntry
    strategy.entry("Short", strategy.short)
    strategy.exit("Short Exit", "Short", stop=close + slMult * atrVal, limit=close - tpMult * atrVal)
if strategy.position_size > 0 and not bullAlign
    strategy.close("Long")
if strategy.position_size < 0 and not bearAlign
    strategy.close("Short")

// ── Visuals ──────────────────────────────────────────────────────────────────
plot(ema1, "EMA 5",  bullAlign ? color.green : bearAlign ? color.red    : color.gray, linewidth=1)
plot(ema2, "EMA 13", bullAlign ? color.lime  : bearAlign ? color.orange : color.gray, linewidth=2)
plot(ema3, "EMA 34", bullAlign ? color.teal  : bearAlign ? color.maroon : color.gray, linewidth=3)
bgcolor(bullAlign ? color.new(color.green, 94) : bearAlign ? color.new(color.red, 94) : na)

Overview

Triple EMA Strategy [trugurpala] enters a long position when all three EMAs align in ascending order and enters short when they align in descending order. Positions are managed with ATR-based stop-loss and take-profit orders or closed early when the moving average alignment dissolves. Plotted directly on the price chart, it displays the three moving averages dynamically colored by alignment state and highlights active trend regimes with background tinting.

Details

Published by

trugurpala on GitHub

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Trend, Moving averages

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

aialgorithmic-tradingclaude-codecodexcoding-agentsgithub-copilotopen-sourcepine-scriptpine-script-v6technical-analysis

Settings

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

SettingTypeDefaultVariable
EMA 1int5e1Len
EMA 2int13e2Len
EMA 3int34e3Len
ATRint14atrLen
SL Multfloat1.5slMult
TP Multfloat2.5tpMult
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

Doge SMA

by hackingthemarkets
474 stars

Doge SMA is a long-only moving-average crossover strategy drawn on the price chart. It calculates a fast and a slow simple moving average of close and enters a long position when the fast average crosses above the slow average, but only inside a user-defined s

Strategy v4 TrendMoving averages
Updated 4 years ago · None stated GitHub repository of Doge SMA

This strategy calculates and plots a fast Exponential Moving Average (EMA) and a slow EMA directly on the main price chart. It enters long trades when the fast EMA crosses above the slow EMA and exits when the fast EMA crosses below the slow EMA. Inputs allow

Strategy v6 TrendMoving averages
Updated today · AGPL-3.0 GitHub repository of Forven S01508 — Simple EMA20/50 Cross
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
257 stars

This strategy calculates dynamic support and resistance levels using pivot highs and lows alongside a custom smoothed trend filter and a 3-period EMA. It identifies entry opportunities when price breaks out relative to the trend filter and short-term EMA cross

Strategy v5 TrendSupport & resistance Repaints
Updated 6 weeks ago · None stated GitHub repository of 30s - ES 1m Strategy Candle Bar

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