//+------------------------------------------------------------------+ //| | //| Индикатор для автоматического построения сужения | //| каналов линейной регрессии | //| http://www.mql4.com/ru/users/Dserg | //+------------------------------------------------------------------+ #property copyright "Dserg, 2010" #property link "http://www.mql4.com/ru/users/Dserg" //---- indicator settings #property indicator_chart_window #property indicator_buffers 8 #property indicator_color1 DeepSkyBlue #property indicator_color2 DeepSkyBlue #property indicator_color3 FireBrick #property indicator_color4 DeepSkyBlue #property indicator_color5 DeepSkyBlue #property indicator_color6 Yellow #property indicator_color7 HotPink #property indicator_color8 LawnGreen //---- buffers double B0[]; double B1[]; double Stop[]; double B3[]; double B4[]; double Up[]; double Dn[]; double Target[]; extern int Nlin=25; extern int r0=150; extern double t0=2.618; extern bool useClose=true; static bool isChannel; static int chEnd; static double a0; static double b0; static double range0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- 3additional buffers are used for counting. //---- drawing settings SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2); SetIndexBuffer(0,B0); SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2); SetIndexBuffer(1,B1); SetIndexStyle(2,DRAW_ARROW,0,2); SetIndexBuffer(2,Stop); SetIndexStyle(3,DRAW_LINE,STYLE_DOT); SetIndexBuffer(3,B3); SetIndexStyle(4,DRAW_LINE,STYLE_DOT); SetIndexBuffer(4,B4); SetIndexStyle(5,DRAW_ARROW,0,1); SetIndexBuffer(5,Up); SetIndexArrow(5,233); SetIndexStyle(6,DRAW_ARROW,0,1); SetIndexBuffer(6,Dn); SetIndexArrow(6,234); SetIndexStyle(7,DRAW_ARROW,0,1); SetIndexBuffer(7,Target); SetIndexArrow(7,231); SetIndexEmptyValue(0,0.0); SetIndexEmptyValue(1,0.0); SetIndexEmptyValue(2,0.0); SetIndexEmptyValue(3,0.0); SetIndexEmptyValue(4,0.0); SetIndexEmptyValue(5,0.0); SetIndexEmptyValue(6,0.0); SetIndexEmptyValue(7,0.0); isChannel=false; return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int deinit() { } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; int loopbegin=Bars-counted_bars; if(counted_bars==0) loopbegin-=1+Nlin+2; int i,j; double a,b,c, sumy=0.0, sumx=0.0, sumxy=0.0, sumx2=0.0, h=0.0,l=0.0, range=0.0; for(i=loopbegin; i>0; i--) { bool flag=false; for(j=0;j0.0 && !isChannel) { flag=true; } } if(flag) continue; //у нас уже есть канал, ждём, пока его пробьёт if(isChannel) { //double up0=a0*(i-chEnd)+b0+range0; //double dn0=a0*(i-chEnd)+b0-range0; double up0=a0*i+b0+range0; double dn0=a0*i+b0-range0; B3[i]=up0; B4[i]=dn0; //проверяем пробитие //вверх if(Open[i]>up0) { Up[i]=up0; Stop[i]=dn0; Target[i]=up0+(up0-dn0)*(t0-1); isChannel=false; continue; } //вниз if(Open[i]h) h = Close[i+j]-LR; if(LR-Close[i+j]>l) l = LR - Close[i+j]; } else { if(High[j+i]-LR > h) h = High[i+j]-LR; if(LR - Low[i+j]> l) l = LR - Low[i+j]; } } range=MathMax(l,h); //проверка ширины канала if(range