AMA Trend Line wo Range
Download scriptThis technical indicator is designed to provide a sophisticated "Filtered Augmented Moving Average" (fAMA) for financial charts. Unlike standard moving averages that simply follow price fluctuations with a consistent lag, this script utilizes advanced mathematical logic to smooth out market "noise" while remaining responsive to genuine trend changes.
Core Logic and Mechanics
1. Noise Measurement and Volatility Assessment The script begins by calculating the "Noise" level of the market over a specific user-defined range. It does this by measuring the cumulative movement between consecutive closing prices. By establishing this baseline, the tool can distinguish between insignificant price jitters (noise) and significant directional movements.
2. The Augmented Moving Average (AMA) Foundation The core engine relies on an Augmented Moving Average calculation. It uses specific weighting factors (k1 and k2) to determine how much importance to give to recent price changes versus historical data. This allows the average to "speed up" when a clear trend emerges and "slow down" when the market is sideways, reducing the typical lag found in traditional indicators.
3. Intelligent Trend Filtering The most unique feature of this script is its filtering layer. Instead of simply plotting the moving average directly onto the chart, the script subjects the data to two specific tests before deciding what to display:
- Velocity Check: It calculates the speed of the current movement relative to recent volatility. If the price is moving too slowly (falling below a specific filter threshold), the script assumes the current movement lacks momentum.
- Price Structure Verification: The logic cross-references the current price against recent "Highs" and "Lows" within a specific window. It looks for structural confirmation—essentially checking if the price is actually breaking out of a local range or merely drifting aimlessly.
Summary of Behavior
In practical terms, the indicator acts as an intelligent tracker:
- During strong trends: The line follows the price closely because the movement exceeds the "noise" and "filter" thresholds.
- During consolidation or choppy markets: The line remains relatively flat or stable. It effectively ignores minor fluctuations that don't meet the script's internal requirements for a significant trend, helping traders avoid "whipsaws" (false signals) caused by insignificant price movements.
//+------------------------------------------------------------------+
//| 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 Crimson
//---- 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[];
double AMA[];
double k1,k2;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name; //îáÿâëåíèå ïåðåìåííîé short_name òèïà "ñòðîêîâûé"
//---- indicators
IndicatorBuffers(3);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(0,fAMA);
SetIndexBuffer(1,mAMA);
SetIndexBuffer(2,AMA);
//---- name for DataWindow and indicator subwindow label
//ïåðåìåííîé short_name ïðèñâàèâàåì ñòðîêîâîå çíà÷åíèå ðàâíîå âûðàæåíèþ
short_name="AMA("+Range+","+FastMA+","+SlowMA+","+filter+","+n+","+h+")";
//äëÿ îòîáðàæåíèÿ íà ãðàôèêå ïðèñâîèì èíäèêàòîðó êðàòêîå íàèìåíîâàíèå
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);//Óñòàíîâèì ìåòêó äëÿ áóôåðà
//----
SetIndexDrawBegin(0,Range); //óñòàíîâêà íà÷àëüíîé òî÷êè ïðîðèñîâêè äëÿ 0 áóôåðà
k1=2.0/(SlowMA+1);
k2=2.0/(FastMA+1)-k1;
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//---- TODO: add your code here
int cb,i,limit;
double Noise,ER,SSC,sdAMA,dAMA;
if (counted_bars==0) limit=Bars-Range;
if (counted_bars>0) limit=Bars-counted_bars;
limit--;
if(Bars<=Range) return(0);
else
{
AMA[Bars-Range]=Close[Bars-Range];
mAMA[Bars-Range]=Close[Bars-Range+1];
//for(cb=Bars-counted_bars-Range-1;cb>=0;cb--)
for(cb=limit;cb>=0;cb--)
{
Noise=0;
for(i=cb;i<=cb+Range-1;i++)
{
Noise=Noise+MathAbs(Close[i]-Close[i+1]);
}
if(Noise!=0.0) ER=MathAbs(Close[cb]-Close[cb+Range])/Noise; else ER=0;
SSC=(ER*k2+k1);
AMA[cb]=AMA[cb+1]+NormalizeDouble(SSC*SSC*(Close[cb]-AMA[cb+1]),Digits);
mAMA[cb]=AMA[cb];
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;
}
}
}//for(cb=Bars-counted_bars;cb>=0;cb--)
//ObjectsRedraw();
//----
return(0);
}
//+------------------------------------------------------------------+
Comments