This specialized technical indicator is designed to analyze market momentum by measuring the relationship between two different speeds of price movement. It works by synthesizing several mathematical layers to help traders visualize "strength" and "directional shifts" in the current market trend.
How the Logic Works
1. The Foundation: Comparative Momentum The script starts by comparing two distinct oscillators (RSX). Think of these as two different ways of measuring the speed of a moving object—one is "fast" (reacting quickly to every tiny change) and one is "slow" (smoothing out the noise to show the bigger picture). By subtracting the slow measurement from the fast measurement, the script identifies the "gap" between immediate price action and the long-term trend.
2. The Smoothing Layer (Signal Line) To ensure that these movements aren't just random noise, the script takes that "gap" and applies a secondary smoothing calculation (an Exponential Moving Average). This creates a "Signal Line." By comparing the raw gap to this smooth signal line, the tool can determine whether the current momentum is accelerating or decelerating relative to its recent history.
3. Dynamic Trend Detection The core logic then looks at the difference between these two values: the Raw Gap and the Signal Line. It constantly monitors whether this difference is growing larger or smaller compared to the previous moment in time.
- If the difference is increasing, it identifies upward pressure.
- If the difference is decreasing, it identifies downward pressure.
4. Visual Representation Finally, the script translates these calculations into a clear visual histogram on your chart:
- Green Highlights: These appear when the momentum is moving in a positive direction. The script multiplies the value to make the visual change more prominent and easier for the human eye to track.
- Red Highlights: These appear when the momentum shifts into a negative direction, providing an immediate visual cue of a potential trend reversal or weakening.
In essence, this tool filters out market "jitter" to highlight clear, sustained moves in price, allowing you to see not just where the price is going, but how much force is behind the move.
//+------------------------------------------------------------------+
//| macd-2.mq4 |
//| Copyright ?2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 LimeGreen
#property indicator_color2 Red
#property indicator_color3 Black
#property indicator_color4 Black
//---- indicator parameters
extern int FastRSX=13;
extern int SlowRSX=17;
extern int SignalRSX=9;
//---- indicator buffers
double ind_buffer1[];
double ind_buffer2[];
double ind_buffer3[];
double ind_buffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
IndicatorBuffers(5);
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,1);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,1);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2 );
SetIndexDrawBegin(0,SignalRSX);
SetIndexDrawBegin(1,SignalRSX);
//---- 4 indicator buffers mapping
if(!SetIndexBuffer(0,ind_buffer1) &&
!SetIndexBuffer(1,ind_buffer2) &&
!SetIndexBuffer(2,ind_buffer3) &&
!SetIndexBuffer(3,ind_buffer4))
Print("cannot set indicators\' buffers!");
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("RSX_CD ("+FastRSX+","+SlowRSX+","+SignalRSX+")");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Oscillator |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
double prev,current;
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- RSX_CD counted in the 1-st additional buffer
for(int i=0; i<limit; i++)
ind_buffer3[i]=iCustom(Symbol(),Period(),"RSX",FastRSX,0,i)-iCustom(Symbol(),Period(),"RSX",SlowRSX,0,i);
//---- signal line counted in the 2-nd additional buffer
for(i=0; i<limit; i++)
ind_buffer4[i]=iMAOnArray(ind_buffer3,Bars,SignalRSX,0,MODE_EMA, i);
//---- dispatch values between 2 buffers
bool up=true;
for(i=limit-1; i>=0; i--)
{
current=ind_buffer3[i]-ind_buffer4[i];
prev=ind_buffer3[i+1]-ind_buffer4[i+1];
if(current>prev) up=true;
if(current<prev) up=false;
if(!up)
{
ind_buffer2[i]=3*current;
ind_buffer1[i]=0.0;
}
else
{
ind_buffer1[i]=3*current;
ind_buffer2[i]=0.0;
}
}
return(0);
}
Comments