//+------------------------------------------------------------------+ //| COG_CCI_VS.mq4 | //| Copyright 2019, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2019, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" //---------ang_pr (Din)-------------------- #property indicator_separate_window #property indicator_buffers 6 #property indicator_color1 Lime #property indicator_color2 Yellow #property indicator_color3 Yellow #property indicator_color4 Yellow #property indicator_color5 Yellow #property indicator_color6 Turquoise #property indicator_level1 -200 #property indicator_level2 200 #property indicator_level3 -100 #property indicator_level4 100 #property indicator_level5 0 #property indicator_levelcolor clrSilver #property indicator_levelstyle STYLE_DOT #property indicator_style1 1 #property indicator_style7 2 #property indicator_width2 2 #property indicator_width3 2 //----------------------------------- extern int bars_back=250; extern int ExtCCIPeriod=14; extern int m = 5; extern int i = 1; extern double kstd=1.618; extern double kstd_internal=0.8; extern int sName=2; //----------------------- double fx[],sqh[],sql[],stdh[],stdl[],stochdata[]; double ai[10,10],b[10],x[10],sx[20]; double sum; int ip,p,n,f; double qq,mm,tt; int ii,jj,kk,ll,nn; double sq,std; bool ready_flag=false; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Prepare_Object() { if(ready_flag==true) return; p=MathRound(bars_back); nn=m+1; ObjectCreate("sstart"+sName,22,0,Time[p],fx[p]); ObjectSet("sstart"+sName,14,159); ready_flag=true; } //******************************************* int init() { IndicatorShortName("COG_CCI_VS"); SetIndexBuffer(0,fx);SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(1,sqh);SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2); SetIndexBuffer(2,sql);SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,2); SetIndexBuffer(3,stdh);SetIndexStyle(3,DRAW_LINE,STYLE_DOT,1); SetIndexBuffer(4,stdl);SetIndexStyle(4,DRAW_LINE,STYLE_DOT,1); SetIndexBuffer(5,stochdata);SetIndexStyle(5,DRAW_LINE); ready_flag=false; return(0); } //---------------------------------------------------------- int deinit() { ObjectDelete("sstart"+sName); return(0); } //********************************************************************************************** int start() { int mi; if (ready_flag==false) Prepare_Object(); //------------------------------------------------------------------------------------------- ip= iBarShift(Symbol(),Period(),ObjectGet("sstart"+sName,OBJPROP_TIME1)); p = bars_back; sx[1]=p+1; SetIndexDrawBegin(0,Bars-p-1); SetIndexDrawBegin(1,Bars-p-1); SetIndexDrawBegin(2,Bars-p-1); SetIndexDrawBegin(3,Bars-p-1); SetIndexDrawBegin(4,Bars-p-1); //----------------------sx------------------------------------------------------------------- int counted_bars = IndicatorCounted(); if(counted_bars < 0) return(-1); if(counted_bars > 0) counted_bars--; int rlimit = Bars - counted_bars; if(counted_bars==0) rlimit-=1; //---- main loop for(int ri=0; rimm) { 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); } } //=========================================================================================================================== for(n=i; n<=i+p; n++) { sum=0; for(kk=1; kk<=m; kk++) { sum+=x[kk+1]*MathPow(n,kk); } fx[n]=x[1]+sum; } //-----------------------------------Std----------------------------------------------------------------------------------- sq=0.0; for(n=i; n<=i+p; n++) { sq+=MathPow(iCCI(NULL,0,ExtCCIPeriod,PRICE_TYPICAL,n) -fx[n],2); } sq=MathSqrt(sq/(p+1))*kstd; std=iStdDevOnArray(stochdata,0,p,0,MODE_SMA,i) *kstd_internal; for(n=i; n<=i+p; n++) { sqh[n] = fx[n] + sq; sql[n] = fx[n] - sq; stdh[n] = fx[n] + std; stdl[n] = fx[n] - std; } //------------------------------------------------------------------------------- ObjectMove("sstart"+sName,0,Time[p],fx[p]); //---------------------------------------------------------------------------------------------------------------------------- return(0); } //==========================================================================================================================