AMA_SLOPE_v1

Download script
Author: Kalenzo
AMA_SLOPE_v1

This tool is designed to analyze market trends by focusing on the "slope" or momentum of price movements, rather than just the price itself. It filters out minor market fluctuations to help identify the underlying direction of a trend more clearly.

How the Logic Works

The script functions by calculating a specialized type of moving average that adapts to the current volatility of the market. Here is the step-by-step breakdown of its internal logic:

1. Volatility Analysis (Noise Detection) The tool first looks at a specific window of recent price history (defined by the periodAMA setting). It calculates the "noise" in the market by measuring the sum of every price change within that window. By doing this, the tool can distinguish between a steady, significant move and erratic, insignificant price vibrations.

2. Signal Strength Calculation Simultaneously, it measures the difference between the current price and the price from a set period ago. It then compares this distance to the "noise" calculated in the first step. This creates a ratio: if the price is moving significantly more than the local noise, the signal is considered strong; if the price move is small compared to the noise, the signal is considered weak.

3. Dynamic Smoothing (The AMA Mechanism) Instead of using a fixed speed to calculate a moving average, this script uses a dynamic smoothing factor. It blends a "fast" and a "slow" calculation based on user-defined parameters. The result is a weighted value that adjusts automatically:

  • In trending markets, the tool reacts more quickly to keep up with the price.
  • In choppy or sideways markets, it slows down to prevent false signals caused by minor price "jitters."

4. Slope Identification The final output shown on your chart is not the price line itself, but rather the change (the slope) in this adaptive moving average. By plotting the difference between the current calculated value and the previous value, the tool highlights the velocity of the trend.

Summary for the User

In plain terms, this script acts as a "smart filter." It observes how much the price is moving compared to how much it is "shaking" (noise). It then uses that information to create a smooth trend line. The indicator you see on your screen represents the momentum of that line—showing you not just where the price is, but how strongly and smoothly it is moving in a specific direction.

Miscellaneous
Implements a curve of type %1
6 Views
0 Downloads
0 Favorites
AMA_SLOPE_v1
//+------------------------------------------------------------------+
//|                                                    AMA SLOPE.mq4 |
//|                                                          Kalenzo |
//|                                     bartlomiej.gorski@gmail.com  |
//|                I used the idea of P.Kauffman and code from KAMA  |
//|                                 made by © 2004, by konKop,wellx  |
//+------------------------------------------------------------------+
#property copyright "Kalenzo"
#property link      "bartlomiej.gorski@gmail.com"
//----
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 SaddleBrown
//---- input parameters
extern int       periodAMA=9;
extern int       nfast=2;
extern int       nslow=30;
extern double    G=2.0;
//---- buffers
double kAMAbuffer[];
//+------------------------------------------------------------------+
int    cbars=0, prevbars=0, prevtime=0;
double slowSC,fastSC;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,0,1);
   SetIndexBuffer(0,kAMAbuffer);
   IndicatorDigits(4);
   IndicatorShortName("AMA SLOPE");
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    i,pos=0;
   double noise=0.000000001,AMA,AMA0,signal,ER;
   double dSC,ERSC,SSC,ddK;
//----
   if (prevbars==Bars) return(0);
   slowSC=(2.0 /(nslow+1));
   fastSC=(2.0 /(nfast+1));
   cbars=IndicatorCounted();
//----
   if (Bars<=(periodAMA+2)) return(0);
   if (cbars<0) return(-1);
   if (cbars>0) cbars--;
   pos=Bars-periodAMA-2;
   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.000000001;
      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;
      SSC=ERSC+slowSC;
      AMA=AMA0+(MathPow(SSC,G)*(Close[pos]-AMA0));
      ddK=(AMA-AMA0);
      kAMAbuffer[pos]=ddK;
      AMA0=AMA;
      pos--;
     }
//----
   prevbars=Bars;
   return(0);
  }
//+------------------------------------------------------------------+

Comments