//+------------------------------------------------------- //| Stat-Arbitrage Indicator.mq4 | //| Ilya Kiselev, JIBS | //| http://www.jibs.se | //+------------------------------------------------------- #property indicator_chart_window #property indicator_buffers 4 #property indicator_color2 Yellow #property indicator_color3 Blue #property indicator_color4 Red extern double T=8; extern int porog_E =10; double H1, L1, A1, H2, L2, A2, H3, L3, A3, T_half, Zt, Wt; //---- buffers double ExtMapBuffer1[]; double Signal[]; double Up[]; double Dn[]; double Fl[]; //+------------------------------------------------------- //| Custom indicator initialization function | //+------------------------------------------------------- int init() { //---- indicators SetIndexStyle(0,DRAW_NONE); SetIndexDrawBegin(0,0); SetIndexBuffer(0,ExtMapBuffer1); SetIndexStyle(1,DRAW_LINE); SetIndexDrawBegin(1,0); SetIndexBuffer(1,Fl); SetIndexStyle(2,DRAW_LINE); SetIndexDrawBegin(2,0); SetIndexBuffer(2,Up); SetIndexStyle(3,DRAW_LINE); SetIndexDrawBegin(3,0); SetIndexBuffer(3,Dn); IndicatorShortName("Indicator EMAVFS"); return; } //+------------------------------------------------------- //| Custom indicator iteration function | //+------------------------------------------------------- int start() { int i; int Indicator_Counted=IndicatorCounted(); int limit=Bars-Indicator_Counted; T_half = T/2; //---- for ( i=limit;i>=0;i--) { H1=High[iHighest(NULL,0,MODE_HIGH, T_half, i)]; L1=Low[iLowest(NULL,0,MODE_LOW, T_half, i)]; A1 = H1-L1; H2=High[iHighest(NULL,0,MODE_HIGH, T, i+T_half)]; L2=Low[iLowest(NULL,0,MODE_LOW, T, i+T_half)]; A2 = H2-L2; H3=High[iHighest(NULL,0,MODE_HIGH, T, i)]; L3=Low[iLowest(NULL,0,MODE_LOW, T, i)]; A3 = H3-L3; Zt = (MathAbs(Close[i]-ExtMapBuffer1[i+1]))/porog_E; if ((Zt<=1) && (Zt>=0)) { Wt = 0.5 * (1 - MathSqrt(1 - Zt*Zt)); } else if (Zt>1) { Wt = 0.5 * (1 + MathSqrt(1 - 1/(Zt*Zt))); } ExtMapBuffer1[i] = Wt*Close[i] + (1Wt)*ExtMapBuffer1[i+1]; if(MathAbs(ExtMapBuffer1[i]-ExtMapBuffer1[i+1]) >=porog_E*Point) { if(i>0) { if(Close[i]<=ExtMapBuffer1[i]) { Dn[i]=ExtMapBuffer1[i]; } else { Fl[i]=ExtMapBuffer1[i]; } if(Close[i] >=ExtMapBuffer1[i]) { Up[i]=ExtMapBuffer1[i]; } else { Fl[i]=ExtMapBuffer1[i]; } } else { Fl[i]=ExtMapBuffer1[i]; } } else { ExtMapBuffer1[i]=ExtMapBuffer1[i+1]; Fl[i]=ExtMapBuffer1[i]; } } return(0); }