//+------------------------------------------------------------------+
//| Redco.mq4 |
//| Copyright 2014, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 8
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 Yellow
extern int RSI_Period = 21;
double A[],B[],C[];
int OnInit()
{
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,A);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,B);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,C);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
int i, limit=(rates_total)-prev_calculated;
for( i=0; i<limit+1; i++){
A[i] = iRSI(NULL,0,RSI_Period,3,i);
B[i] = SS(RSI_Period,i);
C[i] = QQ(A,RSI_Period,i);
A[i] = QQ(B,RSI_Period,i);
B[i] = QQ(C,9,i);
}
return(rates_total);
}
//+------------------------------------------------------------------+
double SS(int vv, int bar){double nn = 9999, rr = -5555;
for(int i = 0; i < vv; i++){
if (nn > A[bar + i]) nn = A[bar + i];
if (rr < A[bar + i]) rr = A[bar + i];
}
if (nn == rr) return (B[bar+1]);
return (100 * (A[bar] - nn) / (rr - nn));
}
double QQ (double& array[], int period, int shift){double ss = 0;
for (int i = shift + period - 1; i >= shift; i--){ss += array[i];
}
return (ss / period);
}