Просьба сделать следующий индикатор
R-квадрат
http://codebase.mql4.com/ru/4706
Код под капотом
Click to reveal..
//+------------------------------------------------------------------+
//| r-squared indicator
//| by Onur Sirek
//+------------------------------------------------------------------+
#property copyright "Onur Sirek"
#property link "melihonurs@gmail.com"

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_level1 0.2
#property indicator_level2 0.8

extern int RSQPeriod=9;
double RSQBuffer[];

int init()
{
string short_name;
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,RSQBuffer);
short_name="r-squared("+RSQPeriod+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
SetIndexDrawBegin(0,RSQPeriod);
SetLevelValue(0,calcLevel(RSQPeriod));
return(0);
}

int start()
{
int i,k, start;
int counted_bars=IndicatorCounted();

if ((RSQPeriod<2) || (Bars<RSQPeriod)) return(0);
start=Bars-RSQPeriod-1;
if(counted_bars>RSQPeriod) start=Bars-counted_bars-1;

for (i=start; i>=0; i--) {
RSQBuffer[i] = RSquared(RSQPeriod,i);
}

return(0);
}

double calcLevel(double per)
{
double per1,lev1, lenper, levdif;
if (per<=5) return(0.77);
if ((per>5) && (per<=10)) { per1=5; lev1=0.77; lenper=5; levdif=0.37; }
if ((per>10) && (per<=14)) { per1=10; lev1=0.40; lenper=4; levdif=0.13; }
if ((per>14) && (per<=20)) { per1=14; lev1=0.27; lenper=6; levdif=0.07; }
if ((per>20) && (per<=25)) { per1=20; lev1=0.20; lenper=5; levdif=0.04; }
if ((per>25) && (per<=30)) { per1=25; lev1=0.16; lenper=5; levdif=0.03; }
if ((per>30) && (per<=50)) { per1=30; lev1=0.13; lenper=20; levdif=0.05; }
if ((per>50) && (per<=60)) { per1=50; lev1=0.08; lenper=10; levdif=0.02; }
if ((per>60) && (per<=120)) { per1=60; lev1=0.06; lenper=60; levdif=0.03; }
if (per>120) return(0.03);
return(lev1 - (per-per1)*(levdif/lenper));
}

// r-squared shows the correlation with its linear regression line
// values close to 1.0 show perfect relation
// values close to 0.0 show poor relation
// See Metastock Help
// To determine if the trend is statistically significant for a given x-period linear regression line,
// plot the r-squared indicator and refer to the following table. This table shows the values of
// r-squared required for a 95% confidence level at various time periods. If the r-squared value
// is less than the critical values shown, you should assume that prices show no statistically
// significant trend.
// Number ofPeriods r-squaredCritical Value(95%confidence)
// 5 0.77
// 10 0.40
// 14 0.27
// 20 0.20
// 25 0.16
// 30 0.13
// 50 0.08
// 60 0.06
// 120 0.03
// You may even consider opening a short-term position opposite the prevailing trend when you
// observe r-squared rounding off at extreme levels. For example, if the slope is positive and
// r-squared is above 0.80 and begins to turn down, you may consider selling or opening a short position.
// There are numerous ways to use the linear regression outputs of r-squared and Slope in trading
// systems. For more detailed coverage, refer to the book The New Technical Trader by Tushar Chande
// and Stanley Kroll.
double RSquared(int per, int shift)
{
int i;
double x, y, div;
double Ex=0.0, Ey=0.0, Exy=0.0, Ex2=0.0, Ey2=0.0;
double Ex22, Ey22;
double r;
for (i=1; i<=per; i++) {
x = i; // x axis value
y = Close[shift+i]; // y axis value
Ex += x;
Ey += y;
Exy += x*y;
Ex2 += MathPow(x,2);
Ey2 += MathPow(y,2);
}
Ex22=MathPow(Ex,2);
Ey22=MathPow(Ey,2);
//slope = (per*Exy-Ex*Ey) / (per*Ex2-Ex22); // slope of regression line
//b = (Ey-slope*Ex)/per;
div = MathSqrt((per*Ex2-Ex22)*(per*Ey2-Ey22));
if (div==0) return(0);
r = (per*Exy-Ex*Ey) / div;
return(MathPow(r,2));
}


И еще один из этой же серии.
Linear Regression Slope
http://codebase.mql4.com/ru/3653#11647
Код под капотом

Click to reveal..
//+------------------------------------------------------------------+
//| LinearRegSlope_v1.mq4 |
//| Copyright © 2006, TrendLaboratory |
//| http://finance.groups.yahoo.com/group/TrendLaboratory |
//| E-mail: igorad2003@yahoo.co.uk |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, TrendLaboratory"
#property link "http://finance.groups.yahoo.com/group/TrendLaboratory"
//----
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 SkyBlue
#property indicator_width1 2
//---- input parameters
extern int Price =0; //Apply to Price(0-Close;1-Open;2-High;3-Low;4-Median price;5-Typical price;6-Weighted Close)
extern int Length =14; //Period of NonLagMA
//---- indicator buffers
double RegSlope[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,RegSlope);
string short_name;
//---- indicator line
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
//---- name for DataWindow and indicator subwindow label
short_name="LinearRegSlope("+Length+")";
IndicatorShortName(short_name);
SetIndexLabel(0,"LinearRegSlope");
SetIndexDrawBegin(0,Length);
//----
return(0);
}
//+------------------------------------------------------------------+
//| LinearRegSlope_v1 |
//+------------------------------------------------------------------+
int start()
{
int i,shift, counted_bars=IndicatorCounted(),limit;
double price;
if(counted_bars > 0) limit=Bars-counted_bars;
if(counted_bars < 0) return(0);
if(counted_bars ==0) limit=Bars-Length-1;
if(counted_bars < 1)
for(i=1;i<Length;i++) RegSlope[Bars-i]=0;
double SumBars=Length * (Length - 1) * 0.5;
double SumSqrBars=(Length - 1.0) * Length * (2.0 * Length - 1.0)/6.0;
for(shift=limit;shift>=0;shift--)
{
double Sum1=0;
for(i=0;i<=Length-1;i++) Sum1+=i*iMA(NULL,0,1,0,1,Price,i+shift);
double SumY=0;
for(i=0;i<=Length-1;i++) SumY+=iMA(NULL,0,1,0,1,Price,i+shift);
double Sum2=SumBars * SumY;
double Num1=Length * Sum1 - Sum2;
double Num2=SumBars * SumBars - Length * SumSqrBars;
if(Num2!=0)
RegSlope[shift]=100*Num1/Num2;
else
RegSlope[shift]=0;
}
//----
return(0);
}


И код с метастока

Click to reveal..
Linear Regression Slope

nio:=Input("Number of points taken to calculate the ROCs",3,1000,14);

rll:=ROC(O,nio-1,%)/(nio-1);
rl:=ROC(O,nio,%)/nio;
rh:=ROC(O,nio+1,%)/(nio+1);
rhh:=ROC(O,nio+2,%)/(nio+2);

xio:=Input("Distances of ROCs from interpolation point XIO ",0.01,1,0.5);

rit:=(rll / (1+xio) +
rl / (xio+.0001)+
rh / (1-xio) +
rhh / (2-xio)) /
( 1 / (1+xio) + 1 / (xio+.0001) + 1 / (1-xio) + 1 / (2-xio));

ro:=LinRegSlope(LinRegSlope(rit,nio),nio);
ro


Отредактировано Frend (Mon Jul 26 2010 02:15 AM)
_________________________
Помогу с реализацией вашей идеи, оценкой системы. Консультации
frendwork@rambler.ru