Kaufman2_v2

Download script
Author: Copyright � 2004, by konKop, GOODMAN, Mstera, af + wellx
Kaufman2_v2

This tool is designed to provide a smoother, more responsive visual representation of market trends by filtering out "market noise"—those minor, erratic price fluctuations that can often lead to false signals for traders. Instead of simply averaging prices in a linear fashion, this script employs an adaptive logic that adjusts itself based on the current state of the market volatility.

How the Logic Works

The core intelligence of the script lies in its ability to distinguish between significant price movements and insignificant "chatter." It achieves this through a three-step analytical process:

1. Noise vs. Signal Identification The script constantly compares the total distance a price has moved over a specific period against the cumulative movement of every individual price tick within that same timeframe.

  • If the market is moving steadily in one direction, the "signal" is high relative to the "noise."
  • If the price is oscillating wildly without making much progress, the "noise" becomes dominant.

2. The Efficiency Ratio (ER) By dividing the signal by the noise, the script calculates an Efficiency Ratio. This value tells the tool how "efficiently" the market is trending. A high efficiency suggests a strong, clear trend, while a low efficiency suggests a choppy, sideways, or unstable market.

3. Dynamic Smoothing (The Kaufman Adaptation) This is where the adaptation happens. The script uses the Efficiency Ratio to adjust the weighting of the moving average:

  • In a Strong Trend: When the market shows high efficiency, the script reacts more quickly to new price data, allowing the indicator line to follow the trend closely without lagging behind.
  • In a Choppy Market: When the market is noisy and inefficient, the script automatically "slows down." It puts more weight on previous data and less on the current erratic price action, preventing the line from jumping around unnecessarily.

Summary for the User

Think of this indicator as an intelligent filter. Rather than providing a generic moving average that might be too slow during a breakout or too jumpy during consolidation, this script "feels" the market texture. It attempts to provide a clean, flowing line that stays glued to the primary trend while remaining stubborn enough to ignore the distractions of minor price fluctuations.

Miscellaneous
Implements a curve of type %1
7 Views
0 Downloads
0 Favorites
Kaufman2_v2
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                      Kaufman.mq4 |
//|                              Copyright © 2004, by konKop & wellx |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, by konKop, GOODMAN, Mstera, af + wellx"
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Sienna
//---- input parameters
extern int       periodAMA=9;
extern int       nfast=2;
extern int       nslow=30;
extern int       G=2;

//---- buffers
double kAMAbuffer[];
//+------------------------------------------------------------------+

int    cbars=0;
double slowSC,fastSC;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   //SetIndexDrawBegin(0,nslow+nfast);
   SetIndexBuffer(0,kAMAbuffer);
   IndicatorDigits(6);
   
   //slowSC=0.064516;
   //fastSC=0.2;
   
   cbars=IndicatorCounted();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    i,pos=0;
   double noise,noise0,AMA,AMA0,signal,ER;
   double dSC,ERSC,wlxSSC;
   
//---- TODO: add your code here
   slowSC=(2.0 /(nslow+1));
   fastSC=(2.0 /(nfast+1));
   

   if (Bars<=(periodAMA+2)) return(0);
   
   
   //---- check for possible errors
   if (cbars<0) return(-1);
//---- last counted bar will be recounted
   if (cbars>0) cbars--;
   pos=Bars-periodAMA-2;
   //pos=100;
   //Print("cbars1: ", cbars);
   AMA0=Close[pos+1];
   while (pos>=0)
     {
      if(pos==Bars-periodAMA-2) AMA0=Close[pos+1];
      signal=MathAbs(Close[pos]-Close[pos+periodAMA]);
      noise=0;
      for(i=0;i<periodAMA;i++)
       {
        noise=noise+MathAbs(Close[pos+i]-Close[pos+i+1]);
       };
      ER =signal/noise;
      dSC=(fastSC-slowSC);
      ERSC=ER*dSC;
      wlxSSC=ERSC+slowSC;
      AMA=AMA0+(MathPow(wlxSSC,G)*(Close[pos]-AMA0));
      kAMAbuffer[pos]=AMA;
      
      /*
      Print("dsC: ", dSC);
      Print("ERSC: ", ERSC);
      Print("slowSc: ", slowSC);
      Print("fastSc: ", fastSC);
      Print("signal: ", signal);
      Print("noise: ",  noise);
      Print("SSC: ", wlxSSC);
      Print("AMA0: ", AMA0);
      Print("AMA: ", AMA);
      Print("MathPow: ", MathPow(wlxSSC,G));
      Print("pos: ", pos);
      Print("close[pos]: ", Close[pos]);
      Print("------------------------ ", 0);
    */
      AMA0=AMA;
      pos--;
     };
     //Print("cbars2: ", cbars);
//----
   return(0);
  }

Comments