//------------------------------------------------------------------ #property copyright "copyright© mladen" #property link "mladenfx@gmail.com" //------------------------------------------------------------------ #property indicator_separate_window #property indicator_buffers 4 #property indicator_plots 3 #property indicator_label1 "Trend" #property indicator_type1 DRAW_FILLING #property indicator_color1 clrLightGreen,clrOrange #property indicator_label2 "Real" #property indicator_type2 DRAW_LINE #property indicator_color2 clrMediumSeaGreen #property indicator_width2 2 #property indicator_label3 "Imaginary" #property indicator_type3 DRAW_LINE #property indicator_color3 clrOrangeRed #property indicator_width3 2 // // // input int inpPeriod = 35; // Period double valr[],vali[],fillu[],filld[],tcos[],tsin[]; struct sGlobalStruct { double real,imag,cSx,sSx,cSy,sSy,cSxx,sSxx,cSxy,sSxy,cSyy,sSyy,X,cY,sY; int lim; }; sGlobalStruct glo; //------------------------------------------------------------------ // //------------------------------------------------------------------ int OnInit() { SetIndexBuffer(0,fillu,INDICATOR_DATA); SetIndexBuffer(1,filld,INDICATOR_DATA); SetIndexBuffer(2,valr ,INDICATOR_DATA); SetIndexBuffer(3,vali ,INDICATOR_DATA); // // // ArrayResize(tcos,inpPeriod); for (int i=0; i=k; k++) { glo.X = close[i-k]; glo.cY = tcos[k]; glo.sY = tsin[k]; glo.cSx = glo.cSx + glo.X ; glo.cSy = glo.cSy + glo.cY; glo.cSxx = glo.cSxx + glo.X * glo.X; glo.cSxy = glo.cSxy + glo.X * glo.cY; glo.cSyy = glo.cSyy + glo.cY * glo.cY; glo.sSx = glo.sSx + glo.X ; glo.sSy = glo.sSy + glo.sY; glo.sSxx = glo.sSxx + glo.X * glo.X; glo.sSxy = glo.sSxy + glo.X * glo.sY; glo.sSyy = glo.sSyy + glo.sY * glo.sY; } if ((inpPeriod*glo.cSxx-glo.cSx*glo.cSx > 0 ) && (inpPeriod*glo.cSyy-glo.cSy*glo.cSy > 0 )) valr[i] = fillu[i] = (inpPeriod*glo.cSxy-glo.cSx*glo.cSy)/sqrt((inpPeriod*glo.cSxx-glo.cSx*glo.cSx)*(inpPeriod*glo.cSyy-glo.cSy*glo.cSy)); if ((inpPeriod*glo.sSxx-glo.sSx*glo.sSx > 0 ) && (inpPeriod*glo.sSyy-glo.sSy*glo.sSy > 0 )) vali[i] = filld[i] = (inpPeriod*glo.sSxy-glo.sSx*glo.sSy)/sqrt((inpPeriod*glo.sSxx-glo.sSx*glo.sSx)*(inpPeriod*glo.sSyy-glo.sSy*glo.sSy)); } return(rates_total); }