i-AMA-Optimum_v1
Download scriptThis technical script is designed as a specialized trading tool that helps visualize market trends by filtering out minor price fluctuations (market "noise"). It produces a smoothed moving average line and identifies specific signal points to assist traders in recognizing the direction of price momentum.
Core Logic and Functionality
The primary objective of this script is to distinguish between significant price movements and insignificant volatility. It achieves this through a sophisticated mathematical approach:
1. Noise Analysis The script constantly scans historical price data to calculate the "noise" level. It does this by comparing current price changes against previous changes over a specific period (defined by the user). By measuring these differences, the tool can determine how much of the market movement is just random jitter versus actual trend progression.
2. Signal Identification To find meaningful trends, the logic looks at the distance between the current price and the price at a specific interval in the past. This allows the script to recognize whether the price is making a substantial move or merely drifting sideways.
3. The "Optimum" Smoothing Mechanism Rather than using a standard moving average—which can often be too slow to react or too fast to be smooth—this script employs an adaptive calculation:
- Dynamic Weighting: It combines two different speed settings (Fast and Slow).
- Adaptive Response: The tool automatically adjusts its sensitivity based on the "Signal" to "Noise" ratio. When the market is moving clearly in one direction, the indicator reacts more quickly; when the market is choppy or sideways, it remains smoother to avoid giving false signals.
4. Visual Output The script renders two primary visual elements on your trading chart:
- The Trend Line: A smooth orange line that represents the "Optimum" moving average, helping you stay aligned with the broader market direction.
- Signal Markers: Specific visual indicators (arrows) that mark critical points where the calculation has finalized a trend shift.
Summary for the User
In simple terms, this tool acts like a smart filter. It ignores the "static" of the market to show you the underlying path of the price. By balancing speed and smoothness based on real-time volatility, it aims to provide a clearer picture of where the market is heading, making it easier to identify when a trend is strengthening or weakening.
//+------------------------------------------------------------------+
//| i-AMA-Optimum.mq4 |
//| Copyright © 2005-2007 RickD |
//+------------------------------------------------------------------+
#property copyright "© 2005-2007 RickD"
#property link "www.e2e-fx.net"
//----
#define major 1
#define minor 0
//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Orange
#property indicator_color2 Black
#property indicator_width1 2
//---- indicator parameters
extern int P = 1000;
extern double Fast = 2;
extern double Slow = 10;
//---- indicator buffers
double buf1[];
double buf2[];
//----
double SlowSC, FastSC;
double AMA;
double Noise, Signal;
double ER, SSC;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
//---- âû÷èñëÿåì ñãëàæèâàþùèå êîíñòàíòû
SlowSC = 2 / (1 + Slow);
FastSC = 2 / (1 + Fast);
//----
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 1);
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1, 158);
// IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS) + 1);
SetIndexBuffer(0, buf1);
SetIndexBuffer(1, buf2);
//----
SetIndexEmptyValue(0, 0.0);
SetIndexEmptyValue(1, 0.0);
//----
IndicatorShortName("AMA("+ P + ", " + Fast + ", " + Slow + ")");
return (0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
if(Bars < P)
return (0);
int counted = IndicatorCounted();
// if(Symbol() == "EURUSD")
// Print("C= ", counted, " B= ", Bars);
if(counted < 0)
return (-1);
if(counted == Bars-1)
return (0);
int limit = 0;
if(counted == 0 || counted > Bars-2)
{
Noise = 0;
limit = Bars - 2;
}
//----
for(int i = limit; i >= 0; i--)
{
if(limit > 0 && i > limit - P)
{
Noise += MathAbs(Open[i] - Open[i+1]);
buf1[i] = 0;
buf2[i] = 0;
continue;
}
Signal = MathAbs(Open[i] - Open[i+P]);
Noise += MathAbs(Open[i] - Open[i+1]);
Noise -= MathAbs(Open[i+P] - Open[i+1+P]);
//----
ER = 1;
if(Noise > 0)
ER = Signal / Noise;
SSC = MathPow(SlowSC + ER*(FastSC - SlowSC), 2);
//----
if(i == limit - P)
AMA = Open[i];
else
AMA = SSC*Open[i] + (1 - SSC)*buf1[i+1];
buf1[i] = AMA;
buf2[i] = AMA;
}
return (0);
}
//+------------------------------------------------------------------+
Comments