//------------------------------------------------------------------
//
//------------------------------------------------------------------
#property copyright
#property link
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 DeepSkyBlue
#property indicator_color2 DeepSkyBlue
#property indicator_color3 PaleVioletRed
#property indicator_color4 PaleVioletRed
#property indicator_color5 DimGray
#property indicator_color6 DimGray
#property indicator_width1 2
#property indicator_width3 2
#property indicator_width5 2
#property indicator_style6 STYLE_DOT
//
//
//
//
//
extern int RsrPrice = PRICE_CLOSE;
extern int RsrShortPeriod = 20;
extern int RsrLongPeriod = 140;
extern int RsrMaMode = MODE_SMA;
extern int AtrPeriod = 10;
extern bool ShowHistogram = true;
//
//
//
//
//
double rsr[];
double rsrHuu[];
double rsrHud[];
double rsrHdu[];
double rsrHdd[];
double zli[];
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
int init()
{
if (ShowHistogram)
int drawStyle = DRAW_HISTOGRAM;
else drawStyle = DRAW_NONE;
//
//
//
//
//
SetIndexBuffer(0,rsrHuu); SetIndexStyle(0,drawStyle);
SetIndexBuffer(1,rsrHud); SetIndexStyle(1,drawStyle);
SetIndexBuffer(2,rsrHdd); SetIndexStyle(2,drawStyle);
SetIndexBuffer(3,rsrHdu); SetIndexStyle(3,drawStyle);
SetIndexBuffer(4,rsr);
SetIndexBuffer(5,zli);
IndicatorShortName("Relative Strength Rank ("+RsrShortPeriod+","+RsrLongPeriod+","+AtrPeriod+")");
return(0);
}
int deinit() { return(0); }
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
double work[][2];
#define _trend 0
#define _slope 1
int start()
{
int i,r,limit,counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit = MathMin(Bars-counted_bars,Bars-2);
if (ArrayRange(work,0)!=Bars) ArrayResize(work,Bars);
//
//
//
//
//
for(i=limit, r=Bars-i-1; i>=0; i--,r++)
{
double price = iMA(NULL,0,1 ,0,MODE_SMA ,RsrPrice,i);
double mas = iMA(NULL,0,RsrShortPeriod,0,RsrMaMode,RsrPrice,i);
double mal = iMA(NULL,0,RsrLongPeriod ,0,RsrMaMode,RsrPrice,i);
double atr = iATR(NULL,0,AtrPeriod,i);
if (atr!=0)
rsr[i] = (price-mas+price-mal)/(2.0*atr);
else rsr[i] = 0;
//
//
//
//
//
zli[i] = 0;
rsrHuu[i] = EMPTY_VALUE;
rsrHud[i] = EMPTY_VALUE;
rsrHdu[i] = EMPTY_VALUE;
rsrHdd[i] = EMPTY_VALUE;
work[r][_slope] = work[r-1][_slope];
if (rsr[i]>rsr[i+1]) work[r][_slope] = 1;
if (rsr[i]<rsr[i+1]) work[r][_slope] = -1;
if (rsr[i]>0)
if (work[r][_slope]==1)
rsrHuu[i] = rsr[i];
else rsrHud[i] = rsr[i];
if (rsr[i]<0)
if (work[r][_slope]==-1)
rsrHdd[i] = rsr[i];
else rsrHdu[i] = rsr[i];
}
return(0);
}