Indicator · Pine Script v6 · On the chart

Multi-Trend

by lunarticktrading· code credited to gambcl

This indicator draws a combined trend overlay on the price chart.

View on GitHub

GitHub stars7on the repository
Pine versionv6current
Lines of code169
Settings23inputs
LicenceNone statedfile: MPL-2.0
Last update2 weeks ago10 Oct 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 indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

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

Multi-Trend.txt
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © gambcl

//@version=6
indicator("Multi-Trend", overlay = true, behind_chart = true, explicit_plot_zorder = true)


////////////////////////////////////////////////////////////////////////////////////////////////////
// Version History
////////////////////////////////////////////////////////////////////////////////////////////////////
// v0.1.0
// - Initial release
////////////////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////////////////////
// Imports
////////////////////////////////////////////////////////////////////////////////////////////////////

import gambcl/LunarTick/1


////////////////////////////////////////////////////////////////////////////////////////////////////
// Constants
////////////////////////////////////////////////////////////////////////////////////////////////////

var SUPERTREND_GROUP = "SUPERTREND"
var MACLOUD_GROUP = "MOVING-AVERAGE CLOUD"
var VIDYA_GROUP = "VIDYA"
var DISPLAY_GROUP = "DISPLAY"
var DEVELOPER_GROUP = "DEVELOPER"


////////////////////////////////////////////////////////////////////////////////////////////////////
// Enums
////////////////////////////////////////////////////////////////////////////////////////////////////

enum MAType
    sma = "SMA"
    ema = "EMA"

enum VersionEnum
    version = "v0.1.0"
    

////////////////////////////////////////////////////////////////////////////////////////////////////
// Inputs
////////////////////////////////////////////////////////////////////////////////////////////////////

// Trend
i_bullish_color = input.color(color.green, "Bullish", display = display.none)
i_bearish_color = input.color(color.red, "Bearish", display = display.none)

// SuperTrend
i_supertrend_enabled = input.bool(true, "Enable SuperTrend", group = SUPERTREND_GROUP, display = display.none)
i_supertrend_show = input.bool(false, "Show SuperTrend", group = SUPERTREND_GROUP, display = display.none, active = i_supertrend_enabled)
i_supertrend_atr_period = input.int(21, "ATR Length", minval = 1, group = SUPERTREND_GROUP, display = display.none, active = i_supertrend_enabled)
i_supertrend_factor = input.float(3.0, "Factor", minval = 0.01, step = 0.01, group = SUPERTREND_GROUP, display = display.none, active = i_supertrend_enabled)
i_supertrend_fill_transparency = input.int(90, "Fill Transparency", minval = 0, maxval = 100, group = SUPERTREND_GROUP, display = display.none, active = i_supertrend_enabled)

// MA Cloud
i_macloud_enabled = input.bool(true, "Enable Moving-Average Cloud", group = MACLOUD_GROUP, display = display.none)
i_macloud_show = input.bool(true, "Show Moving-Average Cloud", group = MACLOUD_GROUP, display = display.none, active = i_macloud_enabled)
i_macloud_fast_length = input.int(8, "Fast Length", minval = 1, group = MACLOUD_GROUP, display = display.none, active = i_macloud_enabled)
i_macloud_slow_length = input.int(24, "Slow Length", minval = 1, group = MACLOUD_GROUP, display = display.none, active = i_macloud_enabled)
i_macloud_type = input.enum(MAType.ema, "Type", group = MACLOUD_GROUP, display = display.none, active = i_macloud_enabled)
i_macloud_fast_transparency = input.int(0, "Fast Transparency", minval = 0, maxval = 100, group = MACLOUD_GROUP, display = display.none, active = i_macloud_enabled)
i_macloud_slow_transparency = input.int(100, "Slow Transparency", minval = 0, maxval = 100, group = MACLOUD_GROUP, display = display.none, active = i_macloud_enabled)
i_macloud_transparency = input.int(60, "Cloud Transparency", minval = 0, maxval = 100, group = MACLOUD_GROUP, display = display.none, active = i_macloud_enabled)

// VIDYA
i_vidya_enabled = input.bool(true, "Enable VIDYA", group = VIDYA_GROUP, display = display.none)
i_vidya_show = input.bool(false, "Show VIDYA", group = VIDYA_GROUP, display = display.none)
i_vidya_length = input.int(21, "Length", minval = 1, group = VIDYA_GROUP, display = display.none, active = i_vidya_enabled)
i_vidya_fill_transparency = input.int(90, "Fill Transparency", minval = 0, maxval = 100, group = VIDYA_GROUP, display = display.none, active = i_vidya_enabled)

