AggM
Download scriptThe AggM tool is a specialized technical analysis indicator designed to help traders gauge market momentum and identify potential overbought or oversold conditions by analyzing price relative to historical extremes. Instead of simply looking at where the price is currently moving, this tool evaluates where the current price sits within a specific "window" of recent history.
How the Logic Works
1. Relative Positioning (Percent Rank) The core engine of this script relies on a calculation called a "Percent Rank." For every new price tick, the tool looks back at two different timeframes (defined by the fast and slow periods). It gathers all the high, low, and closing prices within those windows and sorts them into a ranked list.
By doing this, the tool determines exactly where the current price sits as a percentage of that historical data. For example, if a price is at the very top of its recent range, it receives a high rank; if it is at the bottom, it receives a low rank.
2. Dual-Timeframe Analysis To provide a more balanced view of the market, the script performs this calculation twice using two different speeds:
- Fast Period: Captures immediate, short-term price behavior.
- Slow Period: Captures broader, long-term trends.
The script then combines these two perspectives. It calculates a "long" rank (based on the slow period) and a "short" rank (derived from the fast period). By averaging these two values together, the indicator creates a balanced "Momentum Value." This prevents the tool from being overly reactive to minor price flickers while still remaining sensitive enough to catch significant trend shifts.
3. Smoothing for Clarity Raw momentum data can often be "noisy" or jagged, making it difficult for a human trader to read clearly. To solve this, the script applies a weighted smoothing formula to the final result.
It calculates the current value by taking 60% of the current momentum and 40% of the previous value. This specific weighting creates a smoother, more fluid line on your chart, helping to filter out market "static" so you can more easily identify underlying price trends.
Visual Interpretation
The indicator appears in a separate window below your main chart, ranging from 0 to 1.
- High Values: Suggest that the price is currently trading near the top of its historical range relative to the chosen periods.
- Low Values: Suggest that the price is trading near the bottom of its historical range.
- Levels: The tool includes pre-set horizontal levels (0.2 and 0.7) to help traders quickly identify zones where the market might be reaching extremes.
//+------------------------------------------------------------------+
//| AggM.mq4 |
//| Copyright ?2010, Walter Choy |
//| brother3th@yahoo.com |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2010, Walter Choy"
#property link "brother3th@yahoo.com"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_minimum 0
#property indicator_maximum 1
#property indicator_level1 0.2
#property indicator_level2 0.7
//---- input parameters
extern int fast_m_period=10;
extern int slow_m_period=252;
//---- buffers
double AggMBuffer[];
double MvalueBuffer[];
double tmpArray[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,AggMBuffer);
SetIndexLabel(0, "AggM");
SetIndexEmptyValue(0, 0.0);
SetIndexDrawBegin(0, slow_m_period);
SetIndexBuffer(1, MvalueBuffer);
IndicatorShortName("AggM (" + fast_m_period + "," + slow_m_period + ")");
ArrayResize(tmpArray, slow_m_period * 3);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int i, j;
//----
i = Bars - counted_bars - 1;
j = i;
while(i>=0){
double rank_long = PercentRank(slow_m_period, i);
double rank_short = 1 - PercentRank(fast_m_period, i);
MvalueBuffer[i] = (rank_long + rank_short)/2;
i--;
}
while(j>=0){
AggMBuffer[j] = (MvalueBuffer[j+1]*0.4) + (MvalueBuffer[j]*0.6);
j--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| PercentRank function |
//+------------------------------------------------------------------+
double PercentRank(int r_period, int shift){
double pcrank, rank;
int i;
ArrayCopy(tmpArray, High, 0, shift, r_period);
ArrayCopy(tmpArray, Low, r_period, shift, r_period);
ArrayCopy(tmpArray, Close, r_period * 2, shift, r_period);
ArraySort(tmpArray, r_period * 3);
rank = ArrayBsearch(tmpArray, Close[shift], r_period * 3);
pcrank = rank /(r_period * 3 - 1);
return (pcrank);
}
//+------------------------------------------------------------------+
Comments