top of page

Pine Script Library

Public·1 member

Multi-Period EMA Cloud — Trend Drop


The Multi-Period EMA Cloud stacks three EMA-pair clouds (fast, mid, macro) into one overlay so trend health is visible at a glance instead of cluttering the chart with raw moving averages. When all three clouds agree, you get an unambiguous "full bull" or "full bear" regime — when they disagree, you know to size down.


## What it does

- Plots four EMAs (default 8 / 21 / 55 / 200) and shades three clouds between them via Pine's `fill()`.

- Cloud color flips green/red on each pair's cross — fast = short-term momentum, mid = swing trend, macro = regime.

- Full-stack regime label pinned to the last bar shows FULL BULL / FULL BEAR / MIXED with the current EMA lengths.

- Optional `bgcolor` tint highlights bars where all three clouds agree.

- `alertcondition` lines for full-stack flips and the short-term (EMA1/EMA2) cross.


## Recommended settings

- EMA lengths: 8 / 21 / 55 / 200 (default)

- Source: close

- Show all three clouds: on

- Regime label: on

- Background tint: on

- Faster scalping variant: 5 / 13 / 34 / 89

- Slower swing variant: 10 / 30 / 100 / 200


## Ideal timeframe

Works on any timeframe; the default 8/21/55/200 stack is tuned for 15m–1D charts.


## How to use

Treat the clouds as a regime filter rather than a signal generator. When the macro (3-4) cloud is green and the mid (2-3) cloud is also green, only take long setups — let the fast (1-2) cloud time entries on pullbacks into it. Counter-trend trades become legitimate only when the macro cloud flips or when the mid cloud loses agreement. The full-stack alert is your "trend just confirmed in earnest" signal; the short-term flip alert is your early-warning that the underlying momentum is rotating.


## Pine Script v5 code

```

//@version=5

// ─────────────────────────────────────────────

// │ MarketFragments.com | DNA & Market │

// │ info@marketfragments.com │

// │ www.marketfragments.com │

// ─────────────────────────────────────────────

// Time →

// │

// █ █ █│ █

// █ █ █ │ █ █

// █ █ █ │ █ █ █ ╭─╮

// █ █ █ │ █ █ █ █ ╭─╯ ╰─╮

// █ █ █ │ █ █ █ █ █ █ ╭─╯ ╰─╮

// █ █ █ │ █ █ █ █ █ █ █ █ ╭─╯ ╰─╮

// █ █ █ │ █ █ █ █ █ █ █ █ █ █╭─╯ ╰─╮

// █ █ █ │ █ █ █ █ █ █ █ █ ╰─╮ ╭─╯

// █ █ █ │ █ █ █ █ █ █ ╰─╮ ╭─╯

// █ █ █ │ █ █ █ █ ╰─╮ ╭─╯

// █ █ █ │ █ █ ╰─╮ ╭─╯

// █ █ █ │ █ ╰─────╯

// ──────┴──────────────────────────────────────────────────────────────

// T1 T2 T3 T4 T5 T6

//

// Multi-Period EMA Cloud

// Three stacked EMA-pair clouds (fast/mid/slow) give a layered, color-coded read

// on short, intermediate, and macro trend in a single overlay. Cloud color flips

// when the faster EMA crosses the slower one within the pair; full bull / full

// bear regime is signaled when ALL three pairs agree.

// Free for non-commercial use. (c) MarketFragments.com


indicator("MF Multi-Period EMA Cloud", shorttitle="MF EMA Cloud", overlay=true, max_labels_count=50)


ema1Length = input.int(8, "EMA 1 (fast)", minval=1)

ema2Length = input.int(21, "EMA 2", minval=1)

ema3Length = input.int(55, "EMA 3", minval=1)

ema4Length = input.int(200, "EMA 4 (slow)", minval=1)

showCloud12 = input.bool(true, "Show Cloud 1<->2 (fast)")

showCloud23 = input.bool(true, "Show Cloud 2<->3 (mid)")

showCloud34 = input.bool(true, "Show Cloud 3<->4 (macro)")

showLabel = input.bool(true, "Show Regime Label")

bgTint = input.bool(true, "Background Tint on Full Stack")

src = input.source(close, "Source")


ema1 = ta.ema(src, ema1Length)

ema2 = ta.ema(src, ema2Length)

ema3 = ta.ema(src, ema3Length)

ema4 = ta.ema(src, ema4Length)


p1 = plot(ema1, color=color.new(color.white, 0), linewidth=1, title="EMA 1")

p2 = plot(ema2, color=color.new(color.yellow, 0), linewidth=2, title="EMA 2")

p3 = plot(ema3, color=color.new(color.orange, 0), linewidth=2, title="EMA 3")

p4 = plot(ema4, color=color.new(color.fuchsia, 0), linewidth=3, title="EMA 4")


cloud12Bull = ema1 > ema2

cloud23Bull = ema2 > ema3

cloud34Bull = ema3 > ema4


fill(p1, p2, color = showCloud12 ? (cloud12Bull ? color.new(color.green, 70) : color.new(color.red, 70)) : na, title="Cloud 1-2 (fast)")

fill(p2, p3, color = showCloud23 ? (cloud23Bull ? color.new(color.green, 80) : color.new(color.red, 80)) : na, title="Cloud 2-3 (mid)")

fill(p3, p4, color = showCloud34 ? (cloud34Bull ? color.new(color.green, 87) : color.new(color.red, 87)) : na, title="Cloud 3-4 (macro)")


allBull = cloud12Bull and cloud23Bull and cloud34Bull

allBear = not cloud12Bull and not cloud23Bull and not cloud34Bull

regime = allBull ? 1 : allBear ? -1 : 0

regimePrev = nz(regime[1], 0)


bgcolor(bgTint and regime == 1 ? color.new(color.green, 90) :

bgTint and regime == -1 ? color.new(color.red, 90) : na, title="Regime BG")


regimeText = regime == 1 ? "FULL BULL" : regime == -1 ? "FULL BEAR" : "MIXED"

regimeColor = regime == 1 ? color.green : regime == -1 ? color.red : color.gray


var label lbl = na

if showLabel and barstate.islast

label.delete(lbl)

lbl := label.new(bar_index, ema1,

"EMA Cloud: " + regimeText + " [" + str.tostring(ema1Length) + "/" + str.tostring(ema2Length) + "/" + str.tostring(ema3Length) + "/" + str.tostring(ema4Length) + "]",

style=label.style_label_left,

color=color.new(color.black, 60),

textcolor=regimeColor,

size=size.normal)


alertcondition(regime == 1 and regimePrev != 1, title="Full Bull Stack", message="EMA Cloud: Full Bull Stack")

alertcondition(regime == -1 and regimePrev != -1, title="Full Bear Stack", message="EMA Cloud: Full Bear Stack")

alertcondition(cloud12Bull and not cloud12Bull[1], title="Short-Term Bull Flip", message="EMA Cloud: Short-Term Flip Bull (EMA1 > EMA2)")

alertcondition(not cloud12Bull and cloud12Bull[1], title="Short-Term Bear Flip", message="EMA Cloud: Short-Term Flip Bear (EMA1 < EMA2)")

```


Drop your tweaks, screenshots, and questions below — that's how the library gets better.


1 View
Brain with financial data analysis.

Inquiries at :

Important Risk Notice: Trading involves substantial risk of loss. This is educational content only—not advice. Full details here  ------------>  

Proceed only if you're prepared.

tel#: (843) 321-8514

bottom of page