Var Mov Avg
Download scriptThis technical tool is designed to help traders visualize price trends more smoothly while identifying specific moments where the market momentum shifts significantly. It works by calculating a customized version of an Adaptive Moving Average (AMA), which adjusts its behavior based on market conditions.
Core Logic and Functionality
The primary goal of this script is to distinguish between "noise" (minor, insignificant price fluctuations) and actual price trends. Here is how it achieves that:
1. Market Sensitivity Analysis Instead of treating every price movement the same way, the logic first calculates the relationship between current price changes and historical volatility. It measures the distance between current prices and compares it against the overall "noise" level over a specific period. This allows the indicator to react differently when the market is moving calmly versus when it is experiencing erratic jumps.
2. Adaptive Smoothing The tool uses two different speeds (fast and slow coefficients) to determine how much weight to give to recent data. By combining these, the indicator creates an "adaptive" curve. When the market shows a clear, strong trend, the moving average adjusts to follow that movement more closely; when the market is sideways or choppy, the average slows down to avoid giving false signals.
3. Trend Visualization The script plots a continuous line on your chart. This line represents the "smoothed" price of the asset, helping you see the underlying direction of the market without being distracted by every small tick up or down.
Signal Generation
Beyond just providing a smooth line, the script is programmed to identify specific entry or exit points through visual markers (arrows):
- Upward Signals: The logic monitors the difference between the current value of the moving average and its previous value. If the increase exceeds a specific sensitivity threshold (defined by the user), it marks an upward signal.
- Downward Signals: Similarly, if the moving average drops significantly beyond that same threshold, it identifies a downward signal.
Summary for the Trader
Essentially, this tool acts as a filter. It strips away the "jitter" of the market to show you the true path of price. By using an adaptive calculation, it attempts to stay glued to the trend during big moves while remaining steady during consolidation, ultimately providing visual cues (arrows) when the momentum becomes strong enough to be considered a significant move.
//+------------------------------------------------------------------+
//| AMA&AMAsig.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, by GOODMAN & Mstera è AF "
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Sienna
#property indicator_color2 Yellow
#property indicator_color3 Magenta
//---- input parameters
extern int periodAMA=52;
extern int nfast=5;
extern int nslow=20;
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