zz_mtf_MZZ4

Download script
zz_mtf_MZZ4

This script is a sophisticated technical analysis tool designed to display multiple "ZigZag" indicators on a single trading chart simultaneously. In trading, a ZigZag indicator is used to filter out small price fluctuations and highlight the significant upward and downward swings of a market trend.

Core Functionality

The primary purpose of this script is to render four independent ZigZag lines at once. Each line can be configured with its own unique settings, allowing users to visualize different layers of market structure—such as long-term trends alongside short-term price action—on the same screen.

Key Features and Logic

  • Multi-Timeframe Analysis: One of the script's most advanced features is its ability to calculate ZigZag data from different timeframes (e.g., 15-minute, 1-hour, 4-hour, or daily charts) while displaying them on your current active chart. It automatically handles the conversion between these periods to ensure the data aligns correctly with your visual view.
  • Customizable Parameters: For each of the four ZigZag lines, you can independently set:
    • Depth and Deviation: These determine how "sensitive" the line is. Higher values mean the line will only move when there is a significant price change; lower values make the line more reactive to smaller moves.
    • Backstep: This controls the minimum number of bars between peaks and troughs, helping to smooth out the lines and prevent unnecessary jaggedness.
    • Max Bar Limit: You can restrict how far back in history the script looks to calculate the data for each specific line.
  • Dynamic Sorting: The script includes a "Procedure of Payments" logic. This allows the user to decide whether the indicators are processed and displayed in chronological order (oldest to newest) or reverse chronological order.
  • Real-Time Recalculation: The script is designed to be efficient. It includes logic to distinguish between historical data (which is calculated once) and real-time data. It can be configured to recalculate only a specific number of recent "extremums" (peaks and valleys) as new price data arrives, ensuring the chart remains responsive without overloading your computer's processing power.
  • Automated Buffer Management: Behind the scenes, the script manages complex memory buffers for each indicator. It automatically resizes and organizes these buffers to accommodate the specific requirements of different timeframes, ensuring that the lines remain accurate even when switching between various types of price data.

Summary for the User

Essentially, this tool acts as a "multi-lens" view for your charts. Instead of having to switch back and forth between different timeframes to see the bigger picture, this script pulls that information into one window. It allows you to see the "macro" trend (like a daily swing) and the "micro" trend (like a 15-minute move) simultaneously, helping you identify where larger trends might be shifting or confirming.

Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
zz_mtf_MZZ4
//+------------------------------------------------------------------+
//|                        MultiZigZag                     MZZ4.mq4  |
//+------------------------------------------------------------------+
/*

  08 ìàðòà 2009 ã.


Âíåøíèå ïàðàìåòðû - ñòðîêîâûå ïåðåìåííûå. 
 êàæäóþ ïåðåìåííóþ çàïèñûâàþòñÿ ïàðàìåòðû äëÿ ÷åòûðåõ çèãçàãîâ. 
Ïåðâàÿ öèôðà - äëÿ ïåðâîãî çèãçàãà, âòîðàÿ - äëÿ âòîðîãî, òðåòüÿ - äëÿ òðåòüåãî, ÷åòâåðòàÿ - äëÿ ÷åòâåðòîãî. ×åðåç çàïÿòóþ.

È âûâîäèòñÿ ÷åòûðå çèãçàãà. 

ExtDepth, ExtDeviation è ExtBackstep - ñòàíäàðòíûå ïàðàìåòðû äëÿ çèãçàãà.
Åñëè çàäàòü ExtDepth=0, òî ñîîòâåòñòâóþùèé çèãçàã âûâîäèòüñÿ íå áóäåò.
ExtMaxBar - êîëè÷åñòâî áàðîâ, íà êîòîðûõ ðàññ÷èòûâàåòñÿ çèãçàã.
GrossPeriod - ïåðèîäû ãðàôèêîâ, âûðàæåííûå â ìèíóòàõ, ïî äàííûì ñ êîòîðûõ ñòðîèòñÿ çèãçàã. Ïðè çàïèñè 0 çèãçàã âûâîäèòñÿ íà òåêóùåì òàéìôðåéìå.

ExtProcedureOfPayments - ïîñëåäîâàòåëüíîñòü ðàññ÷åòà çèãçàãîâ: true - â ïîðÿäêå âîçðàñòàíèÿ òàéìôðåéìà, false - â ïîðÿäêå óáûâàíèÿ.

ExtReCalculate - êîëè÷åñòâî ýêñòðåìóìîâ çèãçàãà, íà÷èíàÿ ñ 0, ïåðåñ÷èòûâàåìûõ â ðåæèìå ðåàëüíîãî âðåìåíè. Ïðèìåíÿåòñÿ äëÿ çèãçàãîâ ñî ñòàðøèõ òàéìôðåéìîâ.

ExtComplect - ó íåñêîëüêèõ èíäèêàòîðîâ, çàïóùåííûõ  íà îäíîé âàëþòíîé ïàðå â îäíîì îêíå äîëæíû áûòü ðàçíûå çíà÷åíèÿ ýòîãî ïàðàìåòðà
*/

