Kaufman's Adaptive Moving Average Pine Script — Complete TradingView Guide
Kaufman's Adaptive Moving Average (KAMA) is a unique trend-following indicator developed by Perry Kaufman in 1998 that automatically adjusts its smoothing speed based on current market conditions. Unlike the EMA or SMA, which use a fixed period, KAMA calculates an Efficiency Ratio (ER) — the ratio of net price direction to total price movement — and uses it to control how fast or slow the moving average tracks price. In a strong, directional trend, KAMA moves quickly to stay close to price. In choppy, sideways markets, KAMA nearly flattens, dramatically reducing false signals. This guide covers the complete Pine Script v6 implementation of KAMA with default length 10, all configurable parameters with recommended ranges, three concrete KAMA trading strategies with specific entry and exit conditions, and a five-step guide to generating KAMA scripts instantly with Pineify.
What Is Kaufman's Adaptive Moving Average?
The Kaufman's Adaptive Moving Average (KAMA) is a trend-following overlay indicator that dynamically adjusts its smoothing constant based on the Efficiency Ratio of price movement, used to track trends closely while filtering out sideways noise. Developed by American trading systems researcher Perry J. Kaufman and first published in his 1998 book Trading Systems and Methods, KAMA solved a persistent problem with fixed-period moving averages: they either lag too much in trending markets or generate too many false signals in choppy ones.
The core innovation is the Efficiency Ratio (ER). ER measures how efficiently price is moving in one direction: ER = Signal ÷ Noise, where Signal is the absolute net price change over the lookback period and Noise is the sum of all absolute bar-to-bar price changes over the same period. An ER of 1.0 means perfectly directional movement. An ER near 0 means highly noisy, non-directional price action.
From the ER, KAMA derives an adaptive Smoothing Constant (SC) that interpolates between two EMA speeds: SC = (ER × (fast_SC − slow_SC) + slow_SC)², where fast_SC = 0.666 (equivalent to a 2-period EMA) and slow_SC = 0.0645 (equivalent to a 30-period EMA). This gives KAMA its adaptive behavior: fast when ER is high, slow when ER is low. The KAMA value itself is updated as: KAMA = KAMA(prev) + SC × (price − KAMA(prev)).
KAMA applies to all liquid asset classes: stocks, crypto, forex, and futures. It is most effective in markets that alternate between trending and ranging phases — which makes it especially popular for cryptocurrency and forex pairs. Best timeframes are 1-hour, 4-hour, and Daily charts. Very short timeframes (under 5 minutes) and very long timeframes (monthly) are less well-suited because the Efficiency Ratio becomes less meaningful at those extremes.
Developed By
Perry J. Kaufman, 1998
Best Timeframes
1H, 4H, Daily
Best Markets
Stocks · Crypto · Forex · Futures
KAMA Pine Script Code Example
The code below implements Kaufman's Adaptive Moving Average as a blue overlay line on the TradingView price chart using Pine Script v6 with a default length of 10 bars. To add it to TradingView, open the Pine Script editor with Alt+P, paste the code, and click Add to chart. You can change the 10 in p_ta_kama(close, 10) to any lookback period that matches your trading timeframe.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pineify
//@version=6
indicator(title="Kaufman's Adaptive Moving Average", overlay=true, max_labels_count=500)
// KAMA — adapts speed based on price efficiency ratio
p_ta_kama(series float source, simple int length) =>
dist = math.abs(source[0] - source[1])
signal = math.abs(source - source[length])
noise = math.sum(dist, length)
effr = noise != 0 ? signal / noise : 1
sc = math.pow(effr * (0.666 - 0.0645) + 0.0645, 2)
kama = source
kama := nz(kama[1]) + sc * (source - nz(kama[1]))
kama
p_ind_1 = p_ta_kama(close, 10) // KAMA with default length 10
// Plot the KAMA line on the price chart
plot(p_ind_1, "KAMA", color.rgb(41, 98, 255, 0), 1)Chart Preview

