//+------------------------------------------------------------------+ //| Price_Prediction.mq5 | //| Copyright 2012, Tyler Coyner SKSKSKSKSKSKS| //+------------------------------------------------------------------+ #property copyright "Copyright 2012, Tyler Coyner" #property version "1.00" #property indicator_chart_window #property indicator_buffers 11 #property indicator_plots 5 //--- plot ModelPast #property indicator_label1 "ModelPast" #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot ModelFuture #property indicator_label2 "ModelFuture" #property indicator_type2 DRAW_COLOR_CANDLES #property indicator_color2 clrDodgerBlue,clrRed #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- plot Confidence Cloud #property indicator_label3 "ConfidenceCloud" #property indicator_type3 DRAW_FILLING #property indicator_color3 clrAntiqueWhite,C'0,0,0' #property indicator_style3 STYLE_SOLID #property indicator_width3 1 //--- plot ConfidenceUp #property indicator_label4 "ConfidenceUp" #property indicator_type4 DRAW_LINE #property indicator_color4 clrRed #property indicator_style4 STYLE_SOLID #property indicator_width4 1 //--- plot ConfidenceDown #property indicator_label5 "ConfidenceDown" #property indicator_type5 DRAW_LINE #property indicator_color5 clrLime #property indicator_style5 STYLE_SOLID #property indicator_width5 1 //--- input parameters input int Ncoefficient=150; input int Nfuture=100; input double Kpast=3.0; input double dev=.01; //--- indicator buffers double ModelPastBuffer[]; double ModelFutureBuffer1[]; double ModelFutureBuffer2[]; double ModelFutureBuffer3[]; double ModelFutureBuffer4[]; double ModelFutureColors[]; double ConfidenceUpBuffer[]; double ConfidenceDownBuffer[]; double ConfidenceCloudBuffer1[]; double ConfidenceCloudBuffer2[]; //--- global stuff int Npast,dN; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- initialize global vars if(dev>1) { Print("Error! Dev must be less than 1!"); } Npast=int(Kpast*Ncoefficient); dN=0; //--- indicator buffers mapping ArraySetAsSeries(ModelPastBuffer,true); ArraySetAsSeries(ModelFutureBuffer1,true); ArraySetAsSeries(ModelFutureBuffer2,true); ArraySetAsSeries(ModelFutureBuffer3,true); ArraySetAsSeries(ModelFutureBuffer4,true); ArraySetAsSeries(ModelFutureColors,true); ArraySetAsSeries(ConfidenceUpBuffer,true); ArraySetAsSeries(ConfidenceDownBuffer,true); ArraySetAsSeries(ConfidenceCloudBuffer1,true); ArraySetAsSeries(ConfidenceCloudBuffer2,true); //--- PAST BUFFERS SetIndexBuffer(0,ModelPastBuffer,INDICATOR_DATA); //--- FUTURE BUFFERS SetIndexBuffer(1,ModelFutureBuffer1,INDICATOR_DATA); SetIndexBuffer(2,ModelFutureBuffer2,INDICATOR_DATA); SetIndexBuffer(3,ModelFutureBuffer3,INDICATOR_DATA); SetIndexBuffer(4,ModelFutureBuffer4,INDICATOR_DATA); SetIndexBuffer(5,ModelFutureColors,INDICATOR_COLOR_INDEX); //--- CONFIDENCE BUFFERS SetIndexBuffer(6,ConfidenceUpBuffer,INDICATOR_DATA); SetIndexBuffer(7,ConfidenceDownBuffer,INDICATOR_DATA); SetIndexBuffer(8,ConfidenceCloudBuffer1,INDICATOR_DATA); SetIndexBuffer(9,ConfidenceCloudBuffer2,INDICATOR_DATA); //--- Digits IndicatorSetInteger(INDICATOR_DIGITS,_Digits); //--- Plot Name IndicatorSetString(INDICATOR_SHORTNAME,"TySKS("+string(Npast)+","+string(Ncoefficient)+")"); //--- Plot Index stuff Integer PlotIndexSetInteger(1,PLOT_SHIFT,Nfuture); PlotIndexSetInteger(2,PLOT_SHIFT,Nfuture); PlotIndexSetInteger(3,PLOT_SHIFT,Nfuture); PlotIndexSetInteger(4,PLOT_SHIFT,Nfuture); PlotIndexSetInteger(5,PLOT_DRAW_BEGIN,Nfuture); PlotIndexSetInteger(6,PLOT_DRAW_BEGIN,0); PlotIndexSetInteger(7,PLOT_DRAW_BEGIN,0); PlotIndexSetInteger(8,PLOT_DRAW_BEGIN,0); PlotIndexSetInteger(9,PLOT_DRAW_BEGIN,0); //--- return(0); } //+------------------------------------------------------------------+ //| 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[]) { //--- Is there enough bars, bro? if(rates_total<(Npast+1)) { Print("Error!! Not Enough Bars BRO!!"); return(0); } //--- Comment!! //--- FUTURE && PAST initialize indicator to empty values ArrayInitialize(ModelPastBuffer,EMPTY_VALUE); ArrayInitialize(ModelFutureBuffer1,EMPTY_VALUE); ArrayInitialize(ModelFutureBuffer2,EMPTY_VALUE); ArrayInitialize(ModelFutureBuffer3,EMPTY_VALUE); ArrayInitialize(ModelFutureBuffer4,EMPTY_VALUE); //--- Confidence Level initialize empty value Comment("/0/0/0/0/0/0/0/0/0/0/0/0/0" + "\n" + "| |" + "\n" + "|This is soooo cool! :) |" + "\n" + "\0\0\0\0\0\0\0\0\0\0\0\0\0 " ); //--- PRICES, YES!! MqlRates rates[]; ArraySetAsSeries(rates,true); if(CopyRates(NULL,0,0,Npast+1,rates)<=0) return(0); //+------------------------------------------------------------------+ //| AutoRegression Stuff | //+------------------------------------------------------------------+ //--- Here we go buddy! //--- Prep double o[]; double h[]; double l[]; double c[]; ArrayResize(o,Npast); ArrayResize(h,Npast); ArrayResize(l,Npast); ArrayResize(c,Npast); for(int i=0;i 1.0) ro= 1.0; if(ro<-1.0) ro=-1.0; } else { for(int i=k;i=k;i--) { tmpo=dfo[i]; dfo[i]+=ro*dbo[i-1]; dbo[i]=dbo[i-1]+ro*tmpo; } } } //--- BURG-H --- HIGH!!! void Burgh(double &h[],int n,int p,double &ah[]) { double dfh[],dbh[]; ArrayResize(dfh,n); ArrayResize(dbh,n); double tmph,numh,denh,rh; for(int i=0;i 1.0) rh= 1.0; if(rh<-1.0) rh=-1.0; } else { for(int i=k;i=k;i--) { tmph=dfh[i]; dfh[i]+=rh*dbh[i-1]; dbh[i]=dbh[i-1]+rh*tmph; } } } //--- BURG-L ---- LOW!! void Burgl(double &l[],int n,int p,double &al[]) { double dfl[],dbl[]; ArrayResize(dfl,n); ArrayResize(dbl,n); double tmpl,numl,denl,rl; for(int i=0;i 1.0) rl= 1.0; if(rl<-1.0) rl=-1.0; } else { for(int i=k;i=k;i--) { tmpl=dfl[i]; dfl[i]+=rl*dbl[i-1]; dbl[i]=dbl[i-1]+rl*tmpl; } } } //--- BURG- C ---- CLOSE!! void Burgc(double &c[],int n,int p,double &ac[]) { double dfc[],dbc[]; ArrayResize(dfc,n); ArrayResize(dbc,n); double tmpc,numc,denc,rc; for(int i=0;i 1.0) rc= 1.0; if(rc<-1.0) rc=-1.0; } else { for(int i=k;i=k;i--) { tmpc=dfc[i]; dfc[i]+=rc*dbc[i-1]; dbc[i]=dbc[i-1]+rc*tmpc; } } //---- CONFIDENCE STUFF } //--- return value of prev_calculated for next call //+------------------------------------------------------------------+