#property link   "nen"

//  Îòðèñîâêà èíäèêàòîðà â îñíîâíîì îêíå
#property indicator_chart_window
//  Êîëè÷åñòâî èíäèêàòîðíûõ áóôôåðîâ
#property indicator_buffers  8
//  Öâåò èíäèêàòîðà
#property indicator_color1 Aqua
//#property indicator_color2 Aqua
#property indicator_color3 Red
//#property indicator_color4 Aqua
#property indicator_color5 Yellow
//#property indicator_color6 Aqua
#property indicator_color7 Magenta
//#property indicator_color6 Aqua
//  Òîëùèíà èíäèêàòîðíîé ëèíèè
#property indicator_width1 0
#property indicator_width2 0
#property indicator_width3 0
#property indicator_width4 0
#property indicator_width5 0
#property indicator_width6 0
#property indicator_width7 0
#property indicator_width8 0
//  Ñòèëü  èíäèêàòîðíîé ëèíèè
#property indicator_style1 0
#property indicator_style2 0
#property indicator_style3 0
#property indicator_style4 0
#property indicator_style5 0
#property indicator_style6 0
#property indicator_style7 0
#property indicator_style8 0
//  ÂÕÎÄÍÛÅ ÏÀÐÀÌÅÒÐÛ ÈÍÄÈÊÀÒÎÐÀ 
/*
// ïàðàìåòðû êàê â èíäèêàòîðå òðåõóðîâíåâûé ñåìàôîð
//---
extern string ExtDepth     = "14,28,102";
extern string ExtDeviation = "1,8,21";
extern string ExtBackstep  = "3,5,12";
//---
*/
/*
extern string ExtMaxBar    = "1000,1000,1000";    // Êîëè÷åñòâî îáñ÷èòûâàåìûõ áàðîâ (0-âñå)
extern string GrossPeriod  = "0,0,0";     // Òàéìôðåéìû, íà êîòîðûõ ðàññ÷èòûâàþòñÿ çèãçàãè, 0 - òåêóùèé òàéìôðåéì
*/
//extern string ExtDepth     = "12,0,0,0"; // îòëàäî÷íàÿ ïîñëåäîâàòåëüíîñòü
extern string ExtDepth     = "12,12,12,12";
extern string ExtDeviation = "5,5,5,5";
extern string ExtBackstep  = "3,3,3,3";
extern string ExtMaxBar    = "5000,1000,350,150";    // Êîëè÷åñòâî îáñ÷èòûâàåìûõ áàðîâ (0-âñå)
extern string GrossPeriod  = "15,60,240,1440";     // Òàéìôðåéìû, íà êîòîðûõ ðàññ÷èòûâàþòñÿ çèãçàãè, 0 - òåêóùèé òàéìôðåéì
extern bool   ExtProcedureOfPayments = false;
extern int    ExtReCalculate  = 3;              // Êîëè÷åñòâî ýêñòðåìóìîâ çèãçàãà ñòàðøåãî òàéìôðåéìà, íà÷èíàÿ ñ 0, ïåðåñ÷èòûâàåìûõ
                                                // â ðåæèìå ðåàëüíîãî âðåìåíè
