Author: Copyright ?2005, MetaQuotes Software Corp.
KAMARev_v1

This script is a custom technical analysis tool designed to help traders visualize market trends and price movements more smoothly than standard indicators. It utilizes a sophisticated smoothing logic that balances two competing factors: the direction of the price movement and the intensity of market volatility.

How the Logic Works

The tool operates by analyzing price data over specific timeframes to generate a series of visual lines. Here is a breakdown of the underlying logic:

1. Volatility and Direction Analysis Instead of simply looking at where the price is going, the script calculates how "noisy" or "active" the market is. It measures the total movement (volatility) over a set period and compares it to the actual direction of the price change. This allows the tool to distinguish between a strong, steady trend and erratic, sideways market noise.

2. Dynamic Smoothing (The KAMA Logic) The core engine uses a specialized calculation that adapts to the market environment:

  • In low-volatility markets, the indicator remains "tight" to the price to ensure it doesn't lag behind significant moves.
  • In high-volatility markets, the indicator smooths out more aggressively to prevent the trader from being misled by minor, temporary price fluctuations.

3. Trend Detection and Scaling The script tracks these smoothed values to determine the "momentum" of the price. It calculates the difference between current values and previous values (using a lookback period) to identify the strength of the trend.

4. Visual Output The results are displayed in a separate window as four distinct lines:

  • Primary Trend Line: The main smoothed moving average that follows the primary price action.
  • Momentum Line: A scaled representation of the change in the trend, making it easier to see if the current movement is accelerating or decelerating.
  • Reference Boundaries: Two steady horizontal lines (based on a customizable "Revolution Point") that act as visual markers to help traders identify specific price levels or equilibrium zones.

Summary for the Trader

Essentially, this tool filters out the "market noise" to show you the underlying trend. By accounting for volatility, it helps you stay on the right side of a trend during stable periods while providing a cushioned, less reactive view during wild market swings. It provides a clearer picture of whether the price is truly moving with intent or just vibrating in place.

Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
KAMARev_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 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