Indicator · Pine Script v6 · On the chart

Algo

by TamTH-Dev· code credited to tamth_

This indicator plots dual Kaufman Adaptive Moving Averages (KAMA) alongside a volume profile component on the main price chart.

View on GitHub

GitHub stars2on the repository
Pine versionv6current
Lines of code201
Settings16inputs
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

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

Algo.pine
// This Pine Script® 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        = #F72585
color ORANGE_COLOR     = #fb5607
color YELLOW_COLOR     = #ffbe0b
color GREEN_COLOR      = #2a9d8f
color AQUA_COLOR       = #4CC9F0
color BLUE_COLOR       = #4895EF
color PURPLE_COLOR     = #3F37C9
color PINK_COLOR       = #B5179E
color LIGHT_GRAY_COLOR = #364156
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)

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

//-----------------------------------------------------------------------------
// KAMAs
//-----------------------------------------------------------------------------
// Settings
//-----------------------------------------------------------------------------
kamaCommonGrp   = "kamaCommonGrp"
kamaGrp         = "Kaufman Adaptive Moving Average"
kamaShowed      = input.bool(true, "Show", group = kamaGrp)
kamaSrc         = input.source(close, title = "Source", group = kamaGrp)

kama1Grp        = "K1"
kama1Showed     = input.bool(true, title = "K1", group = kamaGrp, inline = kama1Grp)
kama1Tf         = input.timeframe("", title = "", group = kamaGrp, inline = kama1Grp)
kama1Len        = input.int(21, title = "", group = kamaGrp, inline = kama1Grp)
kama1FastEmaLen = input.int(2, title = "", group = kamaGrp, inline = kama1Grp)
kama1SlowEmaLen = input.int(30, title = "", group = kamaGrp, inline = kama1Grp)

kama2Grp        = "K2"
kama2Showed     = input.bool(true, title = "K2", group = kamaGrp, inline = kama2Grp)
kama2Tf         = input.timeframe("", title = "", group = kamaGrp, inline = kama2Grp)
kama2Len        = input.int(21, title = "", group = kamaGrp, inline = kama2Grp)
kama2FastEmaLen = input.int(2, title = "", group = kamaGrp, inline = kama2Grp)
kama2SlowEmaLen = input.int(30, title = "", group = kamaGrp, inline = kama2Grp)

//-----------------------------------------------------------------------------
// Methods
//-----------------------------------------------------------------------------
getKama(src, len, fastEmaLen, slowEmaLen) =>
    mom = math.abs(ta.change(src, len))
    volatility = math.sum(math.abs(ta.change(src)), len)
    efficiencyRatio = volatility != 0 ? mom / volatility : 0
    fastAlpha = 2 / (fastEmaLen + 1)
    slowAlpha = 2 / (slowEmaLen + 1)
    alpha = math.pow(efficiencyRatio * (fastAlpha - slowAlpha) + slowAlpha, 2)
    kama = 0.0
    kama := alpha * src + (1 - alpha) * nz(kama[1], src)

getDefHtf() =>
    switch timeframe.period
        "3"   => "30"
        "5"   => "60"
        "15"  => "240"
        "30"  => "480"
        "60"  => "D"
        "240" => "W"
        "1D"  => "M"
        "1M"  => "12M"

//-----------------------------------------------------------------------------
// Calculate
//-----------------------------------------------------------------------------
kama1 = request.security(syminfo.tickerid, kama1Tf, getKama(kamaSrc, kama1Len, kama1FastEmaLen, kama1SlowEmaLen), gaps = barmerge.gaps_on, lookahead = barmerge.lookahead_off)
kama2 = request.security(syminfo.tickerid, kama2Tf != "" ? kama2Tf : getDefHtf(), getKama(kamaSrc, kama2Len, kama2FastEmaLen, kama2SlowEmaLen), gaps = barmerge.gaps_on, lookahead = barmerge.lookahead_off)

//-----------------------------------------------------------------------------
// Render
//-----------------------------------------------------------------------------
plot(kamaShowed and kama1Showed ? kama1 : na, title = "KAMA 1", linewidth = 1, color = AQUA_COLOR, display = display.pane)
plot(kamaShowed and kama2Showed ? kama2 : na, title = "KAMA 2", linewidth = 1, color = PURPLE_COLOR, display = display.pane)

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


//-----------------------------------------------------------------------------
// Delta Volume Profile
//-----------------------------------------------------------------------------
// Settings
//-----------------------------------------------------------------------------
dvpGrp = "Delta Volume Profile"
dvpShowed = input.bool(true, "Show", group=dvpGrp)
dvpLookback = input.int(200, "Lookback Length", group=dvpGrp)
dvpPlusColor = input.color(PINK_COLOR, "Volume +", group=dvpGrp)
dvpMinusColor = input.color(PURPLE_COLOR, "Volume -", group=dvpGrp)

//-----------------------------------------------------------------------------
// Calculate & Render
//-----------------------------------------------------------------------------
dvpMaxMin = array.new<float>()
dvpStep = 0.
dvpBins = 0

dvpAtr = ta.atr(200)

if barstate.islast and dvpShowed
    for i = 0 to dvpLookback-1

        h = high[i]
        l = low[i]

        dvpMaxMin.push(h)
        dvpMaxMin.push(l)

    dvpBins := int((dvpMaxMin.max() - dvpMaxMin.min()) / dvpAtr)
    dvpStep := (dvpMaxMin.max() - dvpMaxMin.min()) / dvpBins

dvpVolPlus = array.new<float>(dvpBins, 0)
dvpVolMinus = array.new<float>(dvpBins, 0)

