Indicator · Pine Script v6 · On the chart

Algo

by TamTH-Dev· code credited to tamth_

Algo is an overlay indicator that combines Deviation Scaled Moving Averages (DSMA), multi-layer Ripster exponential moving average clouds, and ATR-based trading levels on the price chart.

View on GitHub

Repaints

GitHub stars2on the repository
Pine versionv6current
Lines of code414
Settings40inputs
LicenceNone statedfile: MPL-2.0
Last update5 weeks ago18 Sep 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

414 lines of Pine Script v6 from strategies/strategies2/Algo.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Algo.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tamth_

//@version=6
indicator("Algo", overlay=true, precision=2, max_labels_count=500, max_lines_count=500, max_boxes_count=1000, max_bars_back=1000)


//-----------------------------------------------------------------------------
// Constants
//-----------------------------------------------------------------------------
// Colors
color TRANSPARENT_COLOR = color.new(#000000, 100)
color WHITE_COLOR      = #ffffff
color BLACK_COLOR      = #000000
color RED_COLOR        = #ff006e
color ORANGE_COLOR     = #fb5607
color YELLOW_COLOR     = #ffbe0b
color GREEN_COLOR      = #2a9d8f
color AQUA_COLOR       = #00b4d8
color BLUE_COLOR       = #3a86ff
color PURPLE_COLOR     = #8338ec
color PINK_COLOR       = #df3bf1
color LIGHT_GRAY_COLOR = #212d40
color DARK_GRAY_COLOR  = #212d40
color TEXT_COLOR       = #ced4da

//-----------------------------------------------------------------------------
// Common Variables
//-----------------------------------------------------------------------------
// Bar index and input
series int barIdx = bar_index

//-----------------------------------------------------------------------------
// Common Methods
//-----------------------------------------------------------------------------
// Debug label function
debug(simple string txt) =>
    var label lbl = label.new(barIdx, na, txt, xloc.bar_index, yloc.price, color(na), label.style_none, WHITE_COLOR, size.large, text.align_left)
    label.set_xy(lbl, barIdx, ta.highest(10)[1])
    label.set_text(lbl, txt)

// Calculate period width by percentage
getPrdWidthByPerc(int prd, float perc) => 
    (ta.highest(prd) - ta.lowest(prd)) * perc / 100

//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// DSMAs
//-----------------------------------------------------------------------------
// Settings
//-----------------------------------------------------------------------------
dsmaGrp    = "DSMAs"
dsmaShowed = input.bool(true, title="Show", group=dsmaGrp)
dsmaSrc    = input.source(close, title="Source", group=dsmaGrp)
dsmaTf     = input.timeframe("", title="Timeframe", group=dsmaGrp)
dsma1Len   = input.int(40, title="DSMA 1 Length", group=dsmaGrp)
dsma1Color = input.color(BLUE_COLOR, title="DSMA 1 Color", group=dsmaGrp)
dsma2Len   = input.int(100, title="DSMA 2 Length", group=dsmaGrp)
dsma2Color = input.color(ORANGE_COLOR, title="DSMA 2 Color", group=dsmaGrp)

//-----------------------------------------------------------------------------
// Methods
//-----------------------------------------------------------------------------
// Calculate DSMA
calcDsma(src, len) =>
    filt = 0.0
    dsma = 0.0

    PI = 3.1415926
    a1 = math.exp( -1.414 * PI / (0.5 * len))
    b1 = 2 * a1 * math.cos( 1.414 * PI / ( 0.5 * len))
    c2 = b1
    c3 = -a1 * a1
    c1 = 1 - c2 - c3

    zeros = src - src[2]
    filt := c1 * (zeros + zeros[1]) / 2 + c2 * nz(filt[1]) + c3 * nz(filt[2])
    rm = math.sum(filt * filt, len) 
    rms = math.sqrt(rm / len) 
    scaledFilt = rms != 0 ? filt / rms : 0
    alpha1 = math.abs(scaledFilt) * 5 / len
    dsma := alpha1 * close + (1 - alpha1) * nz(dsma[1])
    dsma

//-----------------------------------------------------------------------------
// Values
//-----------------------------------------------------------------------------
dsma1 = request.security(syminfo.tickerid, dsmaTf, calcDsma(dsmaSrc, dsma1Len))
dsma2 = request.security(syminfo.tickerid, dsmaTf, calcDsma(dsmaSrc, dsma2Len))

//-----------------------------------------------------------------------------
// Render
//-----------------------------------------------------------------------------
plot(dsmaShowed ? dsma1 : na, color=dsma1Color, linewidth=1, display = display.pane, force_overlay = true)
plot(dsmaShowed ? dsma2 : na, color=dsma2Color, linewidth=1, display = display.pane, force_overlay = true)

//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// Ripster EMA Clouds
//-----------------------------------------------------------------------------
// Settings
//-----------------------------------------------------------------------------
ripsterEmaCloudsGrp    = "Ripster EMA Clouds"
ripsterEmaCloudsShowed = input.bool(false, title="Show", group=ripsterEmaCloudsGrp)
ripsterEmaCloudsSrc    = input.source(close, title="Source", group=ripsterEmaCloudsGrp)
ripsterEmaCloudsTf     = input.timeframe("", title="Timeframe", group=ripsterEmaCloudsGrp)
shortEma1Len           = input.int(8, title="Short EMA 1 Length", group=ripsterEmaCloudsGrp)
longEma1Len            = input.int(9, title="Long EMA 1 Length", group=ripsterEmaCloudsGrp)
ema1CloudShowed        = input.bool(true, title="Show EMA Cloud 1", group=ripsterEmaCloudsGrp)
shortEma2Len           = input.int(5, title="Short EMA 2 Length", group=ripsterEmaCloudsGrp)
longEma2Len            = input.int(13, title="Long EMA 2 Length", group=ripsterEmaCloudsGrp)
ema2CloudShowed        = input.bool(true, title="Show EMA Cloud 2", group=ripsterEmaCloudsGrp)
shortEma3Len           = input.int(20, title="Short EMA 3 Length", group=ripsterEmaCloudsGrp)
longEma3Len            = input.int(21, title="Long EMA 3 Length", group=ripsterEmaCloudsGrp)
ema3CloudShowed        = input.bool(true, title="Show EMA Cloud 3", group=ripsterEmaCloudsGrp)
shortEma4Len           = input.int(48, title="Short EMA 4 Length", group=ripsterEmaCloudsGrp)
longEma4Len            = input.int(50, title="Long EMA 4 Length", group=ripsterEmaCloudsGrp)
ema4CloudShowed        = input.bool(true, title="Show EMA Cloud 4", group=ripsterEmaCloudsGrp)
shortEma5Len           = input.int(180, title="Short EMA 5 Length", group=ripsterEmaCloudsGrp)
longEma5Len            = input.int(200, title="Long EMA 5 Length", group=ripsterEmaCloudsGrp)
ema5CloudShowed        = input.bool(true, title="Show EMA Cloud 5", group=ripsterEmaCloudsGrp)

//-----------------------------------------------------------------------------
// Values
//-----------------------------------------------------------------------------
shortEma1 = request.security(syminfo.tickerid, ripsterEmaCloudsTf, ta.ema(ripsterEmaCloudsSrc, shortEma1Len))
longEma1  = request.security(syminfo.tickerid, ripsterEmaCloudsTf, ta.ema(ripsterEmaCloudsSrc, longEma1Len))
shortEma2 = request.security(syminfo.tickerid, ripsterEmaCloudsTf, ta.ema(ripsterEmaCloudsSrc, shortEma2Len))
longEma2  = request.security(syminfo.tickerid, ripsterEmaCloudsTf, ta.ema(ripsterEmaCloudsSrc, longEma2Len))
shortEma3 = request.security(syminfo.tickerid, ripsterEmaCloudsTf, ta.ema(ripsterEmaCloudsSrc, shortEma3Len))
longEma3  = request.security(syminfo.tickerid, ripsterEmaCloudsTf, ta.ema(ripsterEmaCloudsSrc, longEma3Len))
shortEma4 = request.security(syminfo.tickerid, ripsterEmaCloudsTf, ta.ema(ripsterEmaCloudsSrc, shortEma4Len))
longEma4  = request.security(syminfo.tickerid, ripsterEmaCloudsTf, ta.ema(ripsterEmaCloudsSrc, longEma4Len))
shortEma5 = request.security(syminfo.tickerid, ripsterEmaCloudsTf, ta.ema(ripsterEmaCloudsSrc, shortEma5Len))
longEma5  = request.security(syminfo.tickerid, ripsterEmaCloudsTf, ta.ema(ripsterEmaCloudsSrc, longEma5Len))

cloudcolour1 = shortEma1 >= longEma1 ? AQUA_COLOR : RED_COLOR
cloudcolour2 = shortEma2 >= longEma2 ? AQUA_COLOR : RED_COLOR
cloudcolour3 = shortEma3 >= longEma3 ? PINK_COLOR : YELLOW_COLOR
cloudcolour4 = shortEma4 >= longEma4 ? GREEN_COLOR : PURPLE_COLOR
cloudcolour5 = shortEma5 >= longEma5 ? BLUE_COLOR : ORANGE_COLOR

isUp = ta.crossover(longEma2, shortEma4)
isDn = ta.crossunder(longEma2, shortEma4)

//-----------------------------------------------------------------------------
// Render
//-----------------------------------------------------------------------------
shortEma1Line = plot(ripsterEmaCloudsShowed and ema1CloudShowed ? shortEma1 : na, color=na, linewidth=1, title="Short EMA 1", display = display.pane)
shortEma2Line = plot(ripsterEmaCloudsShowed and ema2CloudShowed ? shortEma2 : na, color=na, linewidth=1, title="Short EMA 2", display = display.pane)
shortEma3Line = plot(ripsterEmaCloudsShowed and ema3CloudShowed ? shortEma3 : na, color=na, linewidth=1, title="Short EMA 3", display = display.pane)
shortEma4Line = plot(ripsterEmaCloudsShowed and ema4CloudShowed ? shortEma4 : na, color=na, linewidth=1, title="Short EMA 4", display = display.pane)
shortEma5Line = plot(ripsterEmaCloudsShowed and ema5CloudShowed ? shortEma5 : na, color=na, linewidth=1, title="Short EMA 5", display = display.pane)

longEma1Line = plot(ripsterEmaCloudsShowed and ema1CloudShowed ? longEma1 : na, color=na, linewidth=1, title="Long EMA 1", display = display.pane)
longEma2Line = plot(ripsterEmaCloudsShowed and ema2CloudShowed ? longEma2 : na, color=na, linewidth=1, title="Long EMA 2", display = display.pane)
longEma3Line = plot(ripsterEmaCloudsShowed and ema3CloudShowed ? longEma3 : na, color=na, linewidth=1, title="Long EMA 3", display = display.pane)
longEma4Line = plot(ripsterEmaCloudsShowed and ema4CloudShowed ? longEma4 : na, color=na, linewidth=1, title="Long EMA 4", display = display.pane)
longEma5Line = plot(ripsterEmaCloudsShowed and ema5CloudShowed ? longEma5 : na, color=na, linewidth=1, title="Long EMA 5", display = display.pane)

fill(shortEma1Line, longEma1Line, color=color.new(cloudcolour1, 80), title="EMA Cloud 1")
fill(shortEma2Line, longEma2Line, color=color.new(cloudcolour2, 80), title="EMA Cloud 2")
fill(shortEma3Line, longEma3Line, color=color.new(cloudcolour3, 60), title="EMA Cloud 3")
fill(shortEma4Line, longEma4Line, color=color.new(cloudcolour4, 60), title="EMA Cloud 4")
fill(shortEma5Line, longEma5Line, color=color.new(cloudcolour5, 80), title="EMA Cloud 5")

plotshape(ripsterEmaCloudsShowed and isUp, title = "Up Trend Signal" , style = shape.triangleup, location = location.belowbar, color = WHITE_COLOR, size = size.tiny, display = display.pane)
plotshape(ripsterEmaCloudsShowed and isDn, title = "Down Trend Signal" , style = shape.triangledown, location = location.abovebar, color = AQUA_COLOR, size = size.tiny, display = display.pane)

//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// ATR Levels
//-----------------------------------------------------------------------------
// Settings
//-----------------------------------------------------------------------------
alGrp= "ATR Levels"
alShowed= input.bool(true, title="Show", group=alGrp)
alDayTradingOption = 'Day'
alMultidayTradingOption = 'Multiday'
alSwingTradingOption = 'Swing'
alTradingType = input.string(alDayTradingOption, 'Trading Type', options=[alDayTradingOption, alMultidayTradingOption, alSwingTradingOption], group=alGrp)
alLength = input.int(14, 'ATR Length', group=alGrp)
alTriggerPerc = input.float(0.236, 'Trigger Percentage', group=alGrp)
alPrevCloseLevelColor = input.color(WHITE_COLOR, 'Previous Close Level Color', group=alGrp)
alLowerTriggerLevelColor = input.color(PURPLE_COLOR, 'Lower Trigger Level Color', group=alGrp)
alUpperTriggerLevelColor = input.color(PURPLE_COLOR, 'Upper Trigger Level Color', group=alGrp)
alKeyTargetLevelColor = input.color(YELLOW_COLOR, 'Key Target Level Color', group=alGrp)
alAtrTargetLevelColor = input.color(WHITE_COLOR, 'ATR Target Level Color', group=alGrp)
alIntermediateTargetLevelColor = input.color(LIGHT_GRAY_COLOR, 'Intermediate Target Level Color', group=alGrp)
alShowAllFibLevels = input.bool(true, 'Show All Fibonacci Levels', group=alGrp)
alFastEma = input.int(8, 'Fast EMA', group=alGrp)
alPivotEma = input.int(21, 'Pivot EMA', group=alGrp)
alSlowEma = input.int(34, 'Slow EMA', group=alGrp)
alOffset = input.int(5, "Offset", group=alGrp)

//-----------------------------------------------------------------------------
// Methods
//-----------------------------------------------------------------------------
// Set the appropriate timeframe based on trading mode
getAlTf() =>
    timeframe = 'D'
    if alTradingType == alDayTradingOption
        timeframe := 'D'
    else if alTradingType == alMultidayTradingOption
        timeframe := 'W'
    else if alTradingType == alSwingTradingOption
        timeframe := 'M'
    else
        timeframe := 'D'

//-----------------------------------------------------------------------------
// Values
//-----------------------------------------------------------------------------
// Trend
price = close
alFastEmaVal = ta.ema(price, alFastEma)
alPivotEmaVal = ta.ema(price, alPivotEma)
alSlowEmaVal = ta.ema(price, alSlowEma)

// Data
alPeriodIdx = 1
alTicker = ticker.new(syminfo.prefix, syminfo.ticker, session=session.extended)
alPrevClose = request.security(alTicker, getAlTf(), close[alPeriodIdx], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
atr = request.security(alTicker, getAlTf(), ta.atr(alLength)[alPeriodIdx], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
alPeriodHigh = request.security(alTicker, getAlTf(), high, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
alPeriodLow = request.security(alTicker, getAlTf(), low, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
alRange1 = alPeriodHigh - alPeriodLow
alTrPercOfAtr = alRange1 / atr * 100
alLowerTrigger = alPrevClose - alTriggerPerc * atr
alUpperTrigger = alPrevClose + alTriggerPerc * atr
alLower0382 = alPrevClose - atr * 0.382
alUpper0382 = alPrevClose + atr * 0.382
alLower0500 = alPrevClose - atr * 0.5
alUpper0500 = alPrevClose + atr * 0.5
alLower0618 = alPrevClose - atr * 0.618
alUpper0618 = alPrevClose + atr * 0.618
alLower0786 = alPrevClose - atr * 0.786
alUpper0786 = alPrevClose + atr * 0.786
alLower1000 = alPrevClose - atr
alUpper1000 = alPrevClose + atr

//-----------------------------------------------------------------------------
// Render
//-----------------------------------------------------------------------------
alChar = '-'
plotchar(alLower1000, char=alChar, show_last=1, location=location.absolute, offset=alOffset, color=alAtrTargetLevelColor, size=size.small, title="-100%", display = display.pane, editable = false)
plotchar(alShowAllFibLevels ? alLower0786 : na, char=alChar, show_last=1, location=location.absolute, offset=alOffset, color=alIntermediateTargetLevelColor, size=size.small, title="-78.6%", display = display.pane, editable = false)
plotchar(alLower0618, char=alChar, show_last=1, location=location.absolute, offset=alOffset, color=alKeyTargetLevelColor, size=size.small, title="-78.6%", display = display.pane, editable = false)
plotchar(alShowAllFibLevels ? alLower0500 : na, char=alChar, show_last=1, location=location.absolute, offset=alOffset, color=alIntermediateTargetLevelColor, size=size.small, title="-50.0%", display = display.pane, editable = false)
plotchar(alShowAllFibLevels ? alLower0382 : na, char=alChar, show_last=1, location=location.absolute, offset=alOffset, color=alIntermediateTargetLevelColor, size=size.small, title="-38.2%", display = display.pane, editable = false)
plotchar(alLowerTrigger, char=alChar, show_last=1, location=location.absolute, offset=alOffset, color=alLowerTriggerLevelColor, size=size.small, title="Lower Trigger", display = display.pane, editable = false)
plotchar(alPrevClose, char=alChar, show_last=1, location=location.absolute, offset=alOffset, color=alPrevCloseLevelColor, size=size.small, title="Previous Close", display = display.pane, editable = false)
plotchar(alUpperTrigger, char=alChar, show_last=1, location=location.absolute, offset=alOffset, color=alUpperTriggerLevelColor, size=size.small, title="Upper Trigger", display = display.pane, editable = false)
plotchar(alShowAllFibLevels ? alUpper0382 : na, char=alChar, show_last=1, location=location.absolute, offset=alOffset, color=alIntermediateTargetLevelColor, size=size.small, title="38.2%", display = display.pane, editable = false)
plotchar(alShowAllFibLevels ? alUpper0500 : na, char=alChar, show_last=1, location=location.absolute, offset=alOffset, color=alIntermediateTargetLevelColor, size=size.small, title="50.0%", display = display.pane, editable = false)
plotchar(alUpper0618, char=alChar, show_last=1, location=location.absolute, offset=alOffset, color=alKeyTargetLevelColor, size=size.small, title="61.8%", display = display.pane, editable = false)
plotchar(alShowAllFibLevels ? alUpper0786 : na, char=alChar, show_last=1, location=location.absolute, offset=alOffset, color=alIntermediateTargetLevelColor, size=size.small, title="78.6%", display = display.pane, editable = false)
plotchar(alUpper1000, char=alChar, show_last=1, location=location.absolute, offset=alOffset, color=alAtrTargetLevelColor, size=size.small, title="100%", display = display.pane, editable = false)

//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// S/R
//-----------------------------------------------------------------------------
// Settings
//-----------------------------------------------------------------------------
srGrp             = "S/R"
srShowed          = input.bool(true, title="Show", group=srGrp)
srPrd             = input.int(284, title="Period", group=srGrp)
srSupportColor    = input.color(#212d4080, title="Support Color", group=srGrp)
srResistanceColor = input.color(#212d4080, title="Resistance Color", group=srGrp)
srStrength        = input.int(2, title="Strength", minval=1, group=srGrp)
srZoneWidthPerc   = input.float(1.5, title="Zone Width In %", minval=0, group=srGrp)
srValColor        = input.color(TEXT_COLOR, title="Value Color", group=srGrp)

//-----------------------------------------------------------------------------
// Methods
//-----------------------------------------------------------------------------
// Format S/R value text
getSrValTxt(float val) =>
    str.tostring(val, "#.#####")

// Build S/R value box
buildSrValBox(float top, float bot, float val, float padding) =>
    int txtOffset = barIdx + 24
    box.new(txtOffset, top - padding / 5, txtOffset + 150, bot + padding / 5, bgcolor=TRANSPARENT_COLOR, border_width=0, text=getSrValTxt(val), text_color=srValColor, text_size=size.small, text_valign=text.align_center, text_halign=text.align_left, extend=extend.right)

//-----------------------------------------------------------------------------
// Render
//-----------------------------------------------------------------------------
// Initialize S/R variables
int srSize           = 21
int srRb             = 10
float srPh           = ta.pivothigh(srRb, srRb)
float srPl           = ta.pivotlow(srRb, srRb)
var srLevels         = array.new_float(srSize, na)
float srHighestVal   = ta.highest(srPrd)
float srLowestVal    = ta.lowest(srPrd)
float srChannelWidth = getPrdWidthByPerc(srPrd, 10)
float srZoneWidth    = getPrdWidthByPerc(300, srZoneWidthPerc)
bool[] srAas         = array.new_bool(41, true)
float srHighestPh    = 0.0, srHighestPh := srHighestPh[1]
float srLowestPl     = 0.0, srLowestPl := srLowestPl[1]
var srLevelsClone    = array.new_float(srSize, na)
var srAreaBoxes      = array.new_box(srSize, na)
var srValBoxes       = array.new_box(srSize, na)

if (not na(srPh) or not na(srPl)) and srShowed
    for i = 0 to array.size(srLevels) - 1
        array.set(srLevels, i, na)

    srHighestPh := srLowestVal
    srLowestPl := srHighestVal
    int ppCount = 0

    for i = 0 to srPrd
        if na(close[i])
            break

        if not na(srPh[i]) or not na(srPl[i])
            srHighestPh := math.max(srHighestPh, nz(srPh[i], srLowestVal), nz(srPl[i], srLowestVal))
            srLowestPl := math.min(srLowestPl, nz(srPh[i], srHighestVal), nz(srPl[i], srHighestVal))
            ppCount += 1

            if ppCount > 40
                break

            if array.get(srAas, ppCount)
                upl = (not na(srPh[i]) ? high[i + srRb] : low[i + srRb]) + srChannelWidth
                dnl = (not na(srPh[i]) ? high[i + srRb] : low[i + srRb]) - srChannelWidth
                tmp = array.new_bool(41, true)
                count = 0
                points = 0

                for j = 0 to srPrd
                    if na(close[j])
                        break

                    if not na(srPh[j]) or not na(srPl[j])
                        chg = false
                        count += 1

                        if count > 40
                            break

                        if array.get(srAas, count)
                            if not na(srPh[j])
                                if high[j + srRb] <= upl and high[j + srRb] >= dnl
                                    points += 1
                                    chg := true

                            if not na(srPl[j])
                                if low[j + srRb] <= upl and low[j + srRb] >= dnl
                                    points += 1
                                    chg := true

                        if chg and count < 41
                            array.set(tmp, count, false)

                if points >= srStrength
                    for g = 0 to 40 by 1
                        if not array.get(tmp, g)
                            array.set(srAas, g, false)

                    if not na(srPh[i]) and ppCount < srSize
                        array.set(srLevels, ppCount, high[i + srRb])

                    if not na(srPl[i]) and ppCount < srSize
                        array.set(srLevels, ppCount, low[i + srRb])

if srShowed
    var box srHighestAreaBox = na, box.delete(srHighestAreaBox)
    var box srLowestAreaBox  = na, box.delete(srLowestAreaBox)
    var box srHighestValBox  = na, box.delete(srHighestValBox)
    var box srLowestValBox   = na, box.delete(srLowestValBox)
    color srHighestColor     = close >= srHighestPh ? srSupportColor : srResistanceColor
    color srLowestColor      = close >= srLowestPl ? srSupportColor : srResistanceColor
    float srHighestTop       = srHighestPh + srZoneWidth
    float srHighestBot       = srHighestPh - srZoneWidth
    float srLowestTop        = srLowestPl + srZoneWidth
    float srLowestBot        = srLowestPl - srZoneWidth
    srHighestAreaBox := box.new(barIdx, srHighestTop, barIdx, srHighestBot, extend=extend.both, bgcolor=srHighestColor, border_width=0)
    srLowestAreaBox := box.new(barIdx, srLowestTop, barIdx, srLowestBot, extend=extend.both, bgcolor=srLowestColor, border_width=0)
    srHighestValBox := buildSrValBox(srHighestTop, srHighestBot, srHighestPh, srZoneWidth)
    srLowestValBox := buildSrValBox(srLowestTop, srLowestBot, srLowestPl, srZoneWidth)

    if not na(srPh) or not na(srPl)
        for i = 0 to array.size(srAreaBoxes) - 1
            array.set(srLevelsClone, i, array.get(srLevels, i))

    for i = 0 to array.size(srAreaBoxes) - 1
        box.delete(array.get(srAreaBoxes, i))
        box.delete(array.get(srValBoxes, i))

        if not na(array.get(srLevelsClone, i))
            color lineColor = close >= array.get(srLevelsClone, i) ? srSupportColor : srResistanceColor
            float level = array.get(srLevelsClone, i)
            float top = level + srZoneWidth
            float bot = level - srZoneWidth
            bool topExisted = math.abs(level - srHighestPh) < srZoneWidth
            bool botExisted = math.abs(level - srLowestPl) < srZoneWidth

            if (not topExisted and not botExisted)
                array.set(srAreaBoxes, i, box.new(barIdx, top, barIdx, bot, extend=extend.both, bgcolor=lineColor, border_width=0))
                array.set(srValBoxes, i, buildSrValBox(top, bot, level, srZoneWidth))

//-----------------------------------------------------------------------------

Overview

Algo calculates adaptive DSMA lines alongside five configurable EMA pairs ranging from short-term to long-term periods. Users can toggle individual EMA clouds, adjust DSMA smoothing lengths, and configure ATR trigger levels based on trading style. Multi-timeframe settings utilize lookahead, which may alter historical calculations compared to live conditions.

Details

Published by

TamTH-Dev on GitHub

Code credit

tamth_, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Moving averages, Trend, Support & resistance, Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Reads higher-timeframe data with lookahead on, so the history can show signals that were not there in real time

Settings

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

SettingTypeDefaultVariable
ShowbooltruedsmaShowed
SourcesourceclosedsmaSrc
TimeframetimeframedsmaTf
DSMA 1 Lengthint40dsma1Len
DSMA 1 ColorcolorBLUE_COLORdsma1Color
DSMA 2 Lengthint100dsma2Len
DSMA 2 ColorcolorORANGE_COLORdsma2Color
ShowboolfalseripsterEmaCloudsShowed
SourcesourcecloseripsterEmaCloudsSrc
TimeframetimeframeripsterEmaCloudsTf
Short EMA 1 Lengthint8shortEma1Len
Long EMA 1 Lengthint9longEma1Len
Show all 40 settings
SettingTypeDefaultVariable
Show EMA Cloud 1booltrueema1CloudShowed
Short EMA 2 Lengthint5shortEma2Len
Long EMA 2 Lengthint13longEma2Len
Show EMA Cloud 2booltrueema2CloudShowed
Short EMA 3 Lengthint20shortEma3Len
Long EMA 3 Lengthint21longEma3Len
Show EMA Cloud 3booltrueema3CloudShowed
Short EMA 4 Lengthint48shortEma4Len
Long EMA 4 Lengthint50longEma4Len
Show EMA Cloud 4booltrueema4CloudShowed
Short EMA 5 Lengthint180shortEma5Len
Long EMA 5 Lengthint200longEma5Len
Show EMA Cloud 5booltrueema5CloudShowed
ShowbooltruealShowed
Trading TypestringalDayTradingOptionalTradingType
ATR Lengthint14alLength
Trigger Percentagefloat0.236alTriggerPerc
Previous Close Level ColorcolorWHITE_COLORalPrevCloseLevelColor
Lower Trigger Level ColorcolorPURPLE_COLORalLowerTriggerLevelColor
Upper Trigger Level ColorcolorPURPLE_COLORalUpperTriggerLevelColor
Key Target Level ColorcolorYELLOW_COLORalKeyTargetLevelColor
ATR Target Level ColorcolorWHITE_COLORalAtrTargetLevelColor
Intermediate Target Level ColorcolorLIGHT_GRAY_COLORalIntermediateTargetLevelColor
Show All Fibonacci LevelsbooltruealShowAllFibLevels
Fast EMAint8alFastEma
Pivot EMAint21alPivotEma
Slow EMAint34alSlowEma
Offsetint5alOffset
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

MA Envelope (MAE)

by mihakralj
99 stars

The MA Envelope indicator calculates upper and lower channel bands shifted by a user-defined percentage around a baseline moving average. It supports Simple Moving Average, Exponential Moving Average, and Weighted Moving Average calculation types. The script p

Indicator v6 Moving averagesSupport & resistance
Updated 4 weeks ago · Apache-2.0 GitHub repository of MA Envelope (MAE)

Trend Compass 4H

by chris-c-thomas
14 stars

Trend Compass 4H plots a multi-EMA ribbon (10/21/50) along with higher-timeframe reference levels on the price chart. It classifies trend phase into six states and calculates a composite weighted trend score. The script detects RSI and MACD divergences, analyz

Indicator v6 TrendMoving averages
Updated 6 months ago · MIT GitHub repository of Trend Compass 4H
10 stars

My Macro Cycle Indicator plots daily and weekly simple and exponential moving averages on the price chart, plus Pi Cycle and Mayer Multiple levels derived from the 200-day average. Optional toggles add support-band fills, a Keltner channel, CME futures gaps, a

Indicator v4 Moving averagesVolatility & bands
Updated 5 years ago · None stated GitHub repository of My Macro Cycle Indicator

This indicator plots a double-smoothed Supertrend baseline on the price chart, combining a Supertrend midline with WMA and EMA smoothing to show trend direction. Direction uses an ATR-scaled baseline slope with hysteresis, while percentile-ranked slope magnitu

Indicator v6 TrendMoving averages
Updated yesterday · MIT GitHub repository of Smooth Trend Radar [WavesUnchained]

SRI Indicator ft. MSB

by kingmalitha
7 stars

This indicator overlays an all-in-one technical analysis toolkit on the price chart. It plots multiple moving averages, including standard EMAs, SMAs, and a Trend Regularity Adaptive Moving Average, alongside Bollinger Bands, Supertrend, Nadaraya-Watson envelo

Indicator v5 Moving averagesTrend Repaints
Updated 3 years ago · None stated GitHub repository of SRI Indicator ft. MSB

More indicators

Trade Your Charts With a Regulated Broker

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

Compare brokers