MultiZigZag

MultiZigZag

This script is designed to display three independent ZigZag indicators on a single trading chart simultaneously. The ZigZag is a popular technical analysis tool used to filter out minor price fluctuations and highlight the significant "peaks" and "troughs" of market movement, making it easier for traders to identify trends and key reversal points.

Core Functionality

The primary logic of this script allows for the simultaneous tracking of three different market structures. Each of the three ZigZags can be configured with its own unique sensitivity settings:

  • Depth: Determines how many price bars are analyzed to find a significant high or low.
  • Deviation: Sets the minimum price change required to consider a new "swing" point as valid, preventing the indicator from reacting to insignificant noise.
  • Backstep: Defines the minimum number of bars that must pass before the indicator can identify a new peak or trough.

Multi-Timeframe Analysis

One of the standout features of this script is its ability to handle multiple timeframes at once. Rather than just showing three different types of ZigZags on your current chart, the script can pull data from larger timeframes (e.g., 60 minutes, 4 hours, or daily charts) and project those lines onto your current view.

This allows a visitor to see "the big picture"—such as long-term market structure—while simultaneously viewing shorter-term price action on their active trading screen. If the timeframe is set to "0," the script simply calculates the ZigZag based on the current chart's period.

Intelligent Data Handling

To ensure the platform remains responsive and accurate, the script employs several sophisticated logic techniques:

  1. Dynamic Memory Management: It automatically adjusts the amount of historical data it stores based on the user's settings (Maximum Bars). This ensures that even when looking at very large periods of history, the chart stays optimized.
  2. Real-Time Recalculation: For older data, the script includes a "ReCalculate" feature. It keeps track of the most recent extreme points and updates them in real-time, ensuring that the lines stay current as new price data arrives without needing to redraw the entire historical dataset every second.
  3. Data Shifting: The logic includes a mechanism to shift elements within the data arrays. This ensures that when switching between different timeframes or historical segments, the visual representation remains continuous and aligned with the correct dates and times.

Summary of User Experience

For a non-programmer, this tool acts as a "multi-layered" trend filter. Instead of looking at three separate windows to see how the market is behaving on different scales, you can see all three trend structures overlaid on one chart. It effectively separates the "noise" of price movement into three distinct visual paths, helping you identify where the market is truly turning based on your preferred levels of sensitivity and timeframe depth.

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

  5 íîÿáðÿ 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];
      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);
        }
     }

   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];
      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 (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, 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 _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