KAMA Parameters
| Parameter | Default Value | Description | Recommended Range |
|---|---|---|---|
| source | close | The price series input for the KAMA calculation. Most commonly close, but can be hl2 (high+low÷2) or hlc3 for a more balanced price representation. | Any numeric series |
| length | 10 | The Efficiency Ratio lookback period — the number of bars used to calculate both the Signal (net price change) and Noise (sum of bar-to-bar changes). A larger length captures bigger trend cycles but increases lag; a smaller length is more responsive but less stable. | 5–30 depending on timeframe |
Tuning Guide by Trading Style
- Scalping (5m–15m charts): length 5–8 — faster Efficiency Ratio response, tracks short micro-trends
- Day trading (1H charts): length 10 (default) — Perry Kaufman's original recommended setting, balances responsiveness and noise rejection
- Swing trading (4H–Daily charts): length 14–20 — captures multi-day trend cycles, filters intraday noise effectively
- Position trading (Weekly charts): length 20–30 — very slow adaptation, designed for macro trend identification only
KAMA Trading Strategies
KAMA is most effective as an adaptive trend filter — it identifies when markets are genuinely trending versus ranging, making it ideal for filtering entry signals from other indicators. Below are three concrete strategies with specific entry and exit conditions.
Strategy 1 — KAMA Slope Direction (Trend Following)
Market environment: trending markets · Best timeframe: 1H, 4H, Daily
The KAMA slope is the simplest and most reliable KAMA signal. When KAMA is rising, the market is in an uptrend detected by the Efficiency Ratio. When KAMA is flat, the market is ranging and no position should be held. Use kama > kama[1] to detect a rising slope.
- Calculate KAMA:
kama = p_ta_kama(close, 10) - Long entry:
kama > kama[1]AND close > kama — KAMA is rising and price is above it - Confirm with volume: average volume over 5 bars > average volume over 20 bars (trend has participation)
- Exit:
kama < kama[1]— KAMA slope turns negative (market entering range or reversing) - Stop loss: below the KAMA value at entry bar
Strategy 2 — Price-KAMA Crossover with ADX Filter
Market environment: breakout from range into trend · Best timeframe: 4H, Daily
Combining KAMA crossovers with ADX (Average Directional Index) ensures entries only occur when trend strength is confirmed. KAMA provides the crossover signal; ADX confirms that directional movement is sufficient (ADX > 20 is the standard threshold for a trending market).
- Calculate KAMA and ADX:
kama = p_ta_kama(close, 10),[adx, _, _] = ta.dmi(14, 14) - Long entry:
ta.crossover(close, kama)AND adx > 20 (trend is strong enough) - Short entry:
ta.crossunder(close, kama)AND adx > 20 - No trade: adx < 20 — market is ranging, KAMA crossovers unreliable
- Exit: opposite crossover signal or ADX falling below 15
Strategy 3 — KAMA + RSI Momentum Confirmation
Market environment: trend resumption after pullback · Best timeframe: 1H, 4H
Pairing KAMA with RSI(14) creates a two-layer filter: KAMA confirms trend direction while RSI confirms that momentum supports a continuation move. This combination is especially effective for re-entering a trend after a pullback.
- Calculate KAMA and RSI:
kama = p_ta_kama(close, 10),rsi14 = ta.rsi(close, 14) - Long entry: kama > kama[1] (rising KAMA) AND close > kama AND rsi14 > 50 (bullish momentum)
- Avoid: entries where rsi14 > 70 (overbought — trend is overextended, reversal risk elevated)
- Pullback re-entry: price touches KAMA from above AND RSI bounces from 40–50 zone — high probability continuation setup
- Exit: kama < kama[1] (KAMA turns flat/down) OR rsi14 falls below 45
Disclaimer: The strategies above are for educational purposes only and do not constitute investment advice. Past performance does not guarantee future results. Always apply proper risk management and position sizing.
How to Generate the KAMA Indicator in Pineify
- 1
Open Pineify
Go to pineify.app and sign in — a free account is sufficient to generate KAMA indicators with full Pine Script v6 code.
- 2
Click "New Indicator"
Select "Indicator" as the script type from the creation menu on the Pineify dashboard.
- 3
Describe the KAMA you want
Type a prompt such as: "Plot Kaufman's Adaptive Moving Average (KAMA) with length 10 as a blue overlay line using the Efficiency Ratio method." Pineify's AI Coding Agent generates the complete Pine Script v6 code in seconds.
- 4
Copy to TradingView
Click "Copy to TradingView" to copy the generated script, then open the TradingView Pine Script editor (Alt+P), paste the code, and click "Add to chart" to see KAMA plotted on your chart.
- 5
Adjust the length parameter
In the TradingView indicator settings panel, change the KAMA length (e.g., from 10 to 14 for swing trading or 5 for scalping) to match your timeframe — no code editing required.
Frequently Asked Questions
Related Pine Script Indicators
Build Your KAMA Indicator in Seconds
Skip the manual coding. Pineify's AI Coding Agent generates complete, ready-to-use Pine Script indicators — including Kaufman's Adaptive Moving Average with ADX and RSI confirmations — instantly for free.
Try Pineify Free