Skip to main content

EMA Ribbon 8/21/55 — Pine Script v5 strategy

TRENDEMAPine Script v5

This script computes three exponential moving averages on close and enters long only when they are stacked in order. It exits the position when the fast average crosses back under the medium one.

Full code (free to copy)

//@version=5
strategy("EMA Ribbon", overlay=true)
ema1 = ta.ema(close, 8)
ema2 = ta.ema(close, 21)
ema3 = ta.ema(close, 55)
if (ema1 > ema2 and ema2 > ema3)
    strategy.entry("Long", strategy.long)
if (ema1 < ema2)
    strategy.close("Long")

Judge this code on BTCUSDT 1D →Free, in your browser, on the same candles as the table below.

Online judge verdict on BTCUSDT (measured 29 November 2026)

TimeframeSealed periodTradesReturnBuy & holdVerdict
1d2024-12-17 → 2026-10-1611-7.78 %-23.25 %No evidence of an edge
4h2026-03-12 → 2026-10-17215.06 %15.83 %Inconclusive
1h2026-08-05 → 2026-10-173114.26 %27.14 %No evidence of an edge

Past data, 10 bps per fill, last 20% of the bars sealed. Windows: full history on 1d, last 3 years on 4h, last year on 1h. Research, not advice: no result is promised.

Measured on 29 November 2026 with the online judge’s Pine v5 engine (sa-pine-vm 0.2.1), on Binance BTCUSDT candles up to 16/10/2026 on 1D and up to 17/10/2026 on 4h and 1h. Differences with TradingView’s Strategy Tester remain possible. Binance data, CC BY-NC-SA 4.0.

Open this code in the free judge (1 click) →

Replay each verdict yourself, in your browser: 1d · 4h · 1h. The script is filled in; nothing runs until you click “Judge”.

How the script works

The first lines compute three exponential moving averages on close: ta.ema(close, 8), ta.ema(close, 21) and ta.ema(close, 55), stored in ema1, ema2 and ema3. The script runs on every bar, so each value updates at the close of that bar. These three series are the only inputs of the rule: no volume, no other indicator and no higher timeframe data is read.

The entry block tests ema1 > ema2 and ema2 > ema3, which means the fast average sits above the medium one, and the medium above the slow one. When both comparisons are true on a bar, the script calls strategy.entry with the id Long and direction strategy.long. The order is filled at the next bar open by default, and the default pyramiding setting keeps a single long position.

The exit block checks a single condition: ema1 < ema2. As soon as the fast EMA drops below the medium EMA, strategy.close is called with the id Long and the position is closed. The test does not require ema2 to be above ema3, so the exit can fire even while the three averages remain ordered. The script defines no stop loss, no take profit and no short side.

Parameters in the code

ParameterValueRole
ema1ta.ema(close, 8)Fast exponential moving average on close, the first series compared in both blocks.
ema2ta.ema(close, 21)Medium exponential moving average, it must sit below ema1 to allow the entry and above ema1 to allow the exit.
ema3ta.ema(close, 55)Slow exponential moving average, it only takes part in the entry filter.
entry conditionema1 > ema2 and ema2 > ema3Both comparisons must be true on the same bar before an order is sent.
entry orderstrategy.entry("Long", strategy.long)Submits a long market order with the id Long while the alignment holds.
exit conditionema1 < ema2Closes the open long as soon as the fast average crosses below the medium one.
exit orderstrategy.close("Long")Closes the position attached to the id Long, at the next bar open by default.
overlaytrueThe strategy is drawn on the price chart instead of a separate pane.
stop loss and take profitnoneNo risk exit is coded; the only exit is the EMA condition.
short sidenoneNo short entry is coded, the strategy is long only.

Known limits of this rule

Before you trust it: test it on data it never saw

A backtest in TradingView's Strategy Tester shows one past path with the settings you picked. Strategy Arena Lab (free, Windows and Linux) replays this Pine on your PC, compares its trades one by one with TradingView's for supported Pine, counts the variants you try, then judges the rule on a period kept sealed during the search: survives, no evidence of an edge or inconclusive.

Get the free Lab →

FAQ

Does it work on crypto?

The code only reads close and the ta.ema function, so it can be applied to crypto pairs, forex or indices on any timeframe. Behaviour differs by market, and you can replay it on a period you have never seen in Strategy Arena Lab, which is free.

How do I add a stop loss?

The script has no stop: the only exit is ema1 < ema2. You can add strategy.exit("Exit", "Long", stop=...) after the entry call, or extend the existing exit block with a second closing condition.

Other free Pine Script v5 strategies

RSI Mean ReversionEMA Crossover 9/21Bollinger Band BounceMACD MomentumSuperTrendStochastic RSIATR BreakoutVWAP BounceRSI + EMA ComboFaber 10-Month TimingGolden Cross SMA 50/200Bollinger Squeeze BreakoutKeltner Channel Breakout 20/1.5Donchian Turtle 20/10ADX 25 & DMI 14 TrendParabolic SAR 0.02/0.2Hull Moving Average 55ALMA 20 Gaussian TrendCCI 20 (+100) BreakoutMoney Flow Index MFI 14 (20/80)ATR 14 Chandelier StopIchimoku Tenkan 9 / Kijun 26Linear Regression 20ROC 14 + EMA 200 FilterWilliams %R 14 PullbackNo-Leak Weekly EMA FilterPivot High/Low BreakoutAI-style ATR Breakout + EMA 200
TradingView Starter
Choose the account path. Prove the strategy separately.
Your first chart and price alert do not require the Lab. Strategy Arena proof remains required before trusting or exporting a strategy.
Partner attribution is for first-time users and web purchases only. Strategy Arena may earn a commission on eligible purchases; starting with a free account needs no payment.
I have never had an account · Start free I already have an account Check a strategy
More TradingView paths
Evidence-gated Pine review

Educational code on past data. No investment advice; no result is promised.