//+------------------------------------------------------------------+ //| | //| Индикатор утреннего флета на основе | //| каналов линейной регрессии | //| http://www.mql4.com/ru/users/ikatsko | //+------------------------------------------------------------------+ #property copyright "Ivan Katsko" #property link "ICQ:372739628" //---- 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 string S3="Цель при пробое отн. ширины канала"; extern double t0=1.3; extern string S4="Использовать для расчёта Close"; extern bool useClose=true; extern string S5="Максимальный SL в пунктах"; extern int MaxSL=800; extern string StartTime = "20:00"; //Начало работы extern string FinishTime = "01:00"; //Конец работы extern int PeriodSilense = 12; string StTime, FinTime; bool New_Bar=false, // Флаг нового бара FindR0, isChannel; double a0; double b0; double range0; double MaxAggres, MinAggres; int r0, Nlin, loopbeg, NumMaxAggres; static datetime New_Time; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { FindR0=false; MaxAggres=0; MinAggres=0; //---- 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); //---- имя индикатора и подсказки для линий SetIndexLabel(0,"Channel Low"); SetIndexLabel(1,"Channel High"); SetIndexLabel(3,"Channel Low Extended"); SetIndexLabel(4,"Channel High Extended"); SetIndexLabel(5,"BUY Signal"); SetIndexLabel(6,"SELL Signal"); SetIndexLabel(2,"Stop/Reverse"); SetIndexLabel(7,"Target"); isChannel=false; return(0); } int deinit() { Comment(""); } int start() { if(Bars-IndicatorCounted()==0) return(0); Fun_New_Bar(); // Определение начала нового бара int i,j,k; if(New_Bar){ // Найдем StTime if(Time[0]==StrToTime(TimeToStr(Time[0], TIME_DATE)+" "+"01:00")) { int flatbeg=(Time[0]-StrToTime(TimeToStr(Time[0]-86400, TIME_DATE)+" "+StartTime))/60/Period(); int flatnull=(Time[0]-StrToTime(TimeToStr(Time[0], TIME_DATE)+" "+"00:00"))/60/Period(); MaxAggres=0; for(i=flatnull+1;i<=flatbeg;i++){ double m1=iCustom(0, 0, "Silense",PeriodSilense,288,0,i); double m2=iCustom(0, 0, "Silense",PeriodSilense,288,0,i+1); double m3=iCustom(0, 0, "Silense",PeriodSilense,288,0,i+2); if(m2>m1 && m2>m3 && m2>MaxAggres){ MaxAggres=m2; MinAggres=0; NumMaxAggres=i+1; } if(MaxAggres>50) break; } if(MaxAggres>0) {StTime=TimeToStr(Time[NumMaxAggres],TIME_MINUTES); FindR0=false;} else {StTime=StartTime;FindR0=false;} } else if(Time[0]<=StrToTime(TimeToStr(Time[0], TIME_DATE)+" "+FinishTime)) return(0); if(MinAggres==0){ if(Time[0]>=StrToTime(TimeToStr(Time[0], TIME_DATE)+" "+FinishTime)) { m1=iCustom(0, 0, "Silense",PeriodSilense,288,0,1); m2=iCustom(0, 0, "Silense",PeriodSilense,288,0,2); m3=iCustom(0, 0, "Silense",PeriodSilense,288,0,3); double n1=iCustom(0, 0, "Silense",PeriodSilense,288,1,1); double n3=iCustom(0, 0, "Silense",PeriodSilense,288,1,3); //Alert("Time[0]=",TimeToStr(Time[0]-60*2*Period(),TIME_MINUTES)," m20) { for(k = MathRound(MaxSL/20); k < MaxSL/2; k++) { r0=k; isChannel=false; a=0.0; b=0.0; c=0.0; sumx=0.0; sumy=0.0; sumxy=0.0; sumx2=0.0; h=0.0; l=0.0; //считаем канал линейной регрессии от i+Nlin до i for(j=2; j= 0; i--) { //у нас уже есть канал, ждём, пока его пробьёт double up0=a0*(i-loopbeg+2)+b0+range0; double dn0=a0*(i-loopbeg+2)+b0-range0; B3[i]=up0; B4[i]=dn0; if(up0>0 && iTime(NULL,0,i)up0) { Up[i]=NormalizeDouble(Open[i],Digits); Stop[i]=NormalizeDouble(Open[i]-(up0-dn0),Digits); Target[i]=NormalizeDouble(Open[i]+(up0-dn0)*t0,Digits); isChannel=false; if(range0>0) Comment(StTime,"-",FinTime," TP=",(Target[i]-Up[i])/Point,", SL=",(Up[i]-Stop[i])/Point); break; } //вниз if (Open[i]0) Comment(StTime,"-",FinTime," TP=",(Dn[i]-Target[i])/Point,", SL=",(Stop[i]-Dn[i])/Point); break; } //continue; } } return(0); } //+------------------------------------------------------------------+ void Fun_New_Bar() // Ф-ия обнаружения нового бара { New_Bar=false; // Нового бара нет if(New_Time!=Time[0]) // Сравниваем время { New_Time=Time[0]; // Теперь время такое New_Bar=true; // Поймался новый бар } }