extern int    ExtComplect  = 0;

int ExtDepth_[]={0,0,0,0}, ExtDeviation_[]={0,0,0,0}, ExtBackstep_[]={0,0,0,0}, ExtMaxBar_[]={0,0,0,0}, GrossPeriod_[]={0,0,0,0};

//  Èíäèêàòîðíûå áóôåðû
double LowestBuffer1[],HighestBuffer1[],LowestBuffer2[],HighestBuffer2[],LowestBuffer3[],HighestBuffer3[],LowestBuffer4[],HighestBuffer4[];
//  Âñïîìîãàòåëüíûå áóôåðû
double LowestBufferGross1[],HighestBufferGross1[],LowestBufferGross2[],HighestBufferGross2[],LowestBufferGross3[],HighestBufferGross3[],LowestBufferGross4[],HighestBufferGross4[];
datetime time2[]={0,0,0,0};
//  Ôëàãè, ïîêàçûâàþùèå, ÷òî ñî ñòàðøåãî òô ïåðâîíà÷àëüíîå ïðåîáðàçîâàíèå çèãçàãà ïðîèçâåäåíî
bool Grosstf_DT[]={false, false, false, false};
//  Ôëàãè, ïîêàçûâàþùèå, ÷òî íà èñòîðèè çèãçàã ïîñòðîåí
bool ZZ_tf[]={false, false, false, false};
//  Çíà÷åíèå âðåìåíè íà÷àëà è êîíöà òðåòüåãî ëó÷à
datetime L2LTime[]={0,0,0,0},L2HTime[]={0,0,0,0};
//  Ïðè âûõîäå çà çíà÷åíèÿ ïåðåìåííûõ lBar, hBar è tiZZ ïðîèçâîäèòñÿ ðàñ÷åò çèãçàãà
//  Òî åñòü òîëüêî ïðè âûõîäå çà ïðåäåëû óæå ïîñ÷èòàííîãî áàðà ïðîèçâîäèòñÿ ðàñ÷åò. 
//  Ýòî ïîçâîëÿåò ðàññ÷èòûâàòü íå íà êàæäîì òèêå.
double lBar[]={0,0,0,0}, hBar[]={0,0,0,0};
datetime tiZZ[]={0,0,0,0};
//  Ìàññèâ äëÿ õðàíåíèÿ çíà÷åíèé Bars
int saveBars[]={0,0,0,0};
int currentBars;
// Ìàññèâ äëÿ õðàíåíèÿ ïîðÿäêà ðàññ÷åòà çèãçàãîâ. Êàêîé çèãçàã çà êàêèì ðàññ÷èòûâàåòñÿ.
int ProcedureOfPayments[4][2];
//  Ïåðåìåííàÿ, õðàíÿùàÿ êîëè÷åñòâî áàðîâ, íà êîòîðûõ ðàññ÷èòûâàåòñÿ çèãçàã
int limit;

