//+------------------------------------------------------------------+
//| IRB.mq5 |
//| David Lee |
//+------------------------------------------------------------------+
#property copyright "David Lee"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots 5
#property indicator_color1 Red
#property indicator_color2 Orange
#property indicator_color3 Yellow
#property indicator_color4 Green
#property indicator_color5 Aqua
#property indicator_type1 DRAW_LINE
#property indicator_type2 DRAW_LINE
#property indicator_type3 DRAW_LINE
#property indicator_type4 DRAW_LINE
#property indicator_type5 DRAW_LINE
#property indicator_label1 "rpc"
#property indicator_label1 "sqh"
#property indicator_label1 "sql"
#property indicator_label1 "sqh2"
#property indicator_label1 "sql2"
#property indicator_style1 STYLE_SOLID
#property indicator_style2 STYLE_SOLID
#property indicator_style3 STYLE_SOLID
#property indicator_style4 STYLE_SOLID
#property indicator_style5 STYLE_SOLID
//---- input parameters
input int degree=3;
input int period=120;
input double strdDev=1.62;
input double strdDev2=2;
//---- indicator buffers
double prc[];
double sqh[];
double sql[];
double sql2[];
double sqh2[];
double ai[10,10];
double b[10];
double x[10];
double sx[10];
double sum;
int ip;
int p;
int n;
int f;
double qq;
double mm;
double tt;
int ii;
int jj;
int kk;
int ll;
int nn;
double sq;
double sq2;
int i0 = 0;
int mi;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit(void)
{
//---- 3 indicator buffers mapping
SetIndexBuffer(0,prc,INDICATOR_DATA);
SetIndexBuffer(1,sqh,INDICATOR_DATA);
SetIndexBuffer(2,sql,INDICATOR_DATA);
SetIndexBuffer(3,sql2,INDICATOR_DATA);
SetIndexBuffer(4,sqh2,INDICATOR_DATA);
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,0);
PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,0);
PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,0);
PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,0);
PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,0);
//---- index labels
PlotIndexSetString(0,PLOT_LABEL,"prc");
PlotIndexSetString(1,PLOT_LABEL,"sqh");
PlotIndexSetString(1,PLOT_LABEL,"sql");
PlotIndexSetString(1,PLOT_LABEL,"sqh2");
PlotIndexSetString(1,PLOT_LABEL,"sql2");
}
//+------------------------------------------------------------------+
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 limit=rates_total-prev_calculated;
//---- main loop
ip = period; // 120
p = ip; //120
sx[1] = p + 1; //121
nn = degree + 1; // 4
//----------------------sx-------------------------------------------------------------------
//
for (mi = 1; mi <= nn * 2 - 2; mi++)
{
sum = 0;
for (n = i0; n <= i0 + p; n++) //i0=0 120
{
sum += MathPow(n, mi);
}
sx[mi + 1] = sum;
}
//----------------------syx-----------
for (mi = 1; mi <= nn; mi++)
{
sum = 0.0;
for (n = i0; n <= i0 + p; n++)
{
if (mi == 1)
sum += close[n];
else
sum += close[n] * MathPow(n, mi - 1);
}
b[mi] = sum;
}
//===============Matrix=======================================================================================================
for (jj = 1; jj <= nn; jj++)
{
for (ii = 1; ii <= nn; ii++)
{
kk = ii + jj - 1;
ai[ii, jj] = sx[kk];
}
}
//===============Gauss========================================================================================================
for (kk = 1; kk <= nn - 1; kk++)
{
ll = 0;
mm = 0;
for (ii = kk; ii <= nn; ii++)
{
if (MathAbs(ai[ii, kk]) > mm)
{
mm = MathAbs(ai[ii, kk]);
ll = ii;
}
}
if (ll == 0)
return 0;
if (ll != kk)
{
for (jj = 1; jj <= nn; jj++)
{
tt = ai[kk, jj];
ai[kk, jj] = ai[ll, jj];
ai[ll, jj] = tt;
}
tt = b[kk];
b[kk] = b[ll];
b[ll] = tt;
}
for (ii = kk + 1; ii <= nn; ii++)
{
qq = ai[ii, kk] / ai[kk, kk];
for (jj = 1; jj <= nn; jj++)
{
if (jj == kk)
ai[ii, jj] = 0;
else
ai[ii, jj] = ai[ii, jj] - qq * ai[kk, jj];
}
b[ii] = b[ii] - qq * b[kk];
}
}
x[nn] = b[nn] / ai[nn, nn];
for (ii = nn - 1; ii >= 1; ii--)
{
tt = 0;
for (jj = 1; jj <= nn - ii; jj++)
{
tt = tt + ai[ii, ii + jj] * x[ii + jj];
x[ii] = (1 / ai[ii, ii]) * (b[ii] - tt);
}
}
sq = 0.0;
sq2 = 0.0;
for (n = i0; n <= i0 + p; n++)
{
sum = 0;
for (kk = 1; kk <= degree; kk++)
{
sum += x[kk + 1] * MathPow(n, kk);
}
prc[n] = (x[1] + sum);
sq += MathPow(close[n] - prc[n], 2);
sq2 += MathPow(close[n] - prc[n], 2);
}
sq = MathSqrt(sq / (p + 1)) * strdDev;
sq2 = MathSqrt(sq2 / (p + 1)) * strdDev2;
for (n = i0; n <= i0 + p; n++)
{
sqh[n] = (prc[n] + sq);
sql[n] = (prc[n] - sq);
sqh2[n] = (prc[n] + sq2);
sql2[n] = (prc[n] - sq2);
}
//---- done
return(rates_total);
}
//+------------------------------------------------------------------+
- Need a programmer!
- 我用i-Regr 做出了不错的EA 请教fxcanada 请教i-Regr
- Sound Alert for i-Regression Channel