KAMARev2_v1

Download script
Author: Copyright ?2005, MetaQuotes Software Corp.
KAMARev2_v1

This technical indicator is designed to analyze market trends by combining price movement, historical volatility, and specific smoothing techniques. It functions as a visual tool that helps traders identify the underlying momentum of an asset while filtering out "market noise."

Core Logic Overview

The script operates through three primary logical stages:

1. Volatility and Direction Analysis The indicator begins by looking at the price movement over a specific period (defined by the "KAMA Period" setting). It calculates two key values:

  • Direction: The difference between the current price and the price from a set number of candles ago.
  • Volatility: The total sum of absolute price changes during that same period.

By comparing these two figures, the script determines an Efficiency Ratio (ER). This ratio measures how efficiently the price is moving toward a target; if the price moves significantly in one direction with little fluctuation, the ratio is high. If the price moves erratically without much progress, the ratio is low.

2. Adaptive Smoothing (KAMA Logic) Instead of using a standard moving average—which treats all price changes equally—this script uses an adaptive approach. It applies different "scaling factors" based on the volatility calculated in the previous step.

  • In high-volatility markets, the indicator adjusts its sensitivity to react more quickly to new data.
  • In low-volatility or "choppy" markets, it smooths out the line significantly to prevent false signals.

3. Momentum and Visual Output Once the core price trend is calculated, the script performs additional calculations to provide visual cues:

  • Momentum Calculation: It tracks the change between the smoothed price and its position several candles back. This helps visualize the "speed" of the trend.
  • Visual Scaling: The indicator scales these values into a readable format on a separate window. It produces multiple lines that represent the primary trend, the momentum, and specific threshold boundaries (based on the "RevPoint" setting).

Summary for the Trader

Essentially, this tool doesn't just tell you where the price is; it tells you how smoothly and quickly the price is moving in a certain direction. By weighing the efficiency of a move against its overall volatility, it aims to provide a clearer picture of the market trend than a standard moving average could offer alone.

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

//+------------------------------------------------------------------+
//|                                                      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 FastSC = (2.0/(2.0 + 1.0));
		double SlowSC = (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