//+------------------------------------------------------------------+
//| Initialization function. Íà÷àëî.                                 |
//+------------------------------------------------------------------+
int init()
  {
   int i,j,m;

// Ïî äâà èíäèêàòîðíûõ áóôôåðà èñïîëüçîâàíî äëÿ ñ÷¸òà êàæäîãî çèãçàãà
   SetIndexBuffer(0,LowestBuffer1);
   SetIndexBuffer(1,HighestBuffer1);
   SetIndexBuffer(2,LowestBuffer2);
   SetIndexBuffer(3,HighestBuffer2);
   SetIndexBuffer(4,LowestBuffer3);
   SetIndexBuffer(5,HighestBuffer3);
   SetIndexBuffer(6,LowestBuffer4);
   SetIndexBuffer(7,HighestBuffer4);
// Ñòèëü èñïîëíåíèÿ ãðàôèêà â âèäå ëîìàíîé ZigZag 
   SetIndexStyle(0,DRAW_ZIGZAG);
   SetIndexStyle(1,DRAW_ZIGZAG);
   SetIndexStyle(2,DRAW_ZIGZAG);
   SetIndexStyle(3,DRAW_ZIGZAG);
   SetIndexStyle(4,DRAW_ZIGZAG);
   SetIndexStyle(5,DRAW_ZIGZAG);
   SetIndexStyle(6,DRAW_ZIGZAG);
   SetIndexStyle(7,DRAW_ZIGZAG);
// Óñòàíîâêà çíà÷åíèé èíäèêàòîðà, êîòîðûå íå áóäóò âèäèìû íà ãðàôèêå
   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,"Low1" );
   SetIndexLabel(1,"High1");
   SetIndexLabel(2,"Low2" );
   SetIndexLabel(3,"High2");
   SetIndexLabel(4,"Low3" );
   SetIndexLabel(5,"High3");
   SetIndexLabel(6,"Low4" );
   SetIndexLabel(7,"High4");

   _stringtointarray (ExtDepth, ExtDepth_, 4);
   _stringtointarray (ExtDeviation, ExtDeviation_, 4);
   _stringtointarray (ExtBackstep, ExtBackstep_, 4);
   _stringtointarray (ExtMaxBar, ExtMaxBar_, 4);
   _stringtointarray (GrossPeriod, GrossPeriod_, 4);

   for (i=0;i<4;i++)
     {
      Grosstf_DT[i]=false; ZZ_tf[i]=false;
      j=GrossPeriod_[i];
      GrossPeriod_[i]=_period(i,j);
//      if (ExtDepth_[i]>=ExtBackstep_[i]) m=ExtDepth_[i]; else m=ExtBackstep_[i];
      m=ExtBackstep_[i]+ExtDepth_[i];
      if ((ExtMaxBar_[i]>iBars(NULL,GrossPeriod_[i])-m) || (ExtMaxBar_[i]==0)) limit=iBars(NULL,GrossPeriod_[i])- m; else limit=ExtMaxBar_[i];

      if (i==0)
        {
         arr_resize(LowestBufferGross1, HighestBufferGross1, limit+m, i);
        }
      else if (i==1)
        {
         arr_resize(LowestBufferGross2, HighestBufferGross2, limit+m, i);
        }
      else if (i==2)
        {
         arr_resize(LowestBufferGross3, HighestBufferGross3, limit+m, i);
        }
      else if (i==3)
        {
         arr_resize(LowestBufferGross4, HighestBufferGross4, limit+m, i);
        }
     }

   for (i=0;i<4;i++)
     {
      ProcedureOfPayments[i][1]=i; ProcedureOfPayments[i][0]=GrossPeriod_[i];
     }

   if (ExtProcedureOfPayments) ArraySort(ProcedureOfPayments,WHOLE_ARRAY,0,MODE_ASCEND); else ArraySort(ProcedureOfPayments,WHOLE_ARRAY,0,MODE_DESCEND);

   currentBars=0;
// Çàâåðøåíèå èíèöèàëèçàöèè

   return(0);
  }
