OPEN-SOURCE SCRIPT
Atualizado

MA Trend Ribbon

1 809
# MA Trend Ribbon

## Overview

MA Trend Ribbon is a trend-following overlay that sits directly on the price chart. It draws a band made of six moving-average lines stacked from fastest to slowest. The band fills with color to show whether the market is leaning up or down, and it prints clear BUY and SELL labels at the moments the trend flips. It can also read the entire ribbon from a higher timeframe, so a lower-timeframe chart can be traded in line with the broader trend. The goal is a single, easy-to-read picture of trend direction and the points where that direction changes.

## What It Shows

- **The ribbon** — six moving averages of increasing length, drawn together as a colored band. When the band tilts and expands upward the trend is up; when it rolls over and expands downward the trend is down. A band that pinches flat signals a market with little direction.
- **The color** — the entire ribbon turns one color for an up-trend and another for a down-trend, so direction reads at a glance without studying the individual lines.
- **The labels** — a BUY label marks the bar where the trend turns up, and a SELL label marks the bar where the trend turns down. By default the labels ride the ribbon itself, sitting just outside the band; they can instead be pinned to the price candles. A label always appears on the same bar the ribbon changes color, so the two never disagree.
- **Optional bar coloring** — price bars can be tinted to match the trend for an even faster read.
- **Alerts** — built-in alerts announce each new BUY and SELL so the chart does not have to be watched constantly.

## The Structure Timeframe

The ribbon can be calculated on a timeframe other than the one being viewed. Left blank, it simply uses the chart's own timeframe. Set to a higher timeframe, the whole ribbon — its lines, its color, and its signals — is drawn from that broader view and displayed on the current chart. This makes it possible to watch a fast chart while keeping every reading aligned to a slower, more meaningful trend.

Two things are worth knowing when a higher timeframe is selected. The ribbon will look stepped, because each higher-timeframe value holds flat across the smaller bars until the larger bar completes. And the most recent portion can shift while the current higher-timeframe bar is still forming, settling once that bar closes; the confirm-on-close option keeps alerts from acting before it settles.

## How Direction Is Decided

The ribbon offers two ways to define the trend, chosen from a single setting:

- **Ribbon Flip** — the trend is up while the fastest line sits above the slowest line, and down when it drops below. This waits for the whole ribbon to turn over, giving steadier, less frequent signals.
- **Fastest MA Slope** — the trend is up the moment the fastest line starts rising and down the moment it starts falling. This reacts earlier and produces more signals.

Whichever method is selected controls both the ribbon color and the labels, keeping the visual and the signals in step.

## Choice of Averages

The ribbon is not limited to one style of average. A dropdown selects the type used for all six lines, ranging from smooth-and-steady to fast-and-reactive. Smoother types change direction later but hold trends more calmly. Faster types change direction sooner but shift more often. Because every line uses the same base length regardless of the type chosen, the base length usually deserves a fresh look after switching types, since the same number behaves differently from one average to the next.

The default type is volume-weighted, which leans on the bars that trade the most. On symbols whose data feed does not carry real volume, a volume-weighted average may behave unpredictably; on those markets one of the price-only types is the better choice.

## Optional Polish

Two extra touches can be switched on to make trends easier to judge, and both are off by default so the standard look stays clean:

- **Momentum-scaled ribbon** — the fill grows more solid as the band expands during a strong trend and fades as it compresses in a quiet market, so strong moves stand out and flat stretches recede.
- **Price-to-ribbon fill** — a soft shade fills the gap between price and the ribbon, making pullbacks toward the band easy to spot.

---

## User Inputs

### Structure

- **Structure Timeframe** — the timeframe the entire ribbon is calculated on. Blank uses the chart's own timeframe. A higher selection draws that higher timeframe's ribbon and signals on the current chart. Default is blank.

### Moving Average

- **Source** — the price used for the calculation. Default is the closing price. Other choices include the open, high, low, or an average of these.
- **MA Type** — the style of average used for every line in the ribbon. Ten options are available, from the smoothest and steadiest to the fastest and most reactive: Simple, Exponential, Weighted, Hull, Wilder's, Volume-Weighted, Double Exponential, Triple Exponential, Arnaud Legoux, and Least Squares. Default is Volume-Weighted.
- **Base MA Length** — the length of the fastest line in the ribbon. Smaller values make the whole ribbon quicker to react; larger values make it slower and smoother. Default is 40.
- **Ribbon Spacing** — the amount added to each line's length as the ribbon steps from fastest to slowest. Smaller values pack the six lines into a tight band; larger values spread them apart so the band widens and narrows more dramatically. Default is 8.

### Advanced MA Inputs

These settings apply only to specific average types and are ignored by the rest.

- **ALMA Offset** — applies only when the Arnaud Legoux type is selected. Higher values make that average track price more closely; lower values make it smoother. Default is 0.85.
- **ALMA Sigma** — applies only when the Arnaud Legoux type is selected. Larger values produce a smoother line; smaller values follow price more closely. Default is 6.
- **LSMA Offset** — applies only when the Least Squares type is selected. Shifts that line forward or backward by a set number of bars. Default is 0.

### Signals

