AMA_SLOPE_v2

Download script
Author: Kalenzo
AMA_SLOPE_v2

The AMA Slope indicator is a sophisticated technical analysis tool designed to help traders visualize and interpret the momentum of price movements by measuring the "slope" or the rate of change in a smoothed moving average. Unlike standard indicators that simply follow price, this tool focuses on the velocity and direction of price trends to filter out market noise.

Core Logic and Functionality

The indicator operates using several distinct mathematical layers to provide a clear picture of market sentiment:

1. Dynamic Smoothing and Noise Filtering At its core, the script calculates a specialized type of moving average. It does not treat all price movements equally; instead, it analyzes the "noise" of the market—the small, erratic fluctuations that often lead to false signals. By comparing the actual signal strength against this calculated noise, the indicator can distinguish between significant trend changes and minor market vibrations.

2. Signal Calculation The logic utilizes two different smoothing coefficients (a fast and a slow setting). By calculating the difference between these two, the tool determines the "momentum" of the current price action. It then applies a power factor to this data, which allows it to react more aggressively to strong trends while remaining stable during periods of consolidation.

3. Slope Visualization (The Main Output) Rather than just showing the value of the average, this script plots the change in the average.

  • Positive Slope: When the moving average is rising, the indicator reflects a positive value, suggesting upward momentum.
  • Negative Slope: When the moving average is falling, it reflects a negative value, indicating downward momentum.

4. Visual Representation The tool provides four different visual outputs to make interpretation easy for the user:

  • Lines: These represent the raw change in the slope.
  • Histograms: The script uses a dual-histogram system that separates upward and downward movements into distinct bars. This allows you to see at a glance whether the current momentum is bullish (positive) or bearish (negative).
  • Trigger Levels: The indicator automatically draws two horizontal "Trigger" lines (one positive, one negative). These serve as visual boundaries; when the slope exceeds these levels, it suggests that the trend momentum has reached a significant threshold.

Summary for Traders

The AMA Slope is designed to help you identify the "health" of a trend. By looking at the histograms and the position of the price relative to the trigger lines, you can determine if a trend is strengthening, weakening, or reversing. It effectively acts as a momentum filter, helping traders stay on the right side of the trend while ignoring the insignificant "noise" of the daily market.

Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
AMA_SLOPE_v2
//+------------------------------------------------------------------+
//|                                                    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 4
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Red
#property indicator_color4 Green
#property indicator_level1 0

//---- input parameters
extern int       periodAMA=9;
extern int       nfast=2;
extern int       nslow=30;
extern double    G=2.0;
extern int       trigger = 2;
extern color     triggerPlus = Green;
extern color     triggerMinus = Red;
//---- buffers
double kAMAbuffer[];
double kAMAbuffer2[];

double amahisto1[];
double amahisto2[];
//+------------------------------------------------------------------+

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);
   SetIndexStyle(1,DRAW_LINE,0,1);
   SetIndexBuffer(1,kAMAbuffer2);
   
   SetIndexStyle(2,DRAW_HISTOGRAM,0,1);
   SetIndexBuffer(2,amahisto1);
   SetIndexStyle(3,DRAW_HISTOGRAM,0,1);
   SetIndexBuffer(3,amahisto2);
 
   IndicatorDigits(4);
   IndicatorShortName("AMA SLOPE");
   
   

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   drawLine((trigger*Point),"Trigger+", triggerPlus);
   drawLine((-trigger*Point),"Trigger-", triggerMinus);
   
   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;     
      
      if(ddK<0)
      kAMAbuffer2[pos]=ddK;     
      
      if(ddK<0)
      {
         amahisto1[pos] = ddK;
         amahisto2[pos] = 0;
      }
      else
      {
         amahisto2[pos] = ddK;
         amahisto1[pos] = 0;  
      }
      
      AMA0=AMA;
      pos--;
     }
//----
   
   prevbars=Bars;
   return(0);
  }

void drawLine(double lvl,string name, color Col)
{
         if(ObjectFind(name) == 0)
         {
            ObjectCreate(name, OBJ_HLINE, WindowFind("AMA SLOPE") , Time[0], lvl,Time[0],lvl);
            ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
            ObjectSet(name, OBJPROP_COLOR, Col);
            ObjectSet(name,OBJPROP_WIDTH,1);
         }
         else
         {
            ObjectDelete(name);
            ObjectCreate(name, OBJ_HLINE, WindowFind("AMA SLOPE") , Time[0], lvl,Time[0],lvl);
            ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
            ObjectSet(name, OBJPROP_COLOR, Col);
            ObjectSet(name,OBJPROP_WIDTH,1);
         }
}

Comments