zz_MultiZigZag_20081103

Download script
zz_MultiZigZag_20081103

This MetaTrader MQL script is designed to render a MultiZigZag indicator on a price chart. Unlike a standard ZigZag which tracks a single set of price fluctuations, this tool allows for the simultaneous display of three different ZigZag patterns, each governed by its own independent settings and timeframes.

Here is a professional breakdown of the logic used in the script:

Core Functionality

The primary purpose of this script is to identify significant "peaks" (highs) and "troughs" (lows) in price action across three distinct layers. By providing different parameters for each layer, users can view market structure at multiple scales at once—for example, identifying long-term trends while simultaneously monitoring short-term volatility.

Key Logic Components

1. Multi-Layer Configuration The script handles three unique ZigZag instances. For each instance, the user can define:

  • Depth and Deviation: These determine how much the price must move to be considered a significant "turn."
  • Backstep: This controls the minimum number of bars between two consecutive highs or lows.
  • Timeframe Mapping: A unique feature of this script is its ability to calculate ZigZags for specific timeframes (e.g., 1-minute, 60-minute, or daily) and project them onto your current chart.

2. Real-Time Data Processing The logic includes a "Recalculation" mechanism. This ensures that as new price data arrives in real-time, the most recent peaks and troughs are updated accurately without requiring the user to manually refresh the chart. It specifically manages how many of the most recent extremes are constantly monitored for updates.

3. Data Transformation & Synchronization Because the script can pull data from different timeframes (like a 4-hour trend on a 15-minute chart), it contains internal logic to "transform" and "shift" these values. This ensures that the historical data from a higher timeframe aligns correctly with the current price candles on your active screen.

4. Memory & Performance Management To ensure the platform remains responsive, the script manages memory by:

  • Dynamically resizing arrays based on the maximum number of bars the user wishes to view.
  • Filtering out unnecessary calculations (e.g., if a specific timeframe is disabled or invalid).
  • Using specific "flags" to track whether historical data has already been processed, preventing redundant calculations.

Summary for the User

Essentially, this script acts as a sophisticated "trend visualizer." It looks at the history of the market, filters out minor price noise based on your custom rules, and draws three distinct lines representing different levels of price movement. This allows you to see "the big picture" and "the small details" simultaneously on a single screen.

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
10 Views
0 Downloads
0 Favorites
zz_MultiZigZag_20081103
//+------------------------------------------------------------------+
//|                        MultiZigZag                               |
//+------------------------------------------------------------------+
/*

  3 íîÿáðÿ 2008 ã.


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

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

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

*/

#property link   "nen"
//  Îòðèñîâêà èíäèêàòîðà â îñíîâíîì îêíå
#property indicator_chart_window
//  Êîëè÷åñòâî èíäèêàòîðíûõ áóôôåðîâ
#property indicator_buffers  6
//  Öâåò èíäèêàòîðà
#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_width1 0
#property indicator_width2 0
#property indicator_width3 0
#property indicator_width4 0
#property indicator_width5 0
#property indicator_width6 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
//  ÂÕÎÄÍÛÅ ÏÀÐÀÌÅÒÐÛ ÈÍÄÈÊÀÒÎÐÀ 
/*
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,12,12";
extern string ExtDeviation = "5,5,5";
extern string ExtBackstep  = "8,8,8";
extern string ExtMaxBar    = "1000,300,150";    // Êîëè÷åñòâî îáñ÷èòûâàåìûõ áàðîâ (0-âñå)
extern string GrossPeriod  = "60,240,1440";     // Òàéìôðåéìû, íà êîòîðûõ ðàññ÷èòûâàþòñÿ çèãçàãè, 0 - òåêóùèé òàéìôðåéì
extern int    ExtReCalculate  = 3;              // Êîëè÷åñòâî ýêñòðåìóìîâ çèãçàãà ñòàðøåãî òàéìôðåéìà, íà÷èíàÿ ñ 0, ïåðåñ÷èòûâàåìûõ
                                                // â ðåæèìå ðåàëüíîãî âðåìåíè

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

//  Èíäèêàòîðíûå áóôåðû
double LowestBuffer1[],HighestBuffer1[],LowestBuffer2[],HighestBuffer2[],LowestBuffer3[],HighestBuffer3[];
//  Âñïîìîãàòåëüíûå áóôåðû
double LowestBufferGross1[],HighestBufferGross1[],LowestBufferGross2[],HighestBufferGross2[],LowestBufferGross3[],HighestBufferGross3[];
datetime time2[]={0,0,0};
//  Ôëàãè, ïîêàçûâàþùèå, ÷òî ñî ñòàðøåãî òô ïåðâîíà÷àëüíîå ïðåîáðàçîâàíèå çèãçàãà ïðîèçâåäåíî
bool Grosstf_DT[]={false, false, false};
//  Ôëàãè, ïîêàçûâàþùèå, ÷òî íà èñòîðèè çèãçàã ïîñòðîåí
bool ZZ_tf[]={false, false, false};
//  Çíà÷åíèå âðåìåíè íà÷àëà è êîíöà âòîðîãî ëó÷à
datetime L2LTime[]={0,0,0},L2HTime[]={0,0,0};
//  Ïðè âûõîäå çà çíà÷åíèÿ ïåðåìåííûõ lBar, hBar è tiZZ ïðîèçâîäèòñÿ ðàñ÷åò çèãçàãà
//  Òî åñòü òîëüêî ïðè âûõîäå çà ïðåäåëû óæå ïîñ÷èòàííîãî áàðà ïðîèçâîäèòñÿ ðàñ÷åò. 
//  Ýòî ïîçâîëÿåò ðàññ÷èòûâàòü íå íà êàæäîì òèêå.
double lBar[]={0,0,0}, hBar[]={0,0,0};
datetime tiZZ[]={0,0,0};
//  Ïåðåìåííàÿ äëÿ õðàíåíèÿ çíà÷åíèÿ Bars
int saveBars[]={0,0,0};
int currentBars;
//  Ïåðåìåííàÿ, õðàíÿùàÿ êîëè÷åñòâî áàðîâ, íà êîòîðûõ ðàññ÷èòûâàåòñÿ çèãçàã
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);
// Ñòèëü èñïîëíåíèÿ ãðàôèêà â âèäå ëîìàíîé 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);
// Óñòàíîâêà çíà÷åíèé èíäèêàòîðà, êîòîðûå íå áóäóò âèäèìû íà ãðàôèêå
   SetIndexEmptyValue(0,0.0);
   SetIndexEmptyValue(1,0.0);
   SetIndexEmptyValue(2,0.0);
   SetIndexEmptyValue(3,0.0);
   SetIndexEmptyValue(4,0.0);
   SetIndexEmptyValue(5,0.0);
// Èìåíà äëÿ îêîí äàííûõ è ëýéáû äëÿ ñóáúîêîí
   SetIndexLabel(0,"Low1" );
   SetIndexLabel(1,"High1");
   SetIndexLabel(2,"Low2" );
   SetIndexLabel(3,"High2");
   SetIndexLabel(4,"Low3" );
   SetIndexLabel(5,"High3");

   _stringtoarray (ExtDepth, ExtDepth_, 3);
   _stringtoarray (ExtDeviation, ExtDeviation_, 3);
   _stringtoarray (ExtBackstep, ExtBackstep_, 3);
   _stringtoarray (ExtMaxBar, ExtMaxBar_, 3);
   _stringtoarray (GrossPeriod, GrossPeriod_, 3);

   for (i=0;i<3;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];
      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);
        }
     }

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

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

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

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

   currentBars=Bars;

   for (i=0;i<3;i++)
     {
      // ïðîâåðêè äëÿ êîððåêòíîãî ðàñ÷¸òà èíäèêàòîðà
      if (ExtDepth_[i]>=ExtBackstep_[i]) m=ExtDepth_[i]; else m=ExtBackstep_[i];
      if ((iBars(NULL,GrossPeriod_[i])-1<m) || (ExtDepth_[i]<=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;
//         lBar[i]=0; hBar[i]=0; tiZZ[i]=0;

         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 (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;
              }
           }

        }
     }

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


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

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

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

   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)) 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++)
        {
         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]) {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 _stringtoarray (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