FAMA_v1
Download scriptThis script functions as a sophisticated technical analysis tool designed to track price movements on a trading chart. Its primary goal is to create a "smoothed" moving average that reacts intelligently to market trends while filtering out insignificant price fluctuations or "noise."
Core Logic and Behavior
The logic operates by calculating several layers of data to distinguish between meaningful price action and minor market vibrations:
1. Noise Identification The tool first evaluates the volatility of the market over a specific look-back period. It calculates the total "noise" by measuring the sum of price changes between candles. This allows the indicator to understand how much the market is actually moving versus just jittering in place.
2. Efficiency Ratio (ER) By comparing the total displacement of price against the cumulative noise identified above, the script determines an Efficiency Ratio. Essentially, this tells the tool whether the price is moving in a clear, directional manner or if it is moving erratically without making significant progress.
3. Adaptive Moving Average (AMA) Calculation The indicator uses these calculations to build a primary moving average. Unlike standard moving averages that treat all data points equally, this one adjusts its sensitivity based on the efficiency of the price movement. If the market is moving efficiently, the average reacts; if it is noisy, the average remains more stable.
4. The Smart Filter System The most advanced part of the logic is the final filtering layer. Before displaying the final line on your chart, the script checks two main conditions:
- Velocity Check: It looks at the speed and magnitude of the price change relative to the standard deviation of the moving average.
- Price Boundary Check: It examines recent highs and lows over a specific number of candles.
If the current price movement is too weak (below the defined filter threshold) or doesn't break out of recent boundaries, the script "holds" its previous position rather than following the new price point. This prevents the indicator line from jaggedly jumping around during sideways consolidation or low-volume periods.
Summary for the User
In simple terms, this tool acts as a "smart" trend line. It attempts to stay flat and stable when the market is indecisive and only begins to move decisively when it detects a confirmed shift in price momentum. This helps traders identify the true direction of a trend by smoothing out the distractions caused by minor market fluctuations.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| fAMA.mq4 |
//| Copyright © 2005, Profi_R |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Profi_R"
#property link "rvm_fam@fromru.com"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Black
//---- input parameters
extern int Range=10;
extern int FastMA=2;
extern int SlowMA=30;
extern int filter=50;
extern int n=4;
extern int h=10;
//---- buffers
double fAMA[];
double mAMA[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name; //????????? ?????????? short_name ???? "?????????"
//---- indicators
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,fAMA);
SetIndexBuffer(1,mAMA);
//---- name for DataWindow and indicator subwindow label
//?????????? short_name ??????????? ????????? ???????? ?????? ?????????
short_name="fAMA("+Range+","+FastMA+","+SlowMA+","+filter+","+n+","+h+")";
//??? ??????????? ?? ??????? ???????? ?????????? ??????? ????????????
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);//????????? ????? ??? ??????
//----
SetIndexDrawBegin(0,Range); //????????? ????????? ????? ?????????? ??? 0 ??????
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//---- TODO: add your code here
int cb,i;
double k1,k2,Noise,ER,SSC,AMA,sdAMA,dAMA;
if(Bars<=Range) return(0);
else
{
k1=2.0/(SlowMA+1);
k2=2.0/(FastMA+1)-k1;
AMA=Close[Bars-Range];
mAMA[Bars-Range]=Close[Bars-Range+1];
for(cb=Bars-counted_bars-Range-1;cb>=0;cb--)
{
Noise=0;
for(i=cb;i<=cb+Range-1;i++)
{
Noise=Noise+MathAbs(Close[i]-Close[i+1]);
}
if(Noise!=0)
{
ER=MathAbs(Close[cb]-Close[cb+Range])/Noise;
}
else
{
ER=0;
}
SSC=(ER*k2+k1);
AMA=AMA+NormalizeDouble(SSC*SSC*(Close[cb]-AMA),4);
mAMA[cb]=AMA;
if(filter<1)
{
fAMA[cb]=mAMA[cb];
}
else
{
for(i=cb;i<=cb+SlowMA-1;i++)
{
sdAMA=sdAMA+MathAbs(mAMA[i]-mAMA[i+1]);
}
dAMA=mAMA[cb]-mAMA[cb+1];
if(dAMA>=0)
{
if(dAMA<NormalizeDouble(filter*sdAMA/(100*SlowMA),4)&&
High[cb]<=High[Highest(NULL,0,MODE_HIGH,n,cb)]+h*Point)
{
fAMA[cb]=fAMA[cb+1];
}
else
{
fAMA[cb]=mAMA[cb];
}
}
else
{
if(MathAbs(dAMA)<NormalizeDouble(filter*sdAMA/(100*SlowMA),4)&&
Low[Lowest(NULL,0,MODE_LOW,n,cb)]-h*Point<Low[cb])
{
fAMA[cb]=fAMA[cb+1];
}
else
{
fAMA[cb]=mAMA[cb];
}
}
sdAMA=0.0;
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments