# Kaufman Efficiency Ratio For ThinkOrSwim

#### Lauri

##### New member
VIP
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.

Code:
``````# 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), n);
plot KER = (netchg / sumchg);
KER.SetStyle(Curve.Firm);
KER.SetDefaultColor(Color.Cyan);
plot zero = if isNaN(close) then double.nan else 0;
zero.SetDefaultColor(Color.gray);
plot OB = HighestAll(KER) * .8;
OB.SetDefaultColor(Color.red);
plot OS = LowestAll(KER) * .8;
OS.SetDefaultColor(Color.green);
# End Code Kaufman Efficiency Ratio``````

# Kaufman Efficiency Ratio by Bezna\$
# It's a good idea to have one at n=50 and an othe one at n=80
# ----------------------------------------------------------
declare lower;
input N = 50;
input Threshold = .80;
def netchg = close - close[N];
def sumchg = Sum(AbsValue(close - close), N);
plot KER = round((netchg / sumchg), 2);
KER.SetStyle(Curve.FIRM);
KER.SetDefaultColor(Color.light_gray);
KER.SetLineWeight(1);

plot Zero = 0;
Zero.SetDefaultColor(Color.white);

plot OS = HighestAll(KER) * Threshold; #.8;
OS.SetDefaultColor(Color.RED);

plot OB = LowestAll(KER) * Threshold; #.8;
OB.SetDefaultColor(Color.GREEN);

def Buy = KER < OB;
def Sell = KER > OS;

#=============
KER.DefineColor("Neutral", Color.gray);
KER.DefineColor("Sell", Color.RED);
#==================
def SellSignal = if KER crosses above OS then KER else Double.NaN;
def BuySignal = if KER crosses below OB then KER else Double.NaN;

# Kaufman Efficiency Ratio by Bezna\$
# It's a good idea to have one at n=50 and an othe one at n=80
# ----------------------------------------------------------
declare lower;
input N = 50;
input Threshold = .80;
def netchg = close - close[N];
def sumchg = Sum(AbsValue(close - close), N);
plot KER = round((netchg / sumchg), 2);
KER.SetStyle(Curve.FIRM);
KER.SetDefaultColor(Color.light_gray);
KER.SetLineWeight(1);

plot Zero = 0;
Zero.SetDefaultColor(Color.white);

plot OS = HighestAll(KER) * Threshold; #.8;
OS.SetDefaultColor(Color.RED);

plot OB = LowestAll(KER) * Threshold; #.8;
OB.SetDefaultColor(Color.GREEN);

def Buy = KER < OB;
def Sell = KER > OS;

#=============
KER.DefineColor("Neutral", Color.gray);
KER.DefineColor("Sell", Color.RED);
#==================
def SellSignal = if KER crosses above OS then KER else Double.NaN;
def BuySignal = if KER crosses below OB then KER else Double.NaN;

this does a great job at calling tops and bottoms,

Last edited by a moderator:
I've tried this indicator at SPY. But it seems not so great as germanburrito said. Could you post a screenshot?

It would depend on the time frame you are using to trade since the signal is using highestall/lowestall.

I've tried this indicator at SPY. But it seems not so great as germanburrito said. Could you post a screenshot?
yeah it depends on how much data you have, meaning if you're looking back at 5 days, 10 days, 20, etc.. I found that RSI its still king.

yeah it depends on how much data you have, meaning if you're looking back at 5 days, 10 days, 20, etc.. I found that RSI its still king.
Agreed RSI is the king specially if you use dominant cycle period for the length.

There is an indicator on trading view which helps you find it but can't locate the indicator right now.

Last edited by a moderator:
Hi - This looks like an easily understood version of Kaufman's Efficiency Ratio. Please convert.

Code:
``````//@version=4
study(title="Efficiency Ratio (Market Noise) by Alejandro P", shorttitle="Efficiency Ratio - AP", overlay=false, precision=2, resolution="")

ERLength = input(10, minval=1, title="Efficiency Ratio Length")
UseDirectional = input(false, title="Use Directional Efficiency Ratio",tooltip="If Use Directional Efficiency Ratio is \"true\" then the calculation will take into account the drection of the market moves and will have values of -100 to 100 while when it is \"false\" the basic ratio will be used with values between 0 to 100")
UseRelative = input(true,"Use Relative Color Markers", tooltip="By selecting to use Relaive Colors the script will change the color of the indicator values to show if the level is low, medium, high or extreme.",group="Relative Color")
ExtremeLevel = input(95.0, minval=0, maxval=100, title="% Extreme Level",group="Relative Color")
HighLevel = input(50.0, minval=0, maxval=100, title="% High Level",group="Relative Color")
LowLevel = input(25.0, minval=0, maxval=100, title="% Low Level",group="Relative Color")

