Var Mov Avg_v1
Download scriptThis tool is designed to analyze market price movements by identifying underlying trends while attempting to filter out the "noise" often found in volatile trading environments. It functions as a sophisticated moving average that adjusts its sensitivity based on the current behavior of the market.
Core Logic and Functionality
The script operates through three primary mechanisms to provide a clearer picture of market direction:
1. Dynamic Trend Smoothing Unlike standard indicators that treat all price movements equally, this logic calculates a specific "noise" ratio. It looks at the magnitude of recent price changes compared to the total volatility over a set period. By doing this, the indicator can distinguish between significant structural moves in the market and minor, insignificant price fluctuations.
2. Adaptive Adjustment The script utilizes a dual-speed calculation (Fast and Slow coefficients). It compares the current speed of price action against a baseline. If the market is moving strongly, the indicator adjusts its smoothing factor to follow the trend more closely; if the market is stagnant or erratic, it maintains a steadier posture to avoid false signals.
3. Visual Trend Mapping The tool provides three distinct visual components on the chart:
- The Main Line: A smooth, continuous line that represents the calculated "Adjusted Moving Average." This serves as the primary visual guide for the current trend direction.
- Upward Signals: These appear as specific markers (arrows) when the indicator detects a positive shift in momentum that exceeds a pre-defined threshold. This helps identify potential buying opportunities or strengthening bullish trends.
- Downward Signals: Similarly, these markers appear when the indicator detects a negative shift in momentum exceeding the threshold, highlighting potential selling opportunities or weakening bearish trends.
How it assists the trader
By balancing speed and smoothness, this logic aims to provide a "cleaner" view of the market. It helps traders stay on the right side of a trend by highlighting clear directional shifts while ignoring the small, distracting price movements that often lead to premature entries or exits.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| 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