AMA_v1
Download scriptThis script is designed as a specialized technical analysis tool for the MetaTrader platform, intended to help traders identify market trends and potential entry points by smoothing out price fluctuations. Instead of simply following the raw price movement, it uses a sophisticated mathematical approach to distinguish between meaningful market trends and insignificant "noise."
Core Logic and Functionality
The tool operates by calculating a customized moving average that adapts to the current market environment. Here is how the logic flows:
1. Signal vs. Noise Filtering The primary intelligence of this script lies in its ability to measure volatility. It compares the overall price change over a specific period against the sum of all individual fluctuations within that same period. By calculating this ratio, the tool can determine if a move is a significant trend (high signal) or merely random market chatter (high noise).
2. Adaptive Sensitivity The script uses two distinct speeds—a "fast" and a "slow" component—to weigh the data. It creates a dynamic coefficient based on these two speeds. This allows the indicator to react quickly to genuine momentum shifts while remaining steady during periods of low activity, effectively "filtering" out the erratic jumps that often mislead manual traders.
3. Dynamic Trend Smoothing The indicator produces a smoothed line on your chart. Unlike a standard moving average, which treats all past data with equal importance, this script applies an exponential power to the calculated variance. This creates a smoother curve that follows the "meat" of the price action more closely.
4. Visual Entry Signals Beyond just providing a smooth line for trend observation, the script identifies specific moments of momentum change:
- Upward Signals: When the smoothed line moves upward by a specific predefined distance, the script flags a potential bullish movement.
- Downward Signals: When the smoothed line drops by that same distance, it flags a potential bearish movement.
These signals are displayed as specific icons on the chart, alerting the user to where the momentum has shifted significantly enough to potentially warrant an attention point.
Summary for the User
Essentially, this tool acts as a "smart filter." It looks at the history of price action, calculates how much of that movement is actual trend and how much is just noise, and then draws a smooth path that follows the true direction of the market. It then places visual markers on the chart whenever the price moves with enough strength to suggest a new trend has begun.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| 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