This tool is designed as a visual momentum indicator for trading platforms, specifically built to help traders identify significant shifts in price direction by monitoring "breakouts" from established price levels.
Core Logic and Functionality
The script operates by scanning historical price data to establish a dynamic range—essentially a "box"—around the current market price. It tracks how the price moves relative to this box to determine whether the market is experiencing an upward trend, a downward trend, or remains within a consolidated range.
How it identifies movements: The indicator uses a specific threshold (defined by the "BoxSize" parameter) to filter out minor market noise.
- Upward Momentum: If the price closes significantly above the established upper limit of the current box, the script registers a positive movement. It resets the boundaries to account for this new high and increments a counter that tracks the consecutive strength of the upward move.
- Downward Momentum: Conversely, if the price closes significantly below the established lower limit, it registers a negative movement. It then adjusts the boundaries downward and increments a counter tracking the strength of the downward trend.
Visual Representation
The script translates these calculations into two distinct visual components displayed in a separate window at the bottom of your chart:
- Upward Strength: Represented as green bars, these indicate the momentum of consecutive upward price breaks.
- Downward Strength: Represented as red bars, these indicate the momentum of consecutive downward price breaks.
Practical Use for Traders
By observing these histograms, a trader can visually distinguish between a "choppy" market (where neither color shows significant growth) and a trending market. When one color begins to grow steadily while the other remains flat, it signals that the price is breaking out of previous zones and establishing a consistent directional trend. The tool effectively simplifies complex price action into a clear visual map of "strength" versus "weakness."
//+------------------------------------------------------------------+
//| Amir.mq4 |
//| Copyright © 2005, Amir |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Amir"
#property link ""
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
//---- input parameters
extern int BoxSize=15;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
int Cur=0;
int KirUp=0;
int KirDn=0;
int kr=0;
int no=0;
double valueh=0;
double valuel=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexLabel(0,"XOUP");
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexLabel(1,"XODOWN");
IndicatorShortName("I-XO-A-H");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int CurrentBar;
double Hi,Lo,Curb;
int counted_bars=IndicatorCounted();
//---- TODO: add your code here
//----Calculation---------------------------
for(int i=0;i<=Bars;i++)
{
CurrentBar = Bars-i;
if (Cur<1)
{
Hi=Close[CurrentBar];
Lo=Close[CurrentBar];
Cur=1;
}
Curb=Close[CurrentBar];
if (Curb>(Hi+BoxSize*Point))
{
Cur+=1;
Hi=Curb;
Lo=Curb-BoxSize*Point;
KirUp=1;
KirDn=0;
kr+=1;
no=0;
}
if (Curb<(Lo-BoxSize*Point))
{
Cur+=1;
Lo=Curb;
Hi=Curb+BoxSize*Point;
KirUp=0;
KirDn=1;
no+=1;
kr=0;
}
valueh=kr;
valuel=0-no;
ExtMapBuffer1[CurrentBar]=valueh;
ExtMapBuffer2[CurrentBar]=valuel;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments