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[1]), 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
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

# 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[1]), 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;

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

AddCloud(KER, 0, Color.green, color.dark_orange);
AddVerticalLine(BuySignal, round(close,2), Color.GREEN, Curve.FIRM);
AddVerticalLine(SellSignal, round(close,2), color.red, Curve.FIRM);
 
# 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[1]), 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;

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

AddCloud(KER, 0, Color.green, color.dark_orange);
AddVerticalLine(BuySignal, round(close,2), Color.GREEN, Curve.FIRM);
AddVerticalLine(SellSignal, round(close,2), color.red, Curve.FIRM);
this does a great job at calling tops and bottoms,
 
Last edited by a moderator:
It would depend on the time frame you are using to trade since the signal is using highestall/lowestall.
 
Last edited by a moderator:
Hi - This looks like an easily understood version of Kaufman's Efficiency Ratio. Please convert.
https://www.tradingview.com/script/saQyrlDt-Efficiency-Ratio-Market-Noise-by-Alejandro-P/

Code:
//@version=4
//@author=© Alexter6277
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.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
419 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top