|
RSI |
|
RSI |
|
RSI |
|
RSI |
|
RSI |
|
RSI |
|
RSI |
|
RSI |
Relative Strength Index - RSI was developed by J. Welles Wilder and published in a 1978 book, New Concepts in Technical Trading Systems. This book also includes the
Parabolic SAR,
Average True Range - ATR and the Directional Movement Concept - concurrency
ADX. RSI has been featured in a number of articles, interviews and books over the years. Relative Strength Index - RSI is technical momentum indicator that compares the magnitude of recent gains to recent losses in an attempt to determine overbought and oversold conditions of an asset (measures the speed and change of price movements). RSI is an extremely popular momentum indicator, that oscillates between zero and 100. What makes it easy to track overbought (70) and excessive sales (30). The RSI is best used as a valuable complement to other indicators for example
METRO,
VininI Trend,
Heiken Ashi and similarly. The reason is that large surges and drops in the price of an asset will affect the Relative Strength Index - RSI by creating false buy or sell signals.
Forex traders also use 50 level of the RSI indicator, which separates buying forces from selling forces on the market, what help identify the general trend.
Mathematical Formula:
RSI = 100 - 100/(1 + RS)
RS = Average Gain / Average Loss
Relative Strength Index - RSI MQ4 Code Base (Copy Code)
#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 DodgerBlue
extern int RSIPeriod=14;
double RSIBuffer[];
double PosBuffer[];
double NegBuffer[];
int init()
{
string short_name;
IndicatorBuffers(3);
SetIndexBuffer(1,PosBuffer);
SetIndexBuffer(2,NegBuffer);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,RSIBuffer);
short_name="RSI("+RSIPeriod+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
SetIndexDrawBegin(0,RSIPeriod);
return(0);
}
int start()
{
int i,counted_bars=IndicatorCounted();
double rel,negative,positive;
if(Bars<=RSIPeriod) return(0);
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;
while(k>=i)
{
rel=Close[k]-Close[k+1];
if(rel>0) sump+=rel;
else sumn-=rel;
k--;
}
positive=sump/RSIPeriod;
negative=sumn/RSIPeriod;
}
else
{
rel=Close[i]-Close[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]=100.0-100.0/(1+positive/negative);
i--;
}
return(0);
}
Relative Strength Index - RSI MQ5 Code Base (Copy Code)
#property copyright "2009, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Relative Strength Index"
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_level1 30
#property indicator_level2 70
#property indicator_buffers 3
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 DodgerBlue
input int InpPeriodRSI=14;
double ExtRSIBuffer[];
double ExtPosBuffer[];
double ExtNegBuffer[];
int ExtPeriodRSI;
void OnInit()
{
if(InpPeriodRSI<1)
{
ExtPeriodRSI=12;
Print("Incorrect value for input variable InpPeriodRSI =",InpPeriodRSI,
"Indicator will use value =",ExtPeriodRSI,"for calculations.");
}
else ExtPeriodRSI=InpPeriodRSI;
SetIndexBuffer(0,ExtRSIBuffer,INDICATOR_DATA);
SetIndexBuffer(1,ExtPosBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,ExtNegBuffer,INDICATOR_CALCULATIONS);
IndicatorSetInteger(INDICATOR_DIGITS,2);
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodRSI);
IndicatorSetString(INDICATOR_SHORTNAME,"RSI("+string(ExtPeriodRSI)+")");
}
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[])
{
int i;
double diff;
if(rates_total<=ExtPeriodRSI)
return(0);
int pos=prev_calculated-1;
if(pos<=ExtPeriodRSI)
{
ExtRSIBuffer[0]=0.0;
ExtPosBuffer[0]=0.0;
ExtNegBuffer[0]=0.0;
double SumP=0.0;
double SumN=0.0;
for(i=1;i<=ExtPeriodRSI;i++)
{
ExtRSIBuffer[i]=0.0;
ExtPosBuffer[i]=0.0;
ExtNegBuffer[i]=0.0;
diff=price[i]-price[i-1];
SumP+=(diff>0?diff:0);
SumN+=(diff<0?-diff:0);
}
ExtPosBuffer[ExtPeriodRSI]=SumP/ExtPeriodRSI;
ExtNegBuffer[ExtPeriodRSI]=SumN/ExtPeriodRSI;
ExtRSIBuffer[ExtPeriodRSI]=100.0-(100.0/(1.0+ExtPosBuffer[ExtPeriodRSI]/ExtNegBuffer[ExtPeriodRSI]));
pos=ExtPeriodRSI+1;
}
for(i=pos;i<rates_total && !IsStopped();i++)
{
diff=price[i]-price[i-1];
ExtPosBuffer[i]=(ExtPosBuffer[i-1]*(ExtPeriodRSI-1)+(diff>0.0?diff:0.0))/ExtPeriodRSI;
ExtNegBuffer[i]=(ExtNegBuffer[i-1]*(ExtPeriodRSI-1)+(diff<0.0?-diff:0.0))/ExtPeriodRSI;
ExtRSIBuffer[i]=100.0-100.0/(1+ExtPosBuffer[i]/ExtNegBuffer[i]);
}
return(rates_total);
}