Author: Copyright � 2004, by konKop,wellx
AMA_003

This script is designed as a technical analysis tool for trading platforms, specifically created to help traders visualize market trends and identify potential entry or exit points. It uses a sophisticated smoothing technique known as an Adaptive Moving Average (AMA) to filter out "market noise" and highlight the underlying direction of price movement.

How the Logic Works

1. Dynamic Adaptation (The "Adaptive" Element) Unlike standard moving averages that apply a fixed weight to past prices, this script calculates how much "noise" is currently in the market. It measures the volatility by comparing recent price changes against a larger historical window.

  • In stable markets: The indicator reacts smoothly to keep the trend line steady.
  • In volatile markets: The indicator adjusts its sensitivity to account for rapid fluctuations, attempting to distinguish between a significant trend change and mere random price "jitter."

2. Trend Tracking The script produces a primary visual line (the AMA). This line acts as a smoothed representation of the price history. By following this line, traders can more easily identify whether the current market sentiment is bullish (upward) or bearish (downward), as it ignores minor, insignificant price spikes that often occur in shorter timeframes.

3. Signal Detection (Up and Down Arrows) Beyond just showing a trend line, the script includes an automated logic to identify specific turning points. It calculates the difference between the current value of the AMA and its previous position:

  • Buy Signals: If the AMA moves upward significantly beyond a specific threshold (defined by the user), the script places a visual marker on the chart.
  • Sell Signals: If the AMA moves downward significantly beyond that same threshold, it places a corresponding marker in the opposite direction.

Key Parameters for Customization

The logic relies on several adjustable settings that allow users to "tune" the indicator to different assets (like Forex, Gold, or Stocks):

  • Period Sensitivity: Determines how far back the indicator looks to calculate its averages.
  • Fast/Slow Settings: These define the boundaries for the adaptive calculation—essentially telling the script how to differentiate between a fast trend and a slow move.
  • Threshold (dK): This acts as a "filter" to ensure that the arrows only appear when the move is substantial enough to be considered significant, preventing the chart from being cluttered with too many minor signals.

Summary for the User

In short, this tool helps you see the "big picture." It smooths out the erratic movements of the market to show you the true trend and automatically flags moments where that trend gains enough momentum to potentially indicate a trading opportunity.

Miscellaneous
Implements a curve of type %1
17 Views
0 Downloads
0 Favorites
AMA_003
//+------------------------------------------------------------------+
//|                                                          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 Sienna
#property indicator_color2 DeepSkyBlue
#property indicator_color3 Gold

//---- 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