fama2
Download scriptThis tool is designed to provide a smoother, more refined visual trend line for trading charts. While standard moving averages can often react too quickly to minor price fluctuations—creating a "jagged" look—this script employs a multi-layered smoothing logic to help traders identify the underlying direction of the market with less visual noise.
Core Smoothing Mechanism
The primary logic begins by calculating a base Moving Average. It uses a specific mathematical approach where it looks at the relationship between "Fast" and "Slow" price speeds. By comparing these two speeds, the script determines how much weight to give to recent price changes versus historical data. This ensures that the resulting line is not just an average of past prices, but a weighted representation of the current momentum.
Noise Reduction
To improve accuracy, the script includes a "Noise" detection system. It analyzes a specific range of candles to determine how much the price is fluctuating erratically. By calculating this noise level, the tool can differentiate between a meaningful trend move and insignificant market "jitter." This prevents the indicator from reacting to tiny, insignificant price movements that don't actually change the overall trend.
The Filtering Layer
The most unique feature of this script is its advanced filtering logic. Even after the initial smoothing is applied, the tool performs a second check before it decides to move the line on your chart:
- Trend Stability: It monitors the "Standard Deviation" (the typical volatility) of the smoothed average. If a price change is too small compared to the current volatility, the script considers it "insignificant" and holds the line steady.
- Price Extremes: The logic checks the highest and lowest prices over a short period. If the price is moving in the correct direction but hasn't broken out of a specific "buffer zone" (determined by user settings), the indicator will wait.
Summary for the Trader
In plain terms, this script acts like a sophisticated stabilizer. It calculates a trend line, identifies if the current market movement is just random noise or a real move, and then applies a "gatekeeper" logic to ensure the line only shifts when there is enough convincing price action to support that move. The result is a cleaner, more reliable visual guide that helps filter out market distractions.
//+------------------------------------------------------------------+
//| 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 Red
//---- input parameters
extern int Range=10;
extern int MaxBars = 1000;
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[MaxBars-Range];
mAMA[MaxBars-Range]=Close[MaxBars-Range+1];
for(cb=MaxBars-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