//------------------------------------------------------------------ #property copyright "copyright© mladen" #property link "mladenfx@gmail.com" //------------------------------------------------------------------ #property indicator_separate_window #property indicator_buffers 5 #property indicator_plots 2 #property indicator_label1 "Trend" #property indicator_type1 DRAW_FILLING #property indicator_color1 clrLightGreen,clrOrange #property indicator_label2 "State" #property indicator_type2 DRAW_COLOR_LINE #property indicator_color2 clrMediumSeaGreen,clrOrangeRed #property indicator_width2 2 // // // input int inpPeriod = 35; // Period double val[],valc[],fillu[],filld[],angle[],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,val ,INDICATOR_DATA); SetIndexBuffer(3,valc ,INDICATOR_COLOR_INDEX); SetIndexBuffer(4,angle,INDICATOR_CALCULATIONS); // // // 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)) glo.real = (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)) glo.imag = (inpPeriod*glo.sSxy-glo.sSx*glo.sSy)/sqrt((inpPeriod*glo.sSxx-glo.sSx*glo.sSx)*(inpPeriod*glo.sSyy-glo.sSy*glo.sSy)); if (glo.imag!=0) angle[i] = 90.0 + 90.0*MathArctan(glo.real/glo.imag) ; if (glo.imag >0) angle[i] = val[i] - 180.0; if (i>0 && (angle[i-1]-angle[i]<270 && angle[i]0) { if ((fabs(angle[i]-angle[i-1])<9.0 && angle[i]<0)) val[i] = -1; if ((fabs(angle[i]-angle[i-1])<9.0 && angle[i]>0)) val[i] = 1; } else val[i] = 0; fillu[i] = val[i]; valc[i] = val[i]>0 ? 0 : 1; } return(rates_total); }