Author: Copyright ?2005, MetaQuotes Software Corp.
KAMARev

This technical tool is designed to provide traders with a visual representation of market momentum and volatility by smoothing out price fluctuations. Instead of just following the raw price movements, which can be noisy and erratic, this script calculates a dynamic trend line that reacts differently depending on how much "action" is happening in the market.

Core Logic Overview

The script operates by analyzing two primary factors: the direction of price movement over a specific timeframe and the total volatility (the speed and size of price changes) during that same period.

1. Trend Analysis & Volatility Measurement The tool looks back at a set number of price bars to determine the current market direction. Simultaneously, it calculates the "Volatility" by summing up all the absolute price movements within that window. This helps the script distinguish between a strong, purposeful move in the market and insignificant "jitter."

2. The Efficiency Ratio (ER) By comparing the total distance moved in a specific direction against the total volatility of the market, the script calculates an "Efficiency Ratio." This allows the tool to understand how much of the market's movement is actually meaningful progress in one direction versus random noise.

3. Dynamic Smoothing The logic uses this Efficiency Ratio to adjust its sensitivity.

  • When the market is moving efficiently (a clear trend), the indicator reacts more decisively.
  • When the market is choppy or sideways (high volatility but little net movement), the indicator smooths out the data to prevent "false signals."

4. Visual Output & Scaling The script generates multiple layers of data to help with visual interpretation:

  • The Main Trend: A calculated line that updates based on the smoothed price logic.
  • Movement Tracking: The tool tracks the change in this trend over a specific "LookBack" period, effectively measuring the velocity of the trend.
  • Reference Boundaries: It creates fixed visual reference points (based on a user-defined point value) to help traders identify specific price thresholds or zones of interest.

Summary for Traders

In plain terms, this script acts as a sophisticated "filter." It takes the chaotic movement of the market and converts it into a smoother, more readable trend line. By weighing the strength of a move against the overall noise of the market, it helps traders visualize where the price is heading while filtering out the distractions of minor price fluctuations.

Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
KAMARev
//+------------------------------------------------------------------+
//|                                                      KAMARev.mq4 |
//|                       Copyright ?2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Black
#property indicator_color2 Yellow
#property indicator_color3 Red
#property indicator_color4 Red

//---- input parameters
extern int KAMAPeriod=4;
extern int LookBack=3;
extern double RevPoint=0.0004;

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {   string short_name;
//---- indicators
 SetIndexStyle(0,DRAW_LINE);
 SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexStyle(2,DRAW_LINE);
    SetIndexBuffer(2, ExtMapBuffer3);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3, ExtMapBuffer4);
   
   short_name="KAMA("+KAMAPeriod+","+LookBack+","+RevPoint+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
  int Scale=500;
  int    i,counted_bars=IndicatorCounted();
  double tmp[];
   double rel,negative,positive;
  if(Bars<=KAMAPeriod) return(0);
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=KAMAPeriod;i++) ExtMapBuffer1[Bars-i]=0.0;

   if(counted_bars>=KAMAPeriod) i=Bars-counted_bars-1;
  
   if(counted_bars<0) return(-1);

   int limit=Bars-counted_bars;
//---- TODO: add your code here
   double FastSC = (double)(2.0/(2.0 + 1.0));
		double SlowSC = (double)(2.0/(30.0 + 1.0));
		
		double Direction=0;
		double Volatility=0;
		double ER=0;
		double SSC=0;	
		double Constant=0;
		int start=counted_bars-1;
		
		int handle;
      
  
       start=0;
       limit=Bars;
	   for(i=start+limit; i>=start; i--){
				 Direction=Close[i]-Close[i+KAMAPeriod];
				 
				 double sum=0;
	for(int j=i+KAMAPeriod-1;(j>=i);j--){
		       sum+=MathAbs(Close[j]-Close[j+1]);
	}
	           Volatility=sum;
	           
				 if (Volatility==0) ER=0;
				 else
				 	ER=MathAbs(Direction/Volatility);
				 SSC= ER * (FastSC - SlowSC) + SlowSC;
				 Constant=SSC*SSC;
				if (i<KAMAPeriod)
					ExtMapBuffer1[i]=Close[i+1]+Constant*(Close[i]-Close[i+1]);
				else
					ExtMapBuffer1[i]=ExtMapBuffer1[i+1]+Constant*(Close[i]-ExtMapBuffer1[i+1]);
					
			
		
		//		ExtMapBuffer1[i]=ExtMapBuffer2[i]-ExtMapBuffer2[i+LookBack];
		double tmpd=ExtMapBuffer1[i]-ExtMapBuffer1[i+LookBack];
				ExtMapBuffer2[i]=tmpd*Scale;
				ExtMapBuffer3[i]=RevPoint*Scale;
				ExtMapBuffer4[i]=-1*RevPoint*Scale;

				
				
				
			
		}
//----
//   FileClose(handle);
   return(0);
  }
//+------------------------------------------------------------------+

Comments