if barstate.islast and dvpShowed
    for i = 0 to dvpLookback-1
        h = high[i]
        l = low[i]
        c = close[i]
        o = open[i]
        v = volume[i]

        for k = 0 to dvpBins - 1

            loww = dvpMaxMin.min() + dvpStep * k
            mid = loww + dvpStep/2

            if h > mid and l < mid 
                if c > o
                    dvpVolPlus.set(k, dvpVolPlus.get(k) + v)
                else
                    dvpVolMinus.set(k, dvpVolMinus.get(k) + v)

var dvpBoxes = array.new<box>()
var dvpLabels = array.new<label>()

if barstate.islast and dvpShowed
    if dvpBoxes.size() >= 0
        for b in dvpBoxes
            box.delete(b)
        dvpBoxes.clear()

    if dvpLabels.size() >= 0
        for l in dvpLabels
            label.delete(l)
        dvpLabels.clear()

    for i = 0 to dvpBins - 1
        loww = dvpMaxMin.min() + dvpStep * i
        highh = loww + dvpStep

        value_plus = int(dvpVolPlus.get(i) / dvpVolPlus.sum()*200)
        value_minus = int(dvpVolMinus.get(i) / dvpVolMinus.sum()*200)

        max_plus = dvpVolPlus.get(i) == dvpVolPlus.max()
        dvpMaxMinus = dvpVolMinus.get(i) == dvpVolMinus.max()

        col_plus = color.from_gradient(dvpVolPlus.get(i), dvpVolPlus.min(), dvpVolPlus.max(), color.new(dvpPlusColor, 90), color.new(dvpPlusColor, 30))
        col_minus = color.from_gradient(dvpVolMinus.get(i), dvpVolMinus.min(), dvpVolMinus.max(), color.new(dvpMinusColor, 90), color.new(dvpMinusColor, 30))

        sum = value_plus + value_minus
        tot = dvpVolPlus.sum() + dvpVolMinus.sum()

        delta = ((dvpVolPlus.sum() - dvpVolMinus.sum()) / dvpVolMinus.sum()) * 100

        b1=box.new(bar_index+50, highh, bar_index+50-value_plus, loww, chart.bg_color, bgcolor = max_plus ? dvpPlusColor : col_plus, text =  dvpVolPlus.get(i) != 0 ? "+"+str.tostring(dvpVolPlus.get(i), format.volume) : "", text_color = TEXT_COLOR, text_size = size.small, text_halign = text.align_right)
        b2=box.new(bar_index+50, highh, bar_index+50+value_minus, loww, chart.bg_color, bgcolor = dvpMaxMinus ? dvpMinusColor : col_minus, text = dvpVolMinus.get(i) != 0 ? "-"+str.tostring(dvpVolMinus.get(i), format.volume) : "", text_color = TEXT_COLOR, text_size = size.small, text_halign = text.align_left)

        dvpBoxes.push(b1)
        dvpBoxes.push(b2)

        dvpLabels.push(label.new(bar_index+50, dvpMaxMin.max(), "Delta: "+ str.tostring(delta, format.percent), color = delta > 0 ? dvpPlusColor : dvpMinusColor, textcolor = TEXT_COLOR, style = label.style_label_down, size = size.small))

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

Overview

Users can configure two separate KAMA instances with distinct timeframes, lookback lengths, and fast or slow smoothing limits. The indicator also provides volume profiling with customizable lookback periods and visual color styling. It functions as an overlay tool without automated trade signals or execution rules.

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, Volume

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
ShowbooltruekamaShowed
SourcesourceclosekamaSrc
K1booltruekama1Showed
kama1Tftimeframekama1Tf
kama1Lenint21kama1Len
kama1FastEmaLenint2kama1FastEmaLen
kama1SlowEmaLenint30kama1SlowEmaLen
K2booltruekama2Showed
kama2Tftimeframekama2Tf
kama2Lenint21kama2Len
kama2FastEmaLenint2kama2FastEmaLen
kama2SlowEmaLenint30kama2SlowEmaLen
Show all 16 settings
SettingTypeDefaultVariable
ShowbooltruedvpShowed
Lookback Lengthint200dvpLookback
Volume +colorPINK_COLORdvpPlusColor
Volume -colorPURPLE_COLORdvpMinusColor
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

Calculates an Elastic Volume Weighted Moving Average (EVWMA), incorporating trading volume to dynamically adjust moving average responsiveness over a specified lookback length. It plots directly on the price chart as a single moving average line. Optional colo

Indicator v4 Moving averagesVolume
Updated 10 days ago · GPL-3.0 GitHub repository of Elastic Volume Weighted Moving Average

Midnight VWAP

by TradersPost
218 stars

The Midnight VWAP indicator calculates and overlays two distinct Volume Weighted Average Price (VWAP) lines on the price chart based on customizable session timeframes. It tracks an overnight or pre-market session alongside regular trading hours, resetting cal

Indicator v6 Moving averagesSessions & time
Updated 3 months ago · None stated GitHub repository of Midnight VWAP

LiqSpikeBounceLong Feb2026

by agutinbaigo28
147 stars

LiqSpikeBounceLong Feb2026 is an indicator designed to identify long bounce entries following high-volume liquidation cascades in bearish market contexts. It checks if price is below an exponential moving average, then detects large single-bar drops exceeding

Indicator v5 Volatility & bandsVolume
Updated 6 weeks ago · MIT GitHub repository of LiqSpikeBounceLong Feb2026

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

Signal Strategy 15m

by tripolskypetr
72 stars

This indicator generates trend-following trade signals on the price chart by combining moving average crossovers with multi-factor filters. It triggers entry alerts when fast and slow EMAs cross in the direction of a baseline trend EMA, confirmed by non-extrem

Indicator v5 TrendMoving averages
Updated 3 days ago · MIT GitHub repository of Signal Strategy 15m

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