// Relative ATR Percent Function
EfficiencyRatio (source,length,driectional) =>
netchange = driectional ? source - source[length] : abs(source - source[length])
SumOfChanges = 0.0
for i = 0 to length-1
SumOfChanges := SumOfChanges + abs(source[i] - source[i+1])
EffRatio = (netchange / SumOfChanges)*100
EffRatio

ER = EfficiencyRatio(close,ERLength,UseDirectional)

clr = (ER >= ExtremeLevel or ER <= -ExtremeLevel) ? color.purple : (ER >= HighLevel or ER <= -HighLevel) ? color.green : (ER >= LowLevel or ER <= -LowLevel) ? color.blue : color.red

plot(ER, "Efficiency Ratio",style=plot.style_columns ,color = UseRelative?clr:color.blue)``````
check the below

CSS:
``````#//@author=© Alexter6277
#study(title="Efficiency Ratio (Market Noise) by Alejandro P", shorttitle="Efficiency Ratio - AP",
# Converted by Sam4Cok@Samer800 - 01/2023 - request from UseThinkScript.com member
Declare lower;
input Src      = close;
input ERLength = 10;          # "Efficiency Ratio Length"
input UseDirectional = no;    # "Use Directional Efficiency Ratio"
input UseRelative = yes;      # "Use Relative Color Markers"
input ExtremeLevel = 95.0;    # "% Extreme Level"
input HighLevel = 50.0;       # "% High Level"
input LowLevel = 25.0;        # "% Low Level"

#// Relative ATR Percent Function
#EfficiencyRatio (source,length,driectional) =>
script EfficiencyRatio {
input source = close;
input length = 10;
input driectional = yes;
def netchange = if driectional then  source - source[length] else AbsValue(source - source[length]);
def SumOfChanges;
SumOfChanges = fold i = 0 to length  with p do
p + AbsValue(source[i] - GetValue(source, i+1));
def EffRatio = (netchange / SumOfChanges)*100;
plot Return = EffRatio;
}

def ER = EfficiencyRatio(Src,ERLength,UseDirectional);

def clr = if (ER >= ExtremeLevel or ER <= -ExtremeLevel) then -2 else
if (ER >= HighLevel or ER <= -HighLevel) then 2 else
if (ER >= LowLevel or ER <= -LowLevel) then 1 else 0;

plot EfficiencyRatio = ER;#, "Efficiency Ratio"
EfficiencyRatio.SetLineWeight(4);
EfficiencyRatio.SetPaintingStrategy(PAintingStrategy.HISTOGRAM);
EfficiencyRatio.AssignValueColor(if !UseRelative then CreateColor(33,150,243) else
if clr ==-2 then CreateColor(156,39,176) else
if clr == 2 then CreateColor(76,175,80) else
if clr == 1 then CreateColor(33,150,243) else Color.RED);

#--- END CODE``````

• check the below

CSS:
``````#//@author=© Alexter6277
#study(title="Efficiency Ratio (Market Noise) by Alejandro P", shorttitle="Efficiency Ratio - AP",
# Converted by Sam4Cok@Samer800 - 01/2023 - request from UseThinkScript.com member
Declare lower;
input Src      = close;
input ERLength = 10;          # "Efficiency Ratio Length"
input UseDirectional = no;    # "Use Directional Efficiency Ratio"
input UseRelative = yes;      # "Use Relative Color Markers"
input ExtremeLevel = 95.0;    # "% Extreme Level"
input HighLevel = 50.0;       # "% High Level"
input LowLevel = 25.0;        # "% Low Level"

#// Relative ATR Percent Function
#EfficiencyRatio (source,length,driectional) =>
script EfficiencyRatio {
input source = close;
input length = 10;
input driectional = yes;
def netchange = if driectional then  source - source[length] else AbsValue(source - source[length]);
def SumOfChanges;
SumOfChanges = fold i = 0 to length  with p do
p + AbsValue(source[i] - GetValue(source, i+1));
def EffRatio = (netchange / SumOfChanges)*100;
plot Return = EffRatio;
}

def ER = EfficiencyRatio(Src,ERLength,UseDirectional);

def clr = if (ER >= ExtremeLevel or ER <= -ExtremeLevel) then -2 else
if (ER >= HighLevel or ER <= -HighLevel) then 2 else
if (ER >= LowLevel or ER <= -LowLevel) then 1 else 0;

plot EfficiencyRatio = ER;#, "Efficiency Ratio"
EfficiencyRatio.SetLineWeight(4);
EfficiencyRatio.SetPaintingStrategy(PAintingStrategy.HISTOGRAM);
EfficiencyRatio.AssignValueColor(if !UseRelative then CreateColor(33,150,243) else
if clr ==-2 then CreateColor(156,39,176) else
if clr == 2 then CreateColor(76,175,80) else
if clr == 1 then CreateColor(33,150,243) else Color.RED);

#--- END CODE``````
Awesome! Thank you, samer800.

### Not the exact question you're looking for?

87k+ Posts
312 Online ## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?