[MT4指标]Extrapolator指标
主图指标
mt4指标类型:趋势指标
是否能用在mt4手机版上:否
是否含有未来函数:无
//+--------------------------------------------------------------------------------------+
//| Extrapolator.mq4 |
//| Copyright ? 2008, gpwr |
//| [email protected] |
//+--------------------------------------------------------------------------------------+
#property copyright "Copyright ? 2008, gpwr"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2
//Global constants
#define pi 3.141592653589793238462643383279502884197169399375105820974944592
//Input parameters
extern int Method =1; //Extrapolation method
extern int LastBar =30; //Last bar in the past data
extern int PastBars =300; //Number of past bars
extern double LPOrder =0.6; //Order of linear prediction model; 0 to 1
//LPOrder*PastBars specifies the number of prediction coefficients a[1..LPOrder*PastBars] where a[0]=1
extern int FutBars =100; //Number of bars to predict; for LP is set at PastBars-Order-1
extern int HarmNo =20; //Number of frequencies for Mathod 1; HarmNo=0 computes PastBars harmonics
extern double FreqTOL =0.0001;//Tolerance of frequency calculation for Method 1
//FreqTOL > 0.001 may not converge
extern int BurgWin =0; //Windowing function for Weighted Burg Method; 0=no window 1=Hamming 2=Parabolic
//Indicator buffers
double pv;
double fv;
//Global variables
double ETA,INFTY,SMNO;
int np,nf,lb,no,it;
int init()
{
lb=LastBar;
np=PastBars;
no=LPOrder*PastBars;
nf=FutBars;
if(Method>1) nf=np-no-1;
if(HarmNo==0) HarmNo=np;
IndicatorBuffers(4);
SetIndexBuffer(0,pv);
SetIndexBuffer(1,fv);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
SetIndexShift(0,-lb);//past data vector 0..np-1; 0 corresponds to bar=lb
SetIndexShift(1,nf-lb);//future data vector i=0..nf; nf corresponds to bar=lb
IndicatorShortName("Extrapolator");
return(0);
}
int deinit(){return(0);}
int start()
{
ArrayInitialize(pv,EMPTY_VALUE);
ArrayInitialize(fv,EMPTY_VALUE);
//Find average of past values
double av=0.0;
for(int i=0;i=1;i--) a=a[i-1];
}
//Calculate linear predictions
if(Method>1)
{
for(int n=no;nFreqTOL)
{
a=b;
z[1]=Open[1+lb]-pv[1]+a*z[0];
num=z[0]*z[1];
den=z[0]*z[0];
for(int i=2;i1) r=1.0;
if(r<-1.0) r=-1.0;
}
else
{
for(i=k;i=k;i--)
{
tmp=df;
df+=r*db[i-1];
db=db[i-1]+r*tmp;
}
}
}
//+-------------------------------------------------------------------------+
double win(int i, int k, int n, int w)
{
if(w==0) return(1.0);
if(w==1) return(0.54-0.46*MathCos(pi*(2.0*(i-k)+1.0)/(n-k)));
if(w==2) return(6.0*(i-k+1.0)*(n-i)/(n-k)/(n-k+1.0)/(n-k+2.0));
}
//+-------------------------------------------------------------------------+
void HNBurg(double x, int p, double& a)
{
int n=ArraySize(x);
double df,db;
ArrayResize(df,n);
ArrayResize(db,n);
int i,k,kh,ki;
double w,tmp,num,den,r;
for(i=0;i1) r=1.0;
if(r<-1.0) r=-1.0;
}
else
{
w=0.0;
for(i=1;i=k;i--)
{
tmp=df;
df+=r*db[i-1];
db=db[i-1]+r*tmp;
}
}
}
//+-------------------------------------------------------------------------+
void Geom(double x, int p, double& a)
{
int n=ArraySize(x);
double df,db;
ArrayResize(df,n);
ArrayResize(db,n);
int i,k,kh,ki;
double tmp,num,denf,denb,r;
for(i=0;i=k;i--)
{
tmp=df;
df+=r*db[i-1];
db=db[i-1]+r*tmp;
}
}
}
//+-------------------------------------------------------------------------+
/* Modified Covariance method from Marple's book. It solves
e[j]=y[j]+SUM(a*y[j-i-1],i=0...m-1), j=0..n-1
for a by the least-squares minimization of e[j] in both directions of j.
The code substitues y[j] with x[n-1-j] because, in the provided data,
x[0] is the latest data point. */
void MCov(double x, int ip, double& a, bool& stop)
{
//Initialization
int n=ArraySize(x);
double c,d,r,v;
ArrayResize(c,ip+1);
ArrayResize(d,ip+1);
ArrayResize(r,ip);
int k,m,mk;
double r1,r2,r3,r4,r5,delta,gamma,lambda,theta,psi,xi;
double save1,save2,save3,save4,c1,c2,c3,c4,ef,eb;
r1=0.0;
for(k=1;k0)
{
for(k=1;k<=m;k++)
{
theta+=x[k]*d[k];
psi+=x[k]*c[k];
xi+=x[n-1-k]*d[k];
r[k-1]-=(x[m]*x[m-k]+x[n-1-m]*x[n-1-m+k]);
save1+=r[k-1]*a[m-k];
}
}
//order update of a
c1=-save1/v;
a[m]=c1;
v*=(1.0-c1*c1);
if(m>0)
{
for(k=0;k<(m+1)/2;k++)
{
mk=m-k-1;
save1=a[k];
a[k]=save1+c1*a[mk];
if(k!=mk) a[mk]+=c1*save1;
}
}
if(m==ip-1)
{
v*=(0.5/(n-1-m));
break;
}
//time update of c,d,gamma,delta, and lambda
r1=1.0/(delta*gamma-lambda*lambda);
c1=(theta*lambda+psi*delta)*r1;
c2=(psi*lambda+theta*gamma)*r1;
c3=(xi*lambda+theta*delta)*r1;
c4=(theta*lambda+xi*gamma)*r1;
for(k=0;k<=m/2;k++)
{
mk=m-k;
save1=c[k];
save2=d[k];
save3=c[mk];
save4=d[mk];
c[k]+=(c1*save3+c2*save4);
d[k]+=(c3*save3+c4*save4);
if(k!=mk)
{
c[mk]+=(c1*save1+c2*save2);
d[mk]+=(c3*save1+c4*save2);
}
}
r2=psi*psi;
r3=theta*theta;
r4=xi*xi;
r5=gamma-(r2*delta+r3*gamma+2.0*psi*lambda*theta)*r1;
r2=delta-(r3*delta+r4*gamma+2.*theta*lambda*xi)*r1;
gamma=r5;
delta=r2;
lambda+=(c3*psi+c4*theta);
if(v<=0.0)
{
Print("Error: negative or zero variance in MCov");
stop=true;
return;
}
if(delta<=0.0 || delta>1.0 || gamma<=0.0 || gamma>1.0)
{
Print("Error: delta and gamma are outside (0,1) in MCov");
stop=true;
return;
}
//time update of a; order updates of c,d,gamma,delta, and lambda
r1=1.0/v;
r2=1.0/(delta*gamma-lambda*lambda);
ef=x[n-m-2];
eb=x[m+1];
for(k=0;k<=m;k++)
{
ef+=a[k]*x[n-1-m+k];
eb+=a[k]*x[m-k];
}
c1=eb*r1;
c2=ef*r1;
c3=(eb*delta+ef*lambda)*r2;
c4=(ef*gamma+eb*lambda)*r2;
for(k=m;k>=0;k--)
{
save1=a[k];
a[k]=save1+c3*c[k]+c4*d[k];
c[k+1]=c[k]+c1*save1;
d[k+1]=d[k]+c2*save1;
}
c[0]=c1;
d[0]=c2;
r3=eb*eb;
r4=ef*ef;
v-=(r3*delta+r4*gamma+2.0*ef*eb*lambda)*r2;
delta-=r4*r1;
gamma-=r3*r1;
lambda+=ef*eb*r1;
if(v<=0.0)
{
Print("Error: negative or zero variance in MCov");
stop=true;
return(0);
}
if(delta<=0.0 || delta>1.0 || gamma<=0.0 || gamma>1.0)
{
Print("Error: delta and gamma are outside (0,1) in MCov");
stop=true;
return(0);
}
}
//for(m=ip;m>=1;m--) a[m]=a[m-1];
//a[0]=1.0;
}
Extrapolator.jpg
发表于:2017-08-10 00:44只看该作者
2楼
ddddddddddddddddddddddddd
韬客社区www.talkfx.co
发表于:2021-01-08 00:39只看该作者
3楼
aaaaaaaaaaaaaaaaaa
韬客社区www.talkfx.co