- **Signal Trigger** — chooses how the trend is defined, either Ribbon Flip (steadier, later) or Fastest MA Slope (earlier, more frequent). Default is Ribbon Flip.
- **Show Buy/Sell Labels** — turns the BUY and SELL labels on or off. Default is on.
- **Label Position** — chooses where labels sit. Ribbon attaches them to the band, just below the lowest line for a buy and just above the highest for a sell, so they travel with the ribbon. Bar pins them to the candles instead, below the low for a buy and above the high for a sell. Default is Ribbon.
- **Label ATR Offset** — sets how far a label sits from the ribbon in Ribbon mode, scaled to recent price movement so the gap stays consistent in calm and volatile markets. A value of zero places the label right on the band; larger values push it further away. Has no effect in Bar mode. Default is 0.5.
- **Color Bars By Trend** — tints the price bars to match the current trend color. Default is off.
- **Confirm Signals On Bar Close** — when on, alerts wait until a bar has fully closed before firing, so a signal cannot appear and then disappear before the bar finishes. Labels still show while the bar is forming. Default is on.

### Style

- **Bullish Color** — the color of the ribbon and labels during an up-trend.
- **Bearish Color** — the color of the ribbon and labels during a down-trend.
- **Ribbon Fill Transparency** — how see-through the shaded band is, from solid to invisible. Default is 78.
- **Ribbon Line Width** — the thickness of each ribbon line. Default is 1.
- **Label Size** — the text size of the BUY and SELL labels, from tiny to large. Default is Normal.

### Visual Polish

- **Momentum-Scaled Ribbon** — when on, the fill grows more solid as the ribbon expands and fades as it compresses, so trend strength is reflected in the shading. Default is off.
- **Strong-Trend Fill Transparency** — the solidity of the fill at full ribbon expansion when the scaling above is on. Lower is more solid. Default is 38.
- **Momentum Normalization Length** — how many bars are used to judge how wide the ribbon is now compared with its recent range. Shorter values react faster to changes in strength; longer values give a steadier scale. Default is 100.
- **Fill Price To Ribbon** — shades the gap between price and the ribbon to highlight pullbacks. Default is off.
- **Price Fill Transparency** — how subtle that price-to-ribbon shading is. Higher is fainter. Default is 88.

---

## Best Use

The ribbon works best as a trend filter rather than a stand-alone entry system. Trends are followed most cleanly when trades lean in the direction of the ribbon color, using the labels to mark the turning points. Reading the ribbon from a higher Structure Timeframe while entering on a faster chart is a natural way to keep trades aligned with the larger trend. In quiet, sideways markets the ribbon will change color back and forth and produce more frequent, less reliable signals; the Ribbon Flip setting and a wider spacing reduce this, at the cost of later entries. Faster average types and tighter spacing suit active, short-term charts, while smoother types and wider spacing suit calmer, longer-term views.
Notas de Lançamento
# MA Trend Ribbon — Update Summary

## Selectable Average Type

The ribbon is no longer tied to a single kind of moving average. A dropdown now chooses the style used for all six lines, with ten options ranging from smooth and steady to fast and reactive. The default is the volume-weighted average, which leans on the bars that trade the most.

## Structure Timeframe

A timeframe selector at the top now lets the whole ribbon be calculated from a higher timeframe and shown on the current chart. Left blank, it uses the chart's own timeframe. Set higher, a faster chart can be viewed while the ribbon, its color, and its signals all reflect the broader trend.

## Signal and Label Controls

The buy and sell signals gained several controls. The trend can be defined either by the full ribbon flipping over or by the fastest line simply turning, whichever is preferred. Labels can sit against the price candles or ride the ribbon itself, and the gap between a label and the ribbon can be adjusted. An option also confirms signals only once a bar has closed, so a signal cannot appear and then vanish before the bar finishes. The label toggle now sits above the trigger setting for a more natural reading order.

## Visual Polish Options

Two optional visual touches are available, both off by default so the standard look stays clean. One makes the ribbon fill grow more solid as a trend strengthens and fade as it weakens. The other shades the gap between price and the ribbon to make pullbacks easier to spot.

## Info Box

A summary box has been added to the chart. It shows the current trend at the top in bold, colored to match the ribbon, followed by the key settings in the same order they appear in the settings panel: timeframe, price source, average type, lengths, and signal mode. Larger detail levels add the most recent signal, how many bars have passed since the last trend change, whether the ribbon is expanding or compressing, and a trend-strength reading.

The box is fully adjustable. Its amount of detail, position, and text size can be set, along with the background, header background, text color, label color, and border color. When the buy and sell labels are switched off, the signal line in the box reads "Off."

## Default Settings

The out-of-the-box configuration was tuned for a steadier, general-purpose read:

- Average type set to volume-weighted.
- Base length set to 40 and spacing set to 8, giving a wider, calmer band.
- Labels positioned on the ribbon.
- Info box shown in the top-right corner, at medium detail with small text.
- Both optional visual touches left off.
Notas de Lançamento
- **Added a separate Base line width input.** Previously a single "Ribbon Line Width" input controlled all six ribbon lines at once. Now the fastest (innermost) line has its own independent width control.
- **Repurposed the existing width input.** "Ribbon Line Width" now governs only the outer five lines (MA 2 through MA 6), and its tooltip was updated to reflect that.

**New / modified user inputs**

Both live in the **Style** group:

- **Base Line Width** — new input. Sets the pixel width of the fastest (innermost) ribbon line on its own. Range 1–4, **defaults to 3**.
- **Ribbon Line Width** — existing input, now narrower in scope. Sets the pixel width of the remaining ribbon lines (MA 2 through MA 6). Range 1–4, defaults to 1.

**Under the hood**

- The `p1` plot (MA 1, fastest) now uses `linewidth=baseLineWidth`.
- The `p2`–`p6` plots still use `linewidth=lineWidth`.
- Nothing else was touched — fills, signals, bar coloring, alerts, and the info box are all unaffected.

**Net effect**

Out of the box, the Base line now renders at 3px while the other five lines stay at 1px, giving the innermost line visual prominence. Both values remain independently adjustable from 1 to 4.

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.