b_Kaufman_Efficiency_Ratio
Download scriptThis tool is designed to measure the "quality" or "efficiency" of price movements in the financial markets. Rather than just looking at whether a price went up or down, it seeks to determine how much progress was made relative to the amount of turbulence encountered during that period.
Core Logic Overview
The indicator works by comparing two distinct metrics: Net Movement and Volatility. By dividing one by the other, it produces an "Efficiency Ratio." Here is a breakdown of how these components function:
- Net Price Movement: This looks at the total distance traveled between two points in time (defined by a user-set period). It calculates the straight-line distance from where the price started to where it ended.
- Volatility (Total Path): This measures the "path" the price took to get to its destination. It adds up every single tiny movement, fluctuation, and zig-zag that occurred during that same time frame.
How the Efficiency Ratio Works
By comparing these two numbers, the indicator provides a clear picture of market behavior:
- High Efficiency (Strong Trends): When the price moves decisively in one direction with very little "noise" or wandering, the total path (Volatility) is nearly equal to the straight-line distance (Net Movement). This results in a high efficiency score, suggesting a strong, healthy trend.
- Low Efficiency (Choppy Markets): If the price moves up and down significantly but ends up only a short distance from where it started, the total path traveled is very large compared to the net progress made. This results in a low efficiency score, signaling a "noisy" or sideways market where there is no clear direction.
Visual Representation
The script allows you to view this data in two ways depending on your preference: as a continuous line or as a histogram. It automatically adjusts to the specific currency or asset you are viewing, ensuring that the scale remains consistent and easy to read.
In short, this tool helps traders distinguish between a steady, productive move and a messy, exhausted price action, allowing for a better understanding of market momentum.
//+--------------------------------------------------------------------------------------------------+
//| b_Kaufman_Efficiency_Ratio.mq4 |
//| Copyright © 2011, barmenteros |
//| http://www.mql4.com/users/barmenteros |
//+--------------------------------------------------------------------------------------------------+
#property copyright "barmenteros"
#property link "barmenteros.fx@gmail.com"
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1
#property indicator_buffers 1
#property indicator_color1 Red
// ---- inputs
// ERperiod It should be >0. If not it will be autoset to default value
// histogram [true] - histogram style on; [false] - histogram style off
extern int ERperiod =10; // Efficiency ratio period
extern bool histogram =false; // Histogram switch
extern int shift =0; // Sets offset
// ---- buffers
double ERBfr[];
// ---- global variables
double direction, noise;
//+--------------------------------------------------------------------------------------------------+
//| Custom indicator initialization function |
//+--------------------------------------------------------------------------------------------------+
int init()
{
string short_name;
// ---- checking inputs
if(ERperiod<=0)
{
ERperiod=10;
Alert("ERperiod readjusted");
}
// ---- drawing settings
if(!histogram) SetIndexStyle(0,DRAW_LINE);
else SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexLabel(0,"KEffRatio");
SetIndexShift(0,shift);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
short_name="KEffRatio(";
IndicatorShortName(short_name+ERperiod+")");
// ---- mapping
SetIndexBuffer(0,ERBfr);
// ---- done
return(0);
}
//+--------------------------------------------------------------------------------------------------+
//| Custom indicator iteration function |
//+--------------------------------------------------------------------------------------------------+
int start()
{
// ---- optimization
if(Bars<ERperiod+2) return(0);
int counted_bars=IndicatorCounted(),
limit, maxbar,
i;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars-1;
maxbar=Bars-1-ERperiod;
if(limit>maxbar) limit=maxbar;
// ---- main cycle
for(i=limit; i>=0; i--)
{
direction=NetPriceMovement(i);
noise=Volatility(i);
if(direction==EMPTY_VALUE || noise==EMPTY_VALUE) continue;
if(noise==0.0) noise=0.000000001;
ERBfr[i]=direction/noise;
}
// ----
return(0);
}
double NetPriceMovement(int initialbar)
{
if(initialbar>Bars-ERperiod-1) return(EMPTY_VALUE);
double n;
n=MathAbs(Close[initialbar]-Close[initialbar+ERperiod]);
return(n);
}
double Volatility(int initialbar)
{
if(initialbar>Bars-ERperiod-1) return(EMPTY_VALUE);
int j;
double v=0.0;
for(j=0; j<ERperiod; j++)
v+=MathAbs(Close[initialbar+j]-Close[initialbar+1+j]);
return(v);
}
Comments