MACD^RSI
Download scriptThis technical tool is designed to provide traders with a combined visual analysis of market momentum and price trends by merging two well-known financial indicators: the MACD (Moving Average Convergence Divergence) and the RSI (Relative Strength Index). Instead of applying the RSI to the standard price of an asset, this script applies it specifically to the MACD values, creating a unique "momentum of momentum" perspective.
Core Functional Logic
The tool operates through three distinct layers of calculation:
1. The Primary Trend Analysis (MACD) The script begins by tracking two different types of moving averages—a fast-moving one and a slower-moving one. By calculating the distance between these two averages, it identifies the "gap" in price momentum.
- When this gap widens, it suggests a strengthening trend.
- When the gap narrows, it suggests a weakening trend.
2. The Signal Smoothing To help filter out "noise" and minor price fluctuations, the script takes the raw MACD data and runs it through a smoothing calculation (a Simple Moving Average). This produces a secondary line that helps traders identify the overall direction of the momentum without being distracted by every tiny price tick.
3. The Specialized Momentum Overlay (MACD-RSI) The most unique feature of this script is how it calculates the RSI component. While a standard RSI tells you if an asset is "overbought" or "oversold" based on price, this script calculates those values based on the MACD's behavior.
- It tracks the positive and negative gains of the MACD values over a specific timeframe.
- It then translates these gains into a specialized scale (adjusted by a "caliber" setting) to show how aggressively the momentum is shifting.
Summary for the User
Essentially, this tool allows you to see not just where the price is going, but how much "fuel" or strength is behind the current move. By combining the MACD’s trend tracking with the RSI’s strength measurement on a single display, it provides a deeper look at whether a market move has significant power behind it or if it is beginning to lose steam.
//+------------------------------------------------------------------+
//| MACD - RSI.mq4 |
//| Copyright © 2009, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//| made in Russia by lukas1 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link "lukas1@ngs.ru"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Silver
#property indicator_color2 Red
#property indicator_color3 DodgerBlue
#property indicator_width1 2
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//---- input parameters
extern int RSIPeriod=14;
extern double caliber=4.0; //need for RSI caliber
//---- buffers
double RSIBuffer[];
double PosBuffer[];
double NegBuffer[];
//---- indicator buffers
double MacdBuffer[];
double SignalBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(5);
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
SetIndexDrawBegin(1,SignalSMA);
IndicatorDigits(Digits+1);
//---- indicator buffers mapping
SetIndexBuffer(0,MacdBuffer);
SetIndexBuffer(1,SignalBuffer);
SetIndexBuffer(2,RSIBuffer);
SetIndexBuffer(3,PosBuffer);
SetIndexBuffer(4,NegBuffer);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD-RSI("+FastEMA+","+SlowEMA+","+SignalSMA+"),("+RSIPeriod+")");
SetIndexLabel(0,"MACD");
SetIndexLabel(1,"Signal");
SetIndexLabel(2,"RSI");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
double rel,negative,positive;
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
for(int i=0; i<limit; i++)
MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
for(i=0; i<limit; i++)
SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
//=============================================================== RSI =
i=Bars-RSIPeriod-1;
if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
double sumn=0.0,sump=0.0;
if(i==Bars-RSIPeriod-1)
{
int k=Bars-2;
//---- initial accumulation
while(k>=i)
{
rel=MacdBuffer[k]-MacdBuffer[k+1];
if(rel>0) sump+=rel;
else sumn-=rel;
k--;
}
positive=sump/RSIPeriod;
negative=sumn/RSIPeriod;
}
else
{
//---- smoothed moving average
rel=MacdBuffer[i]-MacdBuffer[i+1];
if(rel>0) sump=rel;
else sumn=-rel;
positive=(PosBuffer[i+1]*(RSIPeriod-1)+sump)/RSIPeriod;
negative=(NegBuffer[i+1]*(RSIPeriod-1)+sumn)/RSIPeriod;
}
PosBuffer[i]=positive;
NegBuffer[i]=negative;
if(negative==0.0) RSIBuffer[i]=0.0;
else RSIBuffer[i]=caliber*Point*(50.0-100.0/(1+positive/negative) );
i--;
}
return(0);
}
//+------------------------------------------------------------------+
Comments