Author: Copyright � 2004, by konKop,wellx
AMA

This tool is designed as a technical analysis indicator for trading platforms, specifically engineered to help traders identify market trends and potential price movements by smoothing out market "noise." Unlike standard moving averages that can sometimes be sluggish or react too slowly to sudden changes, this script utilizes a dynamic approach to calculate price action.

Core Logic and Methodology

The primary goal of the logic is to distinguish between actual trend movements and minor, insignificant price fluctuations (noise). It achieves this through several distinct layers:

1. Noise Detection and Signal Calculation The script looks at a specific window of recent price data (defined by the user as the "period"). Within this window, it calculates the total amount of price movement to determine the "noise" level. Simultaneously, it measures the difference between the current price and the price from a set period ago to identify the actual "signal." By dividing the signal by the noise, the tool establishes a ratio that helps determine the strength and significance of the current market move.

2. Dynamic Adaptation The indicator uses a sophisticated smoothing mechanism that combines two different speeds: a "fast" component and a "slow" component. By comparing these two speeds against the calculated noise-to-signal ratio, the logic adjusts how much it reacts to new information.

  • In high-noise environments, the script becomes more conservative to prevent false signals.
  • In clear, trending environments, it adapts to follow the price movement more fluidly.

3. Trend Smoothing (The AMA Line) The result of these calculations produces a smoothed price line on your chart. This line acts as a primary visual guide; it follows the general direction of the market while filtering out the jagged "teeth" of standard price ticks. It provides a clearer picture of where the market is heading without the distraction of every minor fluctuation.

4. Automated Signal Alerts (Up and Down) Beyond just drawing a smooth line, the script includes an automated detection system for directional shifts. It monitors the mathematical difference between the current smoothed value and the previous one. If the change exceeds a specific threshold (defined by the user), the script identifies a significant move:

  • Bullish Signals: When the smoothed value moves upward with sufficient momentum, it marks a potential upward trend.
  • Bearish Signals: When the smoothed value drops with sufficient momentum, it marks a potential downward trend.

Summary for the Trader

In practical terms, this script helps you see the "big picture." It filters out the daily market chatter to show you the underlying trend. By providing both a smoothed line and specific markers for significant movements, it allows traders to identify when the market is gaining enough momentum to potentially initiate a new direction.

Miscellaneous
Implements a curve of type %1
16 Views
0 Downloads
0 Favorites
AMA
//+------------------------------------------------------------------+
//|                                                          AMA.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, by konKop,wellx"
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Ivory
#property indicator_color2 Blue
#property indicator_color3 Red
//---- input parameters
extern int       periodAMA=9;
extern int       nfast=2;
extern int       nslow=30;
extern double    G=2.0;
extern double    dK=2.0; 

//---- buffers
double kAMAbuffer[];
double kAMAupsig[];
double kAMAdownsig[];

//+------------------------------------------------------------------+

int    cbars=0, prevbars=0, prevtime=0;

double slowSC,fastSC;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,0,2);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,159);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,159);
   //SetIndexDrawBegin(0,nslow+nfast);
   SetIndexBuffer(0,kAMAbuffer);
   SetIndexBuffer(1,kAMAupsig);
   SetIndexBuffer(2,kAMAdownsig);
   
   
   IndicatorDigits(4);
   
   //slowSC=0.064516;
   //fastSC=0.2;
   //cbars=IndicatorCounted();
//----
   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);
    
//---- TODO: add your code here
   slowSC=(2.0 /(nslow+1));
   fastSC=(2.0 /(nfast+1));
   cbars=IndicatorCounted();
   if (Bars<=(periodAMA+2)) return(0);
//---- check for possible errors
   if (cbars<0) return(-1);
//---- last counted bar will be recounted
   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));
      kAMAbuffer[pos]=AMA;

      ddK=(AMA-AMA0);
      if ((MathAbs(ddK)) > (dK*Point) && (ddK > 0)) kAMAupsig[pos] =AMA; else kAMAupsig[pos]=0;
      if ((MathAbs(ddK)) > (dK*Point) && (ddK < 0)) kAMAdownsig[pos]=AMA; else kAMAdownsig[pos]=0; 

     
      AMA0=AMA;
      pos--;
     }
//----
   prevbars=Bars;
   return(0);
  }

Comments