Kaufman's Adaptive Moving Average (KAMA)

A buddy of mine wrote this KAMA indicator for ThinkorSwim and a few of us in a circle of friends use it. Austin (who write it) has been trying to massage the code so that it will throw alerts when the trend changes, to be able to scan for trend changes on multiple time frames, and to perhaps put a watchlist column in place to be able to easily pick off tickers changing polarity.

declare lower;
## KAMA (Kaufman Adaptive Moving Average) Settings
input price = close;
input KAMAfastLength = 2;
input KAMAslowLength = 30;
input effRatioLength = 10;
input mode = {default KAMA, AMA};

Assert(KAMAfastLength > 0, "'fast length' must be positive: " + KAMAfastLength);
Assert(KAMAslowLength > 0, "'slow length' must be positive: " + KAMAslowLength);

def direction;
def volatility;
def ER;

switch (mode) {
case KAMA:
    direction = AbsValue(price - price[effRatioLength]);
    volatility = Sum(AbsValue(price - price[1]), effRatioLength);
    ER = if volatility != 0 then direction / volatility else 0;
case AMA:
    direction = Double.NaN;
    volatility = Double.NaN;
    ER = AbsValue((price - Lowest(low, effRatioLength)) -
(Highest(high, effRatioLength) - price)) / (Highest(high,
effRatioLength) - Lowest(low, effRatioLength));

def FastSF = 2 / (KAMAfastLength + 1);
def SlowSF = 2 / (KAMAslowLength + 1);
def ScaledSF = ER * (FastSF - SlowSF) + SlowSF;
def AMA = CompoundValue(1, AMA[1] + Sqr(ScaledSF) * (price - AMA[1]),

def MovAvgAdaptive = AMA;

## EMA Settings
input length = 34;
input displace = 0;

def AvgExp = ExpAverage(price[-displace], length);


input fastLength = 12;
input slowLength = 26;
input macdLength = 9;
input averageType = AverageType.EXPONENTIAL;

def diff = reference MACD(fastLength, slowLength, macdLength, averageType).Diff;

## Volume
def Vol = volume(period = AggregationPeriod.DAY);

def avg30dayVol = Average(volume, 30);

def today = volume;
def avg30periodVol = Average(volume, 30);

def BuyVolumeSignal = (today / avg30periodVol) * 100;
def SellVolumeSignal = (today / avg30periodVol) * 100;

def condition1 = price > MovAvgAdaptive and price > AvgExp and BuyVolumeSignal > 15 is true;

def condition2 = price < MovAvgAdaptive and price < AvgExp and BuyVolumeSignal > 15;

plot trend = if condition1 is true then 1 else if condition2 >0 then -1 else 0;
trend.DefineColor("Up", Color.UPTICK);
trend.DefineColor("Down", Color.DOWNTICK);
trend.AssignValueColor(if trend > 0 then trend.Color("Up") else if trend < 0 then trend.Color("Down") else GetColor(1));

input DoAlerts = Yes;
Alert(condition1, "Cainer Buy", Alert.BAR, Sound.Ring );
Alert(condition2, "Cainer Sell", Alert.BAR, Sound.Bell );

Any suggestions would be greatly appreciated, and of course you get to use this. We use it to trade /ES and /NQ futures quite successfully.


Active member
Can you explain which timeframe this is most effective? Is it intended to buy and sell on every signal?


New member
Is there a code for the Kaufman Efficiency Ratio Indicator? I read on Google there was, but I can't seem to find it.

Edit: found it, shared by @tomsk. Developed by Mobius.

# Kaufman Efficiency Ratio
# Mobius
# 1.29.2017

# Here's the Kaufman Efficiency Ratio that the Kaufman AMA is based on.
# Notes: Price at extremes are entry / exit signals. Price in zone between extremes and equity should be avoided.

declare lower;

input n = 10;

def netchg = close - close[n];
def sumchg = sum(AbsValue(close - close[1]), n);
plot KER = (netchg / sumchg);
plot zero = if isNaN(close) then double.nan else 0;
plot OB = HighestAll(KER) * .8;
plot OS = LowestAll(KER) * .8;
# End Code Kaufman Efficiency Ratio


New member
I've found numerous references to this indicator, including one about translating from the TOS version to TradeStation. I know that we have the lower half of the indicator, but I'm looking for the full version that plots on the main chart too.]

Thanks for the help, Wayneg
Last edited:


New member
I'm trying to figure out how to get a buy and sell arrows to show up on the chart when the alerts go off.

Thanks for the help.

Similar threads