#property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 clrRed #property indicator_level1 0 double universal[]; double filt[]; double whiteNoise[]; double peak[]; input int bandEdge=40; input int k = 0; int buffers=0; int drawBegin=64; double a1,b1,c1,c2,c3; double alpha1; double freq,hpFreq,deg2rad; double tempReal= MathArctan(1.0); double rad2Deg = 45.0 / tempReal; double deg2Rad = 1.0 / rad2Deg; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int init() { IndicatorBuffers(4); initBuffer(universal,"Universal",DRAW_LINE); initBuffer(filt); initBuffer(whiteNoise); initBuffer(peak); IndicatorShortName("Universal Oscillator ["+IntegerToString(bandEdge)+"]"); return (0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { if(Bars <= drawBegin) return (0); int countedBars=IndicatorCounted(); if(countedBars < 0) return (-1); if(countedBars>0) countedBars--; int i,limit=MathMin(Bars-countedBars-1,Bars-drawBegin); a1 = MathExp(-MathSqrt(2.0)*M_PI/bandEdge); b1 = 2*a1*MathCos(deg2Rad*MathSqrt(2.0)*180.0/bandEdge); c2 = b1; c3 = -a1*a1; c1 = 1.0-c2-c3; for(i=limit; i>=0; i--) { whiteNoise[i]=(Close[i]-Close[i+2])/2.0; filt[i]=c1*(whiteNoise[i]+whiteNoise[i+1])/2.0+c2*filt[i+1]+c3*filt[i+2]; if(i==limit) filt[i]=0.0; if(i==limit-1) filt[i] = c1*0*(Close[i]+Close[i+1])/2.0+c2*filt[i+1]; if(i==limit-2) filt[i] = c1*0*(Close[i]+Close[i+1])/2.0+c2*filt[i+1]+c3*filt[i+2]; if(i==limit) { peak[i]=0.0000001; }else{ peak[i]=0.991*peak[i+1]; } if(MathAbs(filt[i])>peak[i]) peak[i]=MathAbs(filt[i]); if(peak[i]!=0) { universal[i]=filt[i]/peak[i]; } } return (0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void initBuffer(double &array[],string label="",int type=DRAW_NONE,int arrow=0,int style=EMPTY,int width=EMPTY,color clr=CLR_NONE) { SetIndexBuffer(buffers,array); SetIndexLabel(buffers,label); SetIndexEmptyValue(buffers,EMPTY_VALUE); SetIndexDrawBegin(buffers,drawBegin); SetIndexShift(buffers,0); SetIndexStyle(buffers,type,style,width); SetIndexArrow(buffers,arrow); buffers++; } //+------------------------------------------------------------------+