// Display
i_show_labels = input.bool(true, "Show Labels", group = DISPLAY_GROUP, display = display.none)
i_trend_background_enabled = input.bool(true, "Show Trend Background", group = DISPLAY_GROUP, display = display.none)
i_trend_background_transparency = input.int(90, "Trend Background Transparency", minval = 0, maxval = 100, group = DISPLAY_GROUP, display = display.none, active = i_trend_background_enabled)

// Developer
VersionEnum i_version = input.enum(VersionEnum.version, "Version", display = display.none, group = DEVELOPER_GROUP)

var num_indicators = 0
     + (i_supertrend_enabled ? 1 : 0)
     + (i_macloud_enabled ? 1 : 0)
     + (i_vidya_enabled ? 1 : 0)

var LunarTick.TrendDirection trend_direction = LunarTick.TrendDirection.neutral

int trend_score = 0


////////////////////////////////////////////////////////////////////////////////////////////////////
// SuperTrend
////////////////////////////////////////////////////////////////////////////////////////////////////

[supertrend, direction] = ta.supertrend(i_supertrend_factor, i_supertrend_atr_period)
supertrend := barstate.isfirst ? na : supertrend
plot_supertrend_up = plot(direction < 0 ? supertrend : na, "SuperTrend Up", i_bullish_color, 2, plot.style_linebr, display = i_supertrend_enabled and i_supertrend_show ? display.pane : display.none)
plot_supertrend_down = plot(direction < 0 ? na : supertrend, "SuperTrend Down", i_bearish_color, 2, plot.style_linebr, display = i_supertrend_enabled and i_supertrend_show ? display.pane : display.none)
body_middle = plot(barstate.isfirst ? na : (open + close) / 2, "Body Middle", display = display.none)
fill(body_middle, plot_supertrend_up,   title = "Uptrend background",   color = color.new(color.green, i_supertrend_fill_transparency), fillgaps = false, display = i_supertrend_enabled and i_supertrend_show ? display.all : display.none)
fill(body_middle, plot_supertrend_down, title = "Downtrend background", color = color.new(color.red,   i_supertrend_fill_transparency), fillgaps = false, display = i_supertrend_enabled and i_supertrend_show ? display.all : display.none)
trend_score += (i_supertrend_enabled ? ((direction < 0) ? 1 : -1) : 0)


////////////////////////////////////////////////////////////////////////////////////////////////////
// Moving-Average Cloud
////////////////////////////////////////////////////////////////////////////////////////////////////

ma_fast = (i_macloud_type == MAType.sma) ? ta.sma(close, i_macloud_fast_length) : ta.ema(close, i_macloud_fast_length)
ma_slow = (i_macloud_type == MAType.sma) ? ta.sma(close, i_macloud_slow_length) : ta.ema(close, i_macloud_slow_length)
ma_color = (ma_fast > ma_slow) ? i_bullish_color : i_bearish_color

plot_ma_fast = plot(i_macloud_enabled ? ma_fast : na, "Fast MA", color = color.new(ma_color, i_macloud_fast_transparency), linewidth = 2, display = i_macloud_enabled and i_macloud_show ? display.pane : display.none)
plot_ma_slow = plot(i_macloud_enabled ? ma_slow : na, "Slow MA", color = color.new(ma_color, i_macloud_slow_transparency), linewidth = 2, display = i_macloud_enabled and i_macloud_show ? display.pane : display.none)
fill(plot_ma_fast, plot_ma_slow, color.new(ma_color, i_macloud_transparency), "MA Cloud", display = i_macloud_enabled and i_macloud_show ? display.all : display.none)
trend_score += (i_macloud_enabled ? ((ma_fast > ma_slow) ? 1 : -1) : 0)


////////////////////////////////////////////////////////////////////////////////////////////////////
// VIDYA
////////////////////////////////////////////////////////////////////////////////////////////////////

chande_momentum_oscillator(source, int length) =>
    mom = ta.change(source)
    up_sum = math.sum(math.max(mom, 0), length)
    down_sum = math.sum(-math.min(mom, 0), length)
    (up_sum - down_sum) / (up_sum + down_sum)

cmo = math.abs(chande_momentum_oscillator(close, i_vidya_length))
alpha = 2 / (i_vidya_length + 1)

vidya = 0.0
vidya := close * alpha * cmo + nz(vidya[1]) * (1 - alpha * cmo)

vidya_color = (vidya[0] > vidya[1]) ? i_bullish_color : i_bearish_color
plot_vidya = plot(i_vidya_enabled ? vidya : na, "VIDYA", vidya_color, 3, display = i_vidya_enabled and i_vidya_show ? display.pane : display.none)
fill(plot_vidya, body_middle, color.new(vidya_color, i_vidya_fill_transparency), "VIDYA Fill", display = i_vidya_enabled and i_vidya_show ? display.all : display.none)
trend_score += (i_vidya_enabled ? ((vidya[0] > vidya[1]) ? 1 : -1) : 0)


////////////////////////////////////////////////////////////////////////////////////////////////////
// Detect Trend Change
////////////////////////////////////////////////////////////////////////////////////////////////////

var color bg_color = na
if trend_score == num_indicators
    trend_direction := LunarTick.TrendDirection.bullish
    bg_color := i_bullish_color
else if trend_score == -num_indicators
    trend_direction := LunarTick.TrendDirection.bearish
    bg_color := i_bearish_color

bgcolor(i_trend_background_enabled ? color.new(bg_color, i_trend_background_transparency) : na, title = "Background")

if barstate.isconfirmed 
    if trend_direction == LunarTick.TrendDirection.bullish and trend_direction[1] != LunarTick.TrendDirection.bullish
        alert("Trend flipped Bullish on " + syminfo.ticker + " " + LunarTick.format_timeframe_period(timeframe.period))
        if i_show_labels
            y = math.min(low, i_supertrend_enabled and i_supertrend_show ? supertrend : low, i_macloud_enabled and i_macloud_show ? ma_slow : low, i_vidya_enabled and i_vidya_show ? vidya : low)
            label.new(bar_index, y, "Bullish", xloc.bar_index, yloc.price, i_bullish_color, label.style_label_up, color.white, size.normal, text.align_center)
    else if trend_direction == LunarTick.TrendDirection.bearish and trend_direction[1] != LunarTick.TrendDirection.bearish
        alert("Trend flipped Bearish on " + syminfo.ticker + " " + LunarTick.format_timeframe_period(timeframe.period))
        if i_show_labels
            y = math.max(high, i_supertrend_enabled and i_supertrend_show ? supertrend : high, i_macloud_enabled and i_macloud_show ? ma_slow : high, i_vidya_enabled and i_vidya_show ? vidya : high)
            label.new(bar_index, y, "Bearish", xloc.bar_index, yloc.price, i_bearish_color, label.style_label_down, color.white, size.normal, text.align_center)

Overview

Multi-Trend can enable a SuperTrend based on ATR length and a factor, a fast and slow moving-average cloud using SMA or EMA, and a VIDYA line. Separate switches control whether each component is calculated and whether it is shown, along with fill and line transparency. Bullish and bearish colors, optional labels, and a trend background mark direction. No market or timeframe is specified, and the excerpt does not define entry or exit rules.

Details

Published by

lunarticktrading on GitHub

Code credit

gambcl, as written in the script's header

Draws

On the price chart

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.

Settings

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

SettingTypeDefaultVariable
Bullishcolorcolor.greeni_bullish_color
Bearishcolorcolor.redi_bearish_color
Enable SuperTrendbooltruei_supertrend_enabled
Show SuperTrendboolfalsei_supertrend_show
ATR Lengthint21i_supertrend_atr_period
Factorfloat3.0i_supertrend_factor
Fill Transparencyint90i_supertrend_fill_transparency
Enable Moving-Average Cloudbooltruei_macloud_enabled
Show Moving-Average Cloudbooltruei_macloud_show
Fast Lengthint8i_macloud_fast_length
Slow Lengthint24i_macloud_slow_length
TypeenumMAType.emai_macloud_type
Show all 23 settings
SettingTypeDefaultVariable
Fast Transparencyint0i_macloud_fast_transparency
Slow Transparencyint100i_macloud_slow_transparency
Cloud Transparencyint60i_macloud_transparency
Enable VIDYAbooltruei_vidya_enabled
Show VIDYAboolfalsei_vidya_show
Lengthint21i_vidya_length
Fill Transparencyint90i_vidya_fill_transparency
Show Labelsbooltruei_show_labels
Show Trend Backgroundbooltruei_trend_background_enabled
Trend Background Transparencyint90i_trend_background_transparency
VersionenumVersionEnum.versioni_version
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

318 stars

This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods. It fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes B

Indicator v5 Moving averagesTrend
Updated 2 months ago · MIT GitHub repository of Multiple Moving Averages

NVDA Trend Ribbon

by longsurf-ai
280 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated 3 days ago · MIT GitHub repository of NVDA Trend Ribbon

Bollinger Bands Force

by harryguiacorn
220 stars

This indicator modifies standard Bollinger Bands to measure directional trend force based on line alignment. It calculates a simple moving average basis along with upper and lower volatility bands. When all three lines move upward or downward simultaneously, i

Indicator v5 Volatility & bandsTrend
Updated 1 year ago · None stated GitHub repository of Bollinger Bands Force

Adaptive MA Slope

by capissimo
114 stars

This indicator calculates Kaufman's Adaptive Moving Average (KAMA) on a chosen price source and determines trend direction based on the slope across a configurable lookback window. Signals can be filtered by short-term volatility expansion using ATR comparison

Indicator v4 Moving averagesTrend
Updated 1 year ago · None stated GitHub repository of Adaptive MA Slope

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers