This tool is designed to help traders gauge the strength and direction of a market trend by measuring how recently price "extremes" (the highest highs and lowest lows) occurred within a specific timeframe. Rather than looking at just the current price, it analyzes a rolling window of recent historical data to determine if the market is currently experiencing active momentum or if it is drifting sideways.
Core Logic and Functionality
The script operates by scanning a defined period of time—which can be adjusted by the user—to identify two key pieces of information:
- Upward Momentum Tracking: The tool looks for the highest closing price within the chosen timeframe. It then calculates how close that peak is to the current moment. If the highest price occurred very recently, the indicator produces a high value, signaling strong bullish momentum.
- Downward Momentum Tracking: Similarly, the tool identifies the lowest closing price within that same timeframe. It measures the distance of this "floor" from the current price; if the lowest price happened just moments ago, it signals strong bearish momentum.
Visual Representation and Interpretation
The script generates two distinct lines on a dedicated sub-window (ranging from 0 to 100). These lines act as a visual thermometer for market behavior:
- High Values (Approaching 100): When a line climbs toward the top of the scale, it indicates that the market is reaching new highs or lows very quickly. This suggests a strong, active trend in that specific direction.
- Low Values (Approaching 0): When a line stays near the bottom, it indicates that the price extremes happened a long time ago relative to the current window. This suggests that momentum is weakening or that the market is consolidating without making significant new progress.
Practical Application for Traders
By observing these two lines simultaneously, users can differentiate between a "trending" market and a "ranging" market. For example:
- If both lines are at low values, it often suggests the market is moving sideways in a non-directional range.
- If one line is significantly higher than the other, it highlights which direction the current momentum is favoring.
In essence, this tool filters out "noise" by focusing on the recency of price action, providing a clearer picture of whether the market is currently "pushing" in a specific direction or simply wandering aimlessly.
//+------------------------------------------------------------------+
//| Momentum.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Yellow
#property indicator_color2 DodgerBlue
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_level1 30
#property indicator_level2 70
//---- input parameters
extern int MomPeriod=14;
//---- buffers
double MomBuffer1[],MomBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,MomBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,MomBuffer2);
//---- name for DataWindow and indicator subwindow label
short_name="Aroon("+MomPeriod+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
//----
SetIndexDrawBegin(0,MomPeriod);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Momentum |
//+------------------------------------------------------------------+
int start()
{
int i,counted_bars=IndicatorCounted();
//----
if(Bars<=MomPeriod) return(0); //bar kurang dari 14 keluar..
//---- initial zero
if(counted_bars<1) //..jika bar yang sudah terhitung lebih kecil dari 1 maka nol kan semua
//mulai dari no buffer yang paling besar ke yang paling kecil=0
for(i=1;i<=MomPeriod;i++) {
MomBuffer1[Bars-i]=0.0;
MomBuffer2[Bars-i]=0.0;
}
//----
i=Bars-MomPeriod-1;
if(counted_bars>=MomPeriod) i=Bars-counted_bars-1;//15-14-1=0
int nHigh,nLow;
while(i>=0)
{
double Max=-100000;
double Min=100000;
for(int k=i;k<i+MomPeriod;k++){
double Num=Close[k];
if(Num>Max){
Max=Num;
nHigh=k;
}
if(Num<Min){
Min=Num;
nLow=k;
}
}
//Aroon Indicator math..
MomBuffer1[i]=100.0*(MomPeriod-(nHigh-i))/MomPeriod;
MomBuffer2[i]=100.0*(MomPeriod-(nLow-i))/MomPeriod;
i--;
}
return(0);
}
//+------------------------------------------------------------------+
Comments