This script is a sophisticated technical analysis tool designed to measure the momentum and velocity of price movements in financial markets. While it is built on the foundation of the Relative Strength Index (RSI), it is highly versatile, allowing users to switch between different underlying data sources to determine how "overbought" or "oversold" an asset might be.
Core Functionality
The primary goal of this tool is to provide a visual representation of price strength. It calculates a percentage scale (ranging from 0 to 100) that helps traders identify whether the current market trend is accelerating upwards, slowing down, or experiencing a reversal.
Key Features and Logic Modes
The script features a "Type" setting that fundamentally changes what data the tool analyzes. Depending on your selection, the logic operates in one of three ways:
- Standard RSI Mode: The tool looks directly at the change in closing prices between consecutive bars. It measures how much price has moved up versus how much it has moved down over a specific period to calculate the strength index.
- Shaff-RSI Mode: Instead of using raw price changes, this mode applies an extra layer of filtering by utilizing Moving Average Convergence Divergence (MACD) logic. It analyzes the difference between two moving averages (fast and slow) to smooth out "noise" in the market, focusing on the trend of the momentum rather than just the price.
- FATL-RSI Mode: This is a more complex calculation that uses a specific weighted formula (a mathematical signature) applied to 38 different price points. This helps identify deeper, more nuanced trends by giving different levels of importance to older and newer price data respectively.
Technical Smoothing
Regardless of which mode is selected, the script employs a "smoothed moving average" logic. Instead of reacting erratically to every small tick in price, it uses an internal calculation that blends current values with previous data points. This results in a smoother visual line on your chart, making it easier to identify significant trend shifts without being distracted by minor market fluctuations.
Summary for the User
In practical terms, this tool transforms raw market data into a readable momentum oscillator. By choosing different "Types," you can switch from watching raw price speed to watching smoothed trend momentum or advanced weighted calculations, providing a flexible suite of options for identifying potential entry and exit points in your trading strategy.
//+------------------------------------------------------------------+
//| RSI.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_minimum 0
#property indicator_maximum 100
#property indicator_buffers 1
#property indicator_color1 Blue
//---- input parameters
extern int RSIPeriod=21;
extern int FastMA=23;
extern int SlowMA=50;
extern int Signal=5;
extern int Type=1;
//---- buffers
double RSIBuffer[];
double PosBuffer[];
double NegBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- 2 additional buffers are used for counting.
IndicatorBuffers(3);
SetIndexBuffer(1,PosBuffer);
SetIndexBuffer(2,NegBuffer);
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,RSIBuffer);
//---- name for DataWindow and indicator subwindow label
switch (Type)
{
case 2:
short_name="FATL-RSI(" + RSIPeriod + ")";
break;
case 1:
short_name="Shaff-RSI(" + RSIPeriod + "," + FastMA + "," + SlowMA + ")";
break;
default:
short_name="RSI(" + RSIPeriod + ")";
break;
}
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
//----
SetIndexDrawBegin(0,RSIPeriod);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Relative Strength Index |
//+------------------------------------------------------------------+
int start()
{
int i,counted_bars=IndicatorCounted();
double rel,negative,positive;
//----
if(Bars<=RSIPeriod) return(0);
//---- initial zero
if(counted_bars<1)
for(i=1;i<=RSIPeriod;i++) RSIBuffer[Bars-i]=0.0;
//----
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=GetValue(i);
if(rel>0) sump+=rel;
else sumn-=rel;
k--;
}
positive=sump/RSIPeriod;
negative=sumn/RSIPeriod;
}
else
{
//---- smoothed moving average
rel=GetValue(i);
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]=100.0-100.0/(1+positive/negative);
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
double GetValue(int shift)
{
double Value = 0;
if (Type == 2) Value = GetFATL(shift) - GetFATL(shift+1);
else
{
if (Type == 1) Value = iMACD(NULL,0,FastMA,SlowMA,Signal,PRICE_CLOSE,MODE_MAIN,shift) - iMACD(NULL,0,FastMA,SlowMA,Signal,PRICE_CLOSE,MODE_MAIN,shift+1);
else Value = Close[shift] - Close[shift + 1];
}
return(Value);
}
//+------------------------------------------------------------------+
double GetFATL(int i)
{
double FATL;
if (Bars < 40) return(0);
FATL = 0.4360409450*Close[i+0]
+0.3658689069*Close[i+1]
+0.2460452079*Close[i+2]
+0.1104506886*Close[i+3]
-0.0054034585*Close[i+4]
-0.0760367731*Close[i+5]
-0.0933058722*Close[i+6]
-0.0670110374*Close[i+7]
-0.0190795053*Close[i+8]
+0.0259609206*Close[i+9]
+0.0502044896*Close[i+10]
+0.0477818607*Close[i+11]
+0.0249252327*Close[i+12]
-0.0047706151*Close[i+13]
-0.0272432537*Close[i+14]
-0.0338917071*Close[i+15]
-0.0244141482*Close[i+16]
-0.0055774838*Close[i+17]
+0.0128149838*Close[i+18]
+0.0226522218*Close[i+19]
+0.0208778257*Close[i+20]
+0.0100299086*Close[i+21]
-0.0036771622*Close[i+22]
-0.0136744850*Close[i+23]
-0.0160483392*Close[i+24]
-0.0108597376*Close[i+25]
-0.0016060704*Close[i+26]
+0.0069480557*Close[i+27]
+0.0110573605*Close[i+28]
+0.0095711419*Close[i+29]
+0.0040444064*Close[i+30]
-0.0023824623*Close[i+31]
-0.0067093714*Close[i+32]
-0.0072003400*Close[i+33]
-0.0047717710*Close[i+34]
+0.0005541115*Close[i+35]
+0.0007860160*Close[i+36]
+0.0130129076*Close[i+37]
+0.0040364019*Close[i+38];
return(FATL);
}
Comments