Author: Copyright � 2004, by konKop, GOODMAN, Mstera, af + wellx
Kaufman2

This tool is designed to provide a smoother, more responsive visual trend line on your trading charts compared to standard moving averages. Its primary objective is to filter out market "noise"—those small, insignificant price fluctuations—so that traders can more clearly identify the underlying direction of the market.

How the Logic Works

The script functions by measuring the relationship between the actual price movement and the general background volatility of the market. It processes this information through several key steps:

1. Signal vs. Noise Detection The tool first looks at the current price change over a specific window of time (the period) and compares it to the total amount of "jitter" or noise occurring within that same timeframe. By dividing the significant signal by the total noise, the script determines an Efficiency Ratio. This ratio tells the tool how effectively the price is moving in a specific direction versus how much it is simply fluctuating randomly.

2. Speed Adjustment The logic uses two different speed settings—a "fast" and a "slow" component. These are used to calculate a difference that helps the indicator decide how aggressively it should react to new data. If the market is moving efficiently in one direction, the indicator leans toward the "fast" setting; if the market is messy and volatile, it stays closer to the "slow" setting.

3. Dynamic Smoothing Instead of applying a flat average (which often results in a laggy line), this script uses a dynamic formula. It takes the current price and blends it with the previous value based on the Efficiency Ratio and the speed settings mentioned above. By raising these factors to a specific power, the script can "stretch" or "compress" the line's responsiveness.

The Result for the Trader

The end result is a dynamic trend line that:

  • Flattens out during choppy, sideways markets to avoid giving false signals.
  • Tightens and follows the price more closely when a clear, strong trend emerges.
  • Reduces Lag: By intelligently accounting for market efficiency, it aims to stay closer to the current price than traditional moving averages while remaining smooth enough to be readable.
Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
Kaufman2
//+------------------------------------------------------------------+
//|                                                      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