#property version "2.0" #property strict //---- #property indicator_chart_window #property indicator_buffers 12 #property indicator_color1 Lime #property indicator_width1 1 #property indicator_color2 Red #property indicator_width2 1 //входные переменные bool ShowChannel = true; //Отображать канал bool ShowZigZag = false; //Отображать будущее движение цены bool ShowChannelTF = true; //Отображать канал со старшего таймфрейма bool ShowZigZagTF = false; //Отображать будущее движение цены старшего таймфрейма input ENUM_TIMEFRAMES PeriodTF = PERIOD_M30; //Period TF input color ChannelColor = clrGray; //Channel Color color TriangleColor = clrRed; //Цвет движения input color ChannelColorTF = clrGold; //Color TF Channel color TriangleColorTF = clrBlue; //Цвет движения старшего таймфрейма //Параметры индикатора ZigZag int ExtDepth=12; int ExtDeviation=5; int ExtBackstep=3; bool Second = true; //---- indicator buffers double ExtMapBuffer[]; double ExtMapBuffer2[]; string prefix = "Channel", ind_name = "AcChannelMTF2"; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { IndicatorBuffers(2); //---- drawing settings //SetIndexStyle(0,DRAW_ARROW); SetIndexStyle(0,DRAW_NONE); SetIndexArrow(0, 233); //SetIndexStyle(1,DRAW_ARROW); SetIndexStyle(1,DRAW_NONE); SetIndexArrow(1, 234); //---- indicator buffers mapping SetIndexBuffer(0,ExtMapBuffer); SetIndexBuffer(1,ExtMapBuffer2); SetIndexEmptyValue(0,0.0); //---- indicator short name IndicatorShortName("ZigZag("+IntegerToString(ExtDepth)+","+IntegerToString(ExtDeviation)+","+IntegerToString(ExtBackstep)+")"); //---- initialization done return(0); } void OnDeinit(const int reason){ //удалить все объекты с префиксом канала ObjectsDeleteAll(0, prefix); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { int shift, back,lasthighpos,lastlowpos; double val,res; double curlow,curhigh,lasthigh=0,lastlow=0; //---- for(shift=Bars-ExtDepth; shift>=0; shift--) { val=Low[Lowest(NULL,0,MODE_LOW,ExtDepth,shift)]; if(val==lastlow) val=0.0; else { lastlow=val; if((Low[shift]-val)>(ExtDeviation*Point)) val=0.0; else { for(back=1; back<=ExtBackstep; back++) { res=ExtMapBuffer[shift+back]; if((res!=0)&&(res>val)) ExtMapBuffer[shift+back]=0.0; } } } ExtMapBuffer[shift]=val; //--- high val=High[Highest(NULL,0,MODE_HIGH,ExtDepth,shift)]; if(val==lasthigh) val=0.0; else { lasthigh=val; if((val-High[shift])>(ExtDeviation*Point)) val=0.0; else { for(back=1; back<=ExtBackstep; back++) { res=ExtMapBuffer2[shift+back]; if((res!=0)&&(res=0; shift--) { curlow=ExtMapBuffer[shift]; curhigh=ExtMapBuffer2[shift]; if((curlow==0)&&(curhigh==0)) continue; //--- if(curhigh!=0) { if(lasthigh>0) { if(lasthigh0) { if(lastlow>curlow) ExtMapBuffer[lastlowpos]=0; else ExtMapBuffer[shift]=0; } //--- if((curlow=0; shift--) { if(shift>=Bars-ExtDepth) ExtMapBuffer[shift]=0.0; else { res=ExtMapBuffer2[shift]; if(res!=0.0) ExtMapBuffer2[shift]=res; } } if (Second) DrawChennels(); return(0); } //+------------------------------------------------------------------+ //+--------------------------------------------+ //| Рисует каналы и движения | //+--------------------------------------------+ void DrawChennels(){ //ObjectsDeleteAll(0, prefix); DrawChennel(Period(), ShowZigZag, ShowChannel, ChannelColor, TriangleColor); if (Period() < PeriodTF){ DrawChennel(PeriodTF, ShowZigZagTF, ShowChannelTF, ChannelColorTF, TriangleColorTF); } } //+--------------------------------------------+ //| Возвращает номер позиции в буфере сигнала | //+--------------------------------------------+ //up = true - сигнал вверх, иначе - вниз; num - номер сигнала по порядку int GetLastNum(bool up, int num, int period){ int result = -1, i = 0, n = 0; if (up){ while ((i < 500) && (result < 0)){ if (period != Period()){ if (iCustom(NULL,period,ind_name,false,false,false,false,0,0,0,0,0,ExtDepth,ExtDeviation,ExtBackstep,false,0,i) != 0) n++; } else { if (ExtMapBuffer[i] != 0) n++; } if (n == num) result = i; i++; } }//if (up) else{ while ((i < 500) && (result < 0)){ if (period != Period()){ if (iCustom(NULL,period,ind_name,false,false,false,false,0,0,0,0,0,ExtDepth,ExtDeviation,ExtBackstep,false,1,i) != 0) n++; } else{ if (ExtMapBuffer2[i] != 0) n++; } if (n == num) result = i; i++; } }//else return(result); } //+------------------------------------------------------+ //| Рисование линии | //+------------------------------------------------------+ void DrawLine(string name, datetime x0, datetime x1, double y0, double y1, color clr, bool ray){ // #define WINDOW_MAIN 0 name = prefix + name; ObjectDelete(name); ObjectCreate (name, OBJ_TREND, 0, x0, y0, x1, y1); ObjectSet (name,OBJPROP_RAY,ray); ObjectSet (name, OBJPROP_COLOR, clr); ObjectSet (name,OBJPROP_WIDTH,1); } //+-------------------------------------------------------+ //| Рисует торговый канал предполагаемого движения цены | //+-------------------------------------------------------+ void DrawChennel(int period, bool zigzag, bool chennel, color channel, color triangle){ static int last_up1 = 0, last_down1 = 0; int up1, up2, down1, down2; datetime p0x, p1x, p2x, p3x, p4x; double p0y, p1y, p2y, p3y, p4y; //получить координаты последних 4-х сигналов up1 = GetLastNum(true, 1, period); down1 = GetLastNum(false, 1, period); if (up1 < down1){ up1 = GetLastNum(true, 2, period); up2 = GetLastNum(true, 3, period); down1 = GetLastNum(false, 1, period); down2 = GetLastNum(false, 2, period); }else if (up1 > down1){ up1 = GetLastNum(true, 1, period); up2 = GetLastNum(true, 2, period); down1 = GetLastNum(false, 2, period); down2 = GetLastNum(false, 3, period); }else{ up1 = GetLastNum(true, 2, period); down1 = GetLastNum(false, 2, period); if (up1 < down1){ up1 = GetLastNum(true, 2, period); up2 = GetLastNum(true, 3, period); down1 = GetLastNum(false, 1, period); down2 = GetLastNum(false, 2, period); }else{ up1 = GetLastNum(true, 1, period); up2 = GetLastNum(true, 2, period); down1 = GetLastNum(false, 2, period); down2 = GetLastNum(false, 3, period); }} /* up1 = GetLastNum(true, 1, period); up2 = GetLastNum(true, 2, period); down1 = GetLastNum(false, 1, period); down2 = GetLastNum(false, 2, period);*/ if (last_up1 != up1 || last_down1 != down1){ last_up1 = up1; last_down1 = down1; //рассчёт координат if (up1 < down1){ if (period != Period()){ p0x = iTime(NULL, period, up2); p1x = iTime(NULL, period, down1); p2x = iTime(NULL, period, up1); p0y = iCustom(NULL,period,ind_name,false,false,false,false,0,0,0,0,0,ExtDepth,ExtDeviation,ExtBackstep,false,0,up2); p1y = iCustom(NULL,period,ind_name,false,false,false,false,0,0,0,0,0,ExtDepth,ExtDeviation,ExtBackstep,false,1,down1); p2y = iCustom(NULL,period,ind_name,false,false,false,false,0,0,0,0,0,ExtDepth,ExtDeviation,ExtBackstep,false,0,up1); } else{ p0x = Time[up2]; p1x = Time[down1]; p2x = Time[up1]; p0y = ExtMapBuffer[up2]; p1y = ExtMapBuffer2[down1]; p2y = ExtMapBuffer[up1]; } p3x=nx(period,p1x,down1,up2-up1); p4x=nx(period,p2x,up1,up2-up1); } else { if (period != Period()){ p0x = iTime(NULL, period, down2); p1x = iTime(NULL, period, up1); p2x = iTime(NULL, period, down1); p0y = iCustom(NULL,period,ind_name,false,false,false,false,0,0,0,0,0,ExtDepth,ExtDeviation,ExtBackstep,false,1,down2); p1y = iCustom(NULL,period,ind_name,false,false,false,false,0,0,0,0,0,ExtDepth,ExtDeviation,ExtBackstep,false,0,up1); p2y = iCustom(NULL,period,ind_name,false,false,false,false,0,0,0,0,0,ExtDepth,ExtDeviation,ExtBackstep,false,1,down1); } else{ p0x = Time[down2]; p1x = Time[up1]; p2x = Time[down1]; p0y = ExtMapBuffer2[down2]; p1y = ExtMapBuffer[up1]; p2y = ExtMapBuffer2[down1]; } p3x=nx(period,p1x,up1,down2-down1); p4x=nx(period,p2x,down1,down2-down1); } //рассчёт координатъ p3y = p2y - (p0y-p1y); p4y = p2y - (p0y-p2y); //движение цены if (zigzag){ DrawLine(prefix+"Triangle1"+IntegerToString(period), p2x, p3x, p2y, p3y, triangle, false); DrawLine(prefix+"Triangle2"+IntegerToString(period), p3x, p4x, p3y, p4y, triangle, false); } //канал if (chennel){ DrawLine(prefix+"Channel1"+IntegerToString(period), p0x, p2x, p0y, p2y, channel, true); DrawLine(prefix+"Channel2"+IntegerToString(period), p1x, p3x, p1y, p3y, channel, true); } }//if (last_up1 != up1 || last_down1 != down1) } datetime nx(int period, datetime sx, int bx, int ax){ for(int i=1;i<=ax;i++)if (bx-i>=0)sx=iTime(NULL,period,bx-i);else sx+=period*60; return(sx); }