//+------------------------------------------------------------------+
//| Initialization function. Êîíåö.                                  |
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//| Custom indicator deinitialization function. Íà÷àëî.              |
//+------------------------------------------------------------------+
int deinit()
  {
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function. Êîíåö.               |
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//| Ðàñ÷åò èíäèêàòîðà. Íà÷àëî.                                       |
//+------------------------------------------------------------------+
int start()
  {
   int i, j, k, m, n;
   bool calculate;

   if (Bars-currentBars+1>2)
     {
      for (i=0;i<4;i++)
        {
         saveBars[i]=0;
        }
     }

   currentBars=Bars;

   for (n=0;n<4;n++)
     {
      i=ProcedureOfPayments[n][1];
      // ïðîâåðêè äëÿ êîððåêòíîãî ðàñ÷¸òà èíäèêàòîðà
      if (ExtDepth_[i]==0) continue;
      m=ExtBackstep_[i]+ExtDepth_[i];
      if ((iBars(NULL,GrossPeriod_[i])-1<m) || (m<=0)) continue;

      calculate=false;

      limit=iBars(NULL,GrossPeriod_[i])-saveBars[i]+1;

      if (limit>2)
        {
         calculate=true;
         Grosstf_DT[i]=false;
         ZZ_tf[i]=false;

         if ((ExtMaxBar_[i]>iBars(NULL,GrossPeriod_[i])-m) || (ExtMaxBar_[i]==0)) limit=iBars(NULL,GrossPeriod_[i])- m; else limit=ExtMaxBar_[i];

         if (i==0)
           {
            arr_resize(LowestBufferGross1, HighestBufferGross1, limit+m, i);

            ArrayInitialize(LowestBuffer1,0); ArrayInitialize(HighestBuffer1,0);
           }
         else if (i==1)
           {
            arr_resize(LowestBufferGross2, HighestBufferGross2, limit+m, i);

            ArrayInitialize(LowestBuffer2,0); ArrayInitialize(HighestBuffer2,0); 
           }
         else if (i==2)
           {
            arr_resize(LowestBufferGross3, HighestBufferGross3, limit+m, i);

            ArrayInitialize(LowestBuffer3,0); ArrayInitialize(HighestBuffer3,0); 
          }
         else if (i==3)
           {
            arr_resize(LowestBufferGross4, HighestBufferGross4, limit+m, i);

            ArrayInitialize(LowestBuffer4,0); ArrayInitialize(HighestBuffer4,0); 
          }

        }
      else
        {
         if (lBar[i]>iLow(NULL,GrossPeriod_[i],0) || hBar[i]<iHigh(NULL,GrossPeriod_[i],0) || tiZZ[i]!=iTime(NULL,GrossPeriod_[i],0))
           {
            calculate=true;
           }
        }

      if (calculate)
        {
         switch (i)
           {
            case 0:
              {
               if (GrossPeriod_[i]==0)
                 {
                  ZigZag_(LowestBuffer1, HighestBuffer1, i);
                 }
               else
                 {
                  if (limit==2) Shift_elements(LowestBufferGross1,HighestBufferGross1);

                  if (ZigZag_(LowestBufferGross1, HighestBufferGross1, i)==0)
                    {
                     ZigZagDT (LowestBuffer1, HighestBuffer1, LowestBufferGross1, HighestBufferGross1, i);
                    }
                 }

               break;
              }
            case 1:
              {
               if (GrossPeriod_[i]==0)
                 {
                  ZigZag_(LowestBuffer2, HighestBuffer2, i);
                 }
               else
                 {
                  if (limit==2) Shift_elements(LowestBufferGross2,HighestBufferGross2);

                  if (ZigZag_(LowestBufferGross2, HighestBufferGross2, i)==0)
                    {
                     ZigZagDT (LowestBuffer2, HighestBuffer2, LowestBufferGross2, HighestBufferGross2, i);
                    }
                 }

               break;
              }
            case 2:
              {
               if (GrossPeriod_[i]==0)
                 {
                  ZigZag_(LowestBuffer3, HighestBuffer3, i);
                 }
               else
                 {
                  if (limit==2) Shift_elements(LowestBufferGross3,HighestBufferGross3);

                  if (ZigZag_(LowestBufferGross3, HighestBufferGross3, i)==0)
                    {
                     ZigZagDT (LowestBuffer3, HighestBuffer3, LowestBufferGross3, HighestBufferGross3, i);
                    }
                 }

               break;
              }
            case 3:
              {
               if (GrossPeriod_[i]==0)
                 {
                  ZigZag_(LowestBuffer4, HighestBuffer4, i);
                 }
               else
                 {
                  if (limit==2) Shift_elements(LowestBufferGross4,HighestBufferGross4);

                  if (ZigZag_(LowestBufferGross4, HighestBufferGross4, i)==0)
                    {
                     ZigZagDT (LowestBuffer4, HighestBuffer4, LowestBufferGross4, HighestBufferGross4, i);
                    }
                 }

               break;
              }
           }

        }

     }

 // Çàâåðøåíèå âû÷èñëåíèé èíäèêàòîðà
   return(0);
  }
//+------------------------------------------------------------------+
//| Ðàñ÷åò èíäèêàòîðà. Êîíåö.                                        |
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|               Ïîäïðîãðàììû è ôóíêöèè                             |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//|  Îñíîâíîé ZigZag. Íà÷àëî.                                        |
//+------------------------------------------------------------------+

int ZigZag_(double& LB[],double& HB[],int x)
  {
   int j,jl,jh,bar_l,bar_h, limit1, maxbar_;

   int    bar,back,lasthighpos=-1,lastlowpos=-1;
   double curlow,curhigh,lasthigh,lastlow,val;


   if (ZZ_tf[x]) // Ðåæèì ðåàëüíîãî âðåìåíè.
     {
      // Îïðåäåëåíèå áàðà, ñ êîòîðîãî íà÷èíàåòñÿ ðàñ÷åò
      bar_l=iBarShift(NULL,GrossPeriod_[x],L2LTime[x],true);
      bar_h=iBarShift(NULL,GrossPeriod_[x],L2HTime[x],true);

      if ((bar_l<0) || (bar_h<0)) {saveBars[x]=0; return (-1);}
      if (L2LTime[x]<=L2HTime[x]) limit=bar_l; else limit=bar_h;

      limit1=limit-1;

      // Âîññòàíîâëåíèå ïåðåìåííûõ
      lastlow=iLow(NULL,GrossPeriod_[x],bar_l);
      lasthigh=iHigh(NULL,GrossPeriod_[x],bar_h);

     }
   else // Ïîñòðîåíèå çèãçàãà íà èñòîðèè.
     {
      ZZ_tf[x]=true;
      bar_l=limit;
      bar_h=limit;

      limit1=limit;
     }

   // Íà÷àëî ïåðâîãî áîëüøîãî öèêëà
   for(bar=limit1; bar>=0; bar--)
     {
      //--- low
      if (bar<bar_l)
        {
         j=iLowest(NULL,GrossPeriod_[x],MODE_LOW,ExtDepth_[x],bar);
         val=iLow(NULL,GrossPeriod_[x],j);

         if(val==lastlow) val=0.0;
         else 
           { 
            lastlow=val; 
            if((iLow(NULL,GrossPeriod_[x],bar)-val)>(ExtDeviation_[x]*Point))val=0.0;
            else
              {
               for(back=1; back<=ExtBackstep_[x]; back++)
                 {
                  if(val<LB[j+back])LB[j+back]=0.0; 
                 }
              }
           } 

         if (j==bar) LB[j]=val;
        }

      //--- high
      if (bar<bar_h)
        {
         j=iHighest(NULL,GrossPeriod_[x],MODE_HIGH,ExtDepth_[x],bar);
         val=iHigh(NULL,GrossPeriod_[x],j);

         if(val==lasthigh) val=0.0;
         else 
           {
            lasthigh=val;
            if((val-iHigh(NULL,GrossPeriod_[x],bar))>(ExtDeviation_[x]*Point))val=0.0;
            else
              {
               for(back=1; back<=ExtBackstep_[x]; back++)
                 {
                  if(val>HB[j+back])HB[j+back]=0.0; 
                 } 
              }
           }

         if (j==bar) HB[j]=val;
        }
     }
   // Êîíåö ïåðâîãî áîëüøîãî öèêëà

   // Íà÷àëî âòîðîãî áîëüøîãî öèêëà
   lasthigh=-1; lastlow=-1;

   for(bar=limit; bar>=0; bar--)
     {
      curlow=LB[bar];
      curhigh=HB[bar];

      if((curlow==0)&&(curhigh==0)) continue;

      if(curhigh!=0)
        {
         if(lasthigh>0) 
           {
            if(lasthigh<curhigh) HB[lasthighpos]=0;
            else HB[bar]=0;
           }

         if(lasthigh<curhigh || lasthigh<0)
           {
            lasthigh=curhigh;
            lasthighpos=bar;
           }
         lastlow=-1;
        }

      if(curlow!=0)
        {
         if(lastlow>0)
           {
            if(lastlow>curlow) LB[lastlowpos]=0;
            else LB[bar]=0;
           }

         if((curlow<lastlow)||(lastlow<0))
           {
            lastlow=curlow;
            lastlowpos=bar;
           } 
         lasthigh=-1;
        }
     } 
   // Êîíåö âòîðîãî áîëüøîãî öèêëà

   // Îáíîâëåíèå ïåðåìåííûõ
   saveBars[x]=iBars(NULL,GrossPeriod_[x]);
   lBar[x]=iLow(NULL,GrossPeriod_[x],0); hBar[x]=iHigh(NULL,GrossPeriod_[x],0); tiZZ[x]=iTime(NULL,GrossPeriod_[x],0);

   // Ñîõðàíåíèå âðåìåíè íà÷àëà è îêîí÷àíèÿ òðåòüåãî ëó÷à èëè ïîñëåäíåãî ëó÷à, ìåíüøå òðåòüåãî
   jl=0;jh=0;
   for (bar=0;bar<saveBars[x];bar++)
     {
      if (LB[bar]>0) {if (jl<=1) {L2LTime[x]=iTime(NULL,GrossPeriod_[x],bar);} jl++;}
      if (HB[bar]>0) {if (jh<=1) {L2HTime[x]=iTime(NULL,GrossPeriod_[x],bar);} jh++;}
      if (jl>1 && jh>1) break;
     }

   return(0);
  }
//+------------------------------------------------------------------+
//|  Îñíîâíîé ZigZag. Êîíåö.                                         |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Ïðåîáðàçîâàíèå çèãçàãà ñî ñòàðøåãî òàéìôðåéìà íà òåêóùèé. Íà÷àëî.|
//+------------------------------------------------------------------+
int ZigZagDT (double& LB[], double& HB[], double& LBG[], double& HBG[], int x)
  {
   int i=0, j, jl, jh, ext3=0, end;
   double el=-1, eh=-1;
   datetime t1;

   if (Grosstf_DT[x]) // Ðåæèì ðåàëüíîãî âðåìåíè.
     {
      end=ExtReCalculate+1;

      t1=iTime(NULL, GrossPeriod_[x],i);
      for (j=0;ext3<end && j<Bars;j++)
        {
         if (Time[j]<t1) {i++; t1=iTime(NULL, GrossPeriod_[x],i);}

         LB[j]=0;
         HB[j]=0;
         if (LBG[i]>0)
           {
            if (el>=Low[j] || el<0) {el=Low[j]; jl=j;}
           }
         else
           {
            if (el>0) {LB[jl]=el; el=-1; ext3++;}
           }

         if  (HBG[i]>0)
           {
            if (eh<=High[j]) {eh=High[j]; jh=j;}
           }
         else
           {
            if (eh>0) {HB[jh]=eh; eh=-1; ext3++;}
           } 

        }
     }
   else // Ïîñòðîåíèå çèãçàãà íà èñòîðèè.
     {
      if (limit<=ExtDepth_[x]+ExtBackstep_[x]) {saveBars[x]=0; return (-1);}
      end=iBarShift(NULL,Period(),iTime(NULL, GrossPeriod_[x],limit),false);

      if (end<=0) {saveBars[x]=0; return (-1);}

      Grosstf_DT[x]=true;

      t1=iTime(NULL, GrossPeriod_[x],i);
      for (j=0;j<end;j++)
        {
         if (Time[j]<t1) {i++; t1=iTime(NULL, GrossPeriod_[x],i);}

         if (LBG[i]>0)
           {
            if (el>=Low[j] || el<0) {el=Low[j]; jl=j;}
           }
         else
           {
            if (el>0) {LB[jl]=el; el=-1;}
           }

         if  (HBG[i]>0)
           {
            if (eh<=High[j]) {eh=High[j]; jh=j;}
           }
         else
           {
            if (eh>0) {HB[jh]=eh; eh=-1;}
           } 
        }
     }

   return (0);
  }
//+------------------------------------------------------------------+
//| Ïðåîáðàçîâàíèå çèãçàãà ñî ñòàðøåãî òàéìôðåéìà íà òåêóùèé. Êîíåö. |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Ïðîâåðêà êîððåêòíîñòè çàäàíèÿ òàéìôðåéìà. Íà÷àëî.                |
//+------------------------------------------------------------------+
int _period(int x, int tf)
  {
   if (tf<Period() && tf>0) {ExtDepth_[x]=0; return (tf);}
   if (tf==Period()) return (0);

   switch (tf)
     {
      case 0     : {return (0);}
      case 1     : {return (1);}
      case 5     : {return (5);}
      case 15    : {return (15);}
      case 30    : {return (30);}
      case 60    : {return (60);}
      case 240   : {return (240);}
      case 1440  : {return (1440);}
      case 10080 : {return (10080);}
      case 43200 : {return (43200);}
      default    : {ExtDepth_[x]=0; return (tf);}
     }
  }
//+------------------------------------------------------------------+
//| Ïðîâåðêà êîððåêòíîñòè çàäàíèÿ òàéìôðåéìà. Êîíåö.                 |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Ñäâèã ýëåìåíòîâ ìàññèâà íà 1 îò 0 ýëåìåíòà â ñòîðîíó óâåëè÷åíèÿ  |
//| èíäåêñà. Íà÷àëî.                                                 |
//+------------------------------------------------------------------+
void Shift_elements (double& arr[], double& arr1[])
  {
   int i,j;

   j=ArraySize(arr)-1;
   for (i=j;i>0;i--)
     {
      arr[i]=arr[i-1];
      arr1[i]=arr1[i-1];
     }
   arr[0]=0;
   arr1[0]=0;
  }
//-------------------------------------------------------------------+
//| Ñäâèã ýëåìåíòîâ ìàññèâà íà 1 îò 0 ýëåìåíòà â ñòîðîíó óâåëè÷åíèÿ  |
//| èíäåêñà. Êîíåö.                                                  |
//-------------------------------------------------------------------+


//+------------------------------------------------------------------+
//| Èçìåíåíèå ðàçìåðà ìàññèâîâ è ïðèñâîåíèå âñåì ýëåìåíòàì çíà÷åíèÿ 0|
//| Íà÷àëî.                                                          |
//+------------------------------------------------------------------+
void arr_resize (double& arr[], double& arr1[], int size, int x)
  {
   if (GrossPeriod_[x]>0)
     {
      ArrayResize(arr,size); ArrayResize(arr1,size);
      ArrayInitialize(arr,0); ArrayInitialize(arr1,0);
     }
  }
//+------------------------------------------------------------------+
//| Èçìåíåíèå ðàçìåðà ìàññèâîâ è ïðèñâîåíèå âñåì ýëåìåíòàì çíà÷åíèÿ 0|
//| Êîíåö.                                                           |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Ïåðåíîñ çíà÷åíèé ïàðàìåòðîâ èç ñòðîêè â ÷èñëîâîé ìàññèâ. Íà÷àëî. |
//+------------------------------------------------------------------+
void _stringtointarray (string str, int& arr[], int x)
  {
   int i,j,k=0;
   for (i=0;i<x;i++)
     {
      j=StringFind(str,",",k);
      if (j<0) {arr[i]=StrToInteger(StringSubstr(str,k)); break;}
      arr[i]=StrToInteger(StringSubstr(str,k,j-k));
      k=j+1;
     }
  }
//+------------------------------------------------------------------+
//| Ïåðåíîñ çíà÷åíèé ïàðàìåòðîâ èç ñòðîêè â ÷èñëîâîé ìàññèâ.Êîíåö.   |
//+------------------------------------------------------------------+

Comments