#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 LightBlue
#property indicator_width2 2
#property indicator_color3 Tomato
#property indicator_width3 2
//---- input parameters
extern int RSILength = 14; // Period of evaluation
extern int Smooth = 5; // Period of smoothing
extern double K = 4.236; // Multiplier
//---- buffers
double SmRSI[];
double UpTrend[];
double DnTrend[];
double Delta [];
double ATRRSI[];
double smin[];
double smax[];
double trend[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(
;
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(0,SmRSI);
SetIndexBuffer(1,UpTrend);
SetIndexBuffer(2,DnTrend);
SetIndexBuffer(3,Delta);
SetIndexBuffer(4,ATRRSI);
SetIndexBuffer(5,smin);
SetIndexBuffer(6,smax);
SetIndexBuffer(7,trend);
//---- name for DataWindow and indicator subwindow label
string short_name="TrendStrength("+RSILength+","+Smooth+")";
IndicatorShortName(short_name);
SetIndexLabel(0,"Smoothed RSI");
SetIndexLabel(1,"UpTrend");
SetIndexLabel(2,"DnTrend");
//----
SetIndexDrawBegin(0,3*RSILength+Smooth);
SetIndexDrawBegin(1,3*RSILength+Smooth);
SetIndexDrawBegin(2,3*RSILength+Smooth);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int shift, limit,counted_bars=IndicatorCounted();
//----
if (Bars-1<3*RSILength+Smooth+1)return(0);
if (counted_bars<0)return(-1);
if (counted_bars>0) counted_bars--;
limit=Bars-counted_bars-1;
for( shift=limit; shift>=0; shift--)
{
double RSI = iRSI(NULL,0,RSILength,PRICE_CLOSE,shift);
SmRSI[shift]= SmRSI[shift+1] + 2./(Smooth+1)*(RSI - SmRSI[shift+1]); //iMAOnArray(RSI,0,Smooth,0,1,shift);
if(SmRSI[shift] > SmRSI[shift+1]) {double hRSI = SmRSI[shift]; double lRSI = SmRSI[shift+1];}
else
if(SmRSI[shift] < SmRSI[shift+1]) {hRSI = SmRSI[shift+1]; lRSI = SmRSI[shift];}
else
{hRSI = SmRSI[shift]; lRSI = SmRSI[shift];}
ATRRSI[shift] = hRSI - lRSI;
}
for( shift=limit; shift>=0; shift--)
Delta[shift] = iMAOnArray(ATRRSI,0,2*RSILength-1,0,1,shift);
for( shift=limit; shift>=0; shift--)
{
double del = iMAOnArray(Delta,0,2*RSILength-1,0,1,shift);
smin[shift] = SmRSI[shift] - K*del;
smax[shift] = SmRSI[shift] + K*del;
trend[shift] = trend[shift+1];
if (SmRSI[shift]>smax[shift+1]) trend[shift]= 1;
if (SmRSI[shift]<smin[shift+1]) trend[shift]=-1;
if(trend[shift]>0)
{
if (smin[shift]<smin[shift+1]) smin[shift]=smin[shift+1];
UpTrend[shift]=smin[shift];
DnTrend[shift]=EMPTY_VALUE;
}
else
if(trend[shift]<0)
{
if(smax[shift]>smax[shift+1]) smax[shift]=smax[shift+1];
DnTrend[shift]=smax[shift];
UpTrend[shift]=EMPTY_VALUE;
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
a to juz sRSI tez potrzebne i tez nie mam pojecia jak to przekonwertowac