
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Red
#property indicator_width1 2
#property indicator_color2 DodgerBlue
#property indicator_width2 2
#property indicator_color3 White
#property indicator_width3 2
#property indicator_color4 White
#property indicator_width4 2
#property indicator_color5 Gray
#property indicator_width5 2
#property indicator_color6 Gray
#property indicator_width6 2

//---- input parameters
input int h_left=6;  // left (past) h-value
input int h_right=24;   // right (future) h-value
extern string seperator                     = "============================";
extern bool   ShowText                      = true;
extern int    FontSize                      = 10;
extern string FontStyle                     = "Arial Bold";
extern color  Default_StaticColor           = Blue;
extern int    __Adjust_Vertical_Indent      = 30; //must be >0 
extern int    __Adjust_Horizontal_Indent    = 20; //must be >0
extern int    __Adjust_LineSpace            = 20; //must be >0
 
//---- buffers
double ExtUpFractalsBuffer[];
double ExtDownFractalsBuffer[];
double ResolvedBufferUp[];
double ResolvedBufferDn[];
double Up[];
double Dn[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator buffers mapping
    SetIndexBuffer(0,ExtUpFractalsBuffer);
    SetIndexBuffer(1,ExtDownFractalsBuffer);   
    SetIndexBuffer(2,ResolvedBufferUp);  
    SetIndexBuffer(3,ResolvedBufferDn);
    SetIndexBuffer(4,Up);  
    SetIndexBuffer(5,Dn);

//---- drawing settings
    SetIndexStyle(0,DRAW_ARROW);
    SetIndexArrow(0,217);
    SetIndexStyle(1,DRAW_ARROW);
    SetIndexArrow(1,218);
    SetIndexStyle(2,DRAW_ARROW);
    SetIndexArrow(2,217);
    SetIndexStyle(3,DRAW_ARROW);
    SetIndexArrow(3,218);
//    SetIndexStyle(4,DRAW_LINE);
//    SetIndexStyle(5,DRAW_LINE);
  
//----
    SetIndexEmptyValue(0,0.0);
    SetIndexEmptyValue(1,0.0);
    SetIndexEmptyValue(2,0.0);
    SetIndexEmptyValue(3,0.0);
//---- name for DataWindow
    SetIndexLabel(0,"Transient zone UP");
    SetIndexLabel(1,"Transient zone DOWN");
    SetIndexLabel(2,"Resolved possible transient zone UP");  
    SetIndexLabel(3,"Resolved possible transient zone DN");      
//---- initialization done   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
ObjectDelete("TZSTAT0");
ObjectDelete("TZSTAT05");
ObjectDelete("TZSTAT1");
ObjectDelete("TZSTAT2");
ObjectDelete("TZSTAT3");
ObjectDelete("TZSTAT4");
ObjectDelete("TZSTAT5");
ObjectDelete("TZSTAT6");
ObjectDelete("TZSTAT7");
ObjectDelete("TZSTAT8");
ObjectDelete("TZSTAT9");
ObjectDelete("TZSTAT10");
ObjectDelete("TZSTAT11");
ObjectDelete("TZSTAT12");
ObjectDelete("TZSTAT125");
ObjectDelete("TZSTAT126");
ObjectDelete("TZSTAT127");
ObjectDelete("TZSTAT128");
ObjectDelete("TZSTAT129");
ObjectDelete("TZSTAT13");
ObjectDelete("TZSTAT14");
ObjectDelete("TZSTAT15");
ObjectDelete("TZSTAT16");
ObjectDelete("TZSTAT165");
ObjectDelete("TZSTAT166");
ObjectDelete("TZSTAT167");
ObjectDelete("TZSTAT168");
ObjectDelete("TZSTAT169");

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    i,countproblembars,countresolvedproblembars,totalnumofbars=0,limit;
   int    counttrans, countrestrans, countfract, countresfract;
   double prevmin,prevmax,futuremin,futuremax;
   double d, dmin, dmax, dsum;
   double frmin, frmax, frsum;
   int frzeros=0, frones=0, frtwos=0;
   double trmin, trmax, trsum;
   int trzeros=0, trones=0, trtwos=0;   

   //Vertical and Horizontal Adjust   
   double x =  __Adjust_Horizontal_Indent;
   double y =  __Adjust_Vertical_Indent;

   limit=Bars-h_left;  
   i=limit;
    dmin=88888888;dmax=0;dsum=0;    
    trmin=88888888;trmax=0;trsum=0;  
    frmin=88888888;frmax=0;frsum=0; 
    
//----Up and Down Fractals
   while(i>=1)
     {

         prevmax=max(i,h_left);
         prevmin=min(i,h_left);
         if (i>h_left) futuremax=max(i,-h_right);
         if (i>h_left) futuremin=min(i,-h_right);  
                
         if (High[i]>prevmax) 
            {
            if (Close[i]>prevmax) //possible transient zone towards up
               {
               counttrans++;
               if ((futuremin<=prevmax)&&(futuremax>=High[i])) 
                     {countresolvedproblembars++; countrestrans++; ResolvedBufferUp[i]=High[i];} //fully resolved; a recurrence zone
                  else 
                  {
                  d=MathMax(futuremin-prevmax,High[i]-futuremax);    //not fully resolved, there is a transient zone
                  dsum+=d; trsum+=d;
                  if (d<dmin) dmin=d; if (d<trmin) trmin=d;
                  if (d>dmax) dmax=d; if (d>trmax) trmax=d;
                  ExtUpFractalsBuffer[i]=High[i];
                  }
               }
               
            if (Close[i]<=prevmax)  //possible up fractal
               {
               countfract++;
               if (futuremax>=High[i]) 
                     {countresolvedproblembars++; countresfract++; ResolvedBufferUp[i]=High[i];} //fully resolved, not a fractal at <h-i,h+i>
                  else
                  {                 
                  d=MathMin(High[i]-futuremax,High[i]-prevmax);  //not fully resolved - a fractal at <h-i,h+i>
                  dsum+=d; frsum+=d;
                  if (d<dmin) dmin=d; if (d<frmin) frmin=d;
                  if (d>dmax) dmax=d; if (d>frmax) frmax=d;
                  ExtUpFractalsBuffer[i]=High[i];
                  }
               }   
            //ObjectCreate("rect1", OBJ_RECTANGLE, 0, Time[i+h_left],Close[i],Time[i-h_left],prevmax);      
             }
         if (Low[i]<prevmin) 
            {             
            if (Close[i]<prevmin)  //possible transient zone towards down
               {
               counttrans++;
               if ((futuremax>=prevmin)&&(futuremin<=Low[i])) 
                     {countresolvedproblembars++; countrestrans++; ResolvedBufferDn[i]=Low[i];} //fully resolved
                  else 
                  {
                  d=MathMax(prevmin-futuremax,futuremin-Low[i]);  //transient zone presesnt
                  dsum+=d; trsum+=d;
                  if (d<dmin) dmin=d; if (d<trmin) trmin=d;
                  if (d>dmax) dmax=d; if (d>trmax) trmax=d;
                  ExtDownFractalsBuffer[i]=Low[i];
                  }
               }
               
            if (Close[i]>prevmin)  //possible down fractal
               {
               countfract++;
               if (futuremin<=Low[i]) 
                     {countresolvedproblembars++; countresfract++; ResolvedBufferDn[i]=Low[i];} //fully resolved
                  else
                  {                 
                  d=MathMin(futuremin-Low[i],prevmin-Low[i]);  //true down fractal at <h-i,h+i>
                  dsum+=d; frsum+=d;
                  if (d<dmin) dmin=d; if (d<frmin) frmin=d;
                  if (d>dmax) dmax=d; if (d>frmax) frmax=d;
                  ExtDownFractalsBuffer[i]=Low[i];
                  }
               }                
               
               
               //ObjectCreate("rect2", OBJ_RECTANGLE, 0, Time[i+h_left],prevmin,Time[i-h_left],Close[i]);                      
            }   
     totalnumofbars++;         
     i--;
     }
     
     countproblembars=counttrans+countfract;
     
     int trueproblembars=countproblembars-countresolvedproblembars;     
     double meand=dsum/double(trueproblembars);
   
     i=limit;
      while(i>=1)
     {

         prevmax=max(i,h_left);
         Up[i]=prevmax;
         prevmin=min(i,h_left);
         Dn[i]=prevmin;
         if (i>h_left) futuremax=max(i,-h_left);
         if (i>h_left) futuremin=min(i,-h_left);  
                
         if (High[i]>prevmax) 
            {
            if (Close[i]>prevmax) //possible transient zone towards up
               {

               if ((futuremin<=prevmax)&&(futuremax>=High[i])) {trzeros++;} // resolved, d=0
                  else 
                  {
                  d=MathMax(futuremin-prevmax,High[i]-futuremax);
                  if (d<meand)   //statistics of finite d
                     trzeros++;
                     else if (d<2*meand) 
                     trones++;
                     else if (d<3*meand)  
                     trtwos++;
                  }
               }
               
            if (Close[i]<=prevmax)  //possible up fractal
               {
               if (futuremax>=High[i]) {frzeros++;} //confirmed up fractal, d=0
                  else
                  {                 
                  d=MathMin(High[i]-futuremax,High[i]-prevmax);
                  if (d<meand)   //statistics of finite d
                     frzeros++;
                     else if (d<2*meand) 
                     frones++;
                     else if (d<3*meand)  
                     frtwos++;
                  }
               }   
            //ObjectCreate("rect1", OBJ_RECTANGLE, 0, Time[i+h_left],Close[i],Time[i-h_left],prevmax);      
             }
         if (Low[i]<prevmin) 
            {
             
            if (Close[i]<prevmin)  //possible transient zone towards down
               {

               if ((futuremax>=prevmin)&&(futuremin<=Low[i])) {trzeros++;} //fully resolved, d=0
                  else 
                  {
                  d=MathMax(prevmin-futuremax,futuremin-Low[i]);
                  if (d<meand)    //statistics of finite d
                     trzeros++;
                     else if (d<2*meand) 
                     trones++;
                     else if (d<3*meand)  
                     trtwos++;
                  }
               }
               
            if (Close[i]>prevmin)  //possible down fractal
               {
               if (futuremin<=Low[i]) {frzeros++;}  //fully resolved, d=0
                  else
                  {                 
                  d=MathMin(futuremin-Low[i],prevmin-Low[i]);
                  if (d<meand) //statistics of finite d
                     frzeros++;
                     else if (d<2*meand) 
                     frones++;
                     else if (d<3*meand)  
                     frtwos++;
                  }
               }                
               
               
               //ObjectCreate("rect2", OBJ_RECTANGLE, 0, Time[i+h_left],prevmin,Time[i-h_left],Close[i]);                      
            }           
     i--;
     }
     
  if (ShowText) {

   string temp0 = StringConcatenate("\n","h_left = ",h_left, ", h_right = ", h_right);
   string temp05 = "\n---------------------------------------";   
   string temp1 = StringConcatenate("\n","Number of bars: ",totalnumofbars);  
   string temp2 = StringConcatenate("\n","Problem bars: ",trueproblembars);
   string temp3 = StringConcatenate("\n","Fully resolved bars: ",countresolvedproblembars);     
   string temp4 = StringConcatenate("\n","Frequency of true problem bars: ",100*double(trueproblembars)/double(totalnumofbars)," %");    
   string temp5 = StringConcatenate("\n","Frequency of possible problem bars: ",100*double(countproblembars)/double(totalnumofbars)," %");
   string temp6 = StringConcatenate("\n","Probability of full resolving: ",100*double(countresolvedproblembars)/double(countproblembars)," %");
   string temp7 = StringConcatenate("\n","Mean width of the problem zone <k> : ",dsum/double(trueproblembars));
   string temp8 = StringConcatenate("\n","Max width of the problem zone : ",dmax);
   string temp9 = "\n---------------------------------------";
   string temp10 = StringConcatenate("\n","Frequency of true transient bars: ",100*double(counttrans-countrestrans)/double(totalnumofbars)," %");   
   string temp11 = StringConcatenate("\n","Frequency of possible transient bars: ",100*double(counttrans)/double(totalnumofbars)," %");
   string temp12 = StringConcatenate("\n","Probability of fully resolving possible transient bars: ",100*double(countrestrans)/double(counttrans)," %"); 
   string temp125 = StringConcatenate("\n","Mean width of trans. problem zone <k> : ",trsum/double(counttrans-countrestrans)); 
   string temp126 = StringConcatenate("\n","Max width of trans. problem zone: ",trmax);    
   string temp127 = StringConcatenate("\n","Probability of trans. zone width k=[0,  <k>> : ",100*(double(trzeros)/double(counttrans))," %");
   string temp128 = StringConcatenate("\n","Probability of trans. zone width k=[0, 2<k>> : ",100*(double(trzeros+trones)/double(counttrans))," %");
   string temp129 = StringConcatenate("\n","Probability of trans. zone width k=[0, 3<k>> : ",100*(double(trzeros+trones+trtwos)/double(counttrans))," %");   
   string temp13 = "\n---------------------------------------";
   string temp14 = StringConcatenate("\n","Frequency of true fractal bars: ",100*double(countfract-countresfract)/double(totalnumofbars)," %");   
   string temp15 = StringConcatenate("\n","Frequency of possible fractal bars: ",100*double(countfract)/double(totalnumofbars)," %");
   string temp16 = StringConcatenate("\n","Probability of fully resolving possible fractal bars: ",100*double(countresfract)/double(countfract)," %");
   string temp165 = StringConcatenate("\n","Mean width of fract. problem zone <k> : ",frsum/double(countfract-countresfract)); 
   string temp166 = StringConcatenate("\n","Max width of fract. problem zone: ",frmax); 
   string temp167 = StringConcatenate("\n","Probability of fract. zone width k=[0,  <k>> : ",100*(double(frzeros)/double(countfract))," %");
   string temp168 = StringConcatenate("\n","Probability of fract. zone width k=[0, 2<k>> : ",100*(double(frzeros+frones)/double(countfract))," %");
   string temp169 = StringConcatenate("\n","Probability of fract. zone width k=[0, 3<k>> : ",100*(double(frzeros+frones+frtwos)/double(countfract))," %");        

// Comment(temp0+temp05+temp1+temp2+temp3+temp4+temp5+temp6+temp7+temp8+temp9+temp10+temp11+temp12+temp125+temp126+temp127+temp128+temp129+temp13+temp14+temp15+temp16+temp165+temp166+temp167+temp168+temp169);

   string tObjName1   = "TZSTAT0"  ;
   ObjectDelete(tObjName1);  
   ObjectCreate(tObjName1, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName1, temp0, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName1, OBJPROP_CORNER, 0);
   ObjectSet(tObjName1, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName1, OBJPROP_YDISTANCE, __Adjust_LineSpace + y); 

   string tObjName2   = "TZSTAT05"  ;
   ObjectDelete(tObjName2);  
   ObjectCreate(tObjName2, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName2, temp05, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName2, OBJPROP_CORNER, 0);
   ObjectSet(tObjName2, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName2, OBJPROP_YDISTANCE, 2*__Adjust_LineSpace + y); 

   string tObjName3   = "TZSTAT1"  ;
   ObjectDelete(tObjName3);  
   ObjectCreate(tObjName3, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName3, temp1, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName3, OBJPROP_CORNER, 0);
   ObjectSet(tObjName3, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName3, OBJPROP_YDISTANCE, 3*__Adjust_LineSpace + y); 

   string tObjName4   = "TZSTAT2"  ;
   ObjectDelete(tObjName4);  
   ObjectCreate(tObjName4, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName4, temp2, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName4, OBJPROP_CORNER, 0);
   ObjectSet(tObjName4, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName4, OBJPROP_YDISTANCE, 4*__Adjust_LineSpace + y); 

   string tObjName5   = "TZSTAT3"  ;
   ObjectDelete(tObjName5);  
   ObjectCreate(tObjName5, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName5, temp3, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName5, OBJPROP_CORNER, 0);
   ObjectSet(tObjName5, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName5, OBJPROP_YDISTANCE, 5*__Adjust_LineSpace + y); 

   string tObjName6   = "TZSTAT4"  ;
   ObjectDelete(tObjName6);  
   ObjectCreate(tObjName6, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName6, temp4, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName6, OBJPROP_CORNER, 0);
   ObjectSet(tObjName6, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName6, OBJPROP_YDISTANCE, 6*__Adjust_LineSpace + y); 

   string tObjName7   = "TZSTAT5"  ;
   ObjectDelete(tObjName7);  
   ObjectCreate(tObjName7, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName7, temp5, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName7, OBJPROP_CORNER, 0);
   ObjectSet(tObjName7, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName7, OBJPROP_YDISTANCE, 7*__Adjust_LineSpace + y); 

   string tObjName8   = "TZSTAT6"  ;
   ObjectDelete(tObjName8);  
   ObjectCreate(tObjName8, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName8, temp6, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName8, OBJPROP_CORNER, 0);
   ObjectSet(tObjName8, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName8, OBJPROP_YDISTANCE, 8*__Adjust_LineSpace + y); 

   string tObjName9   = "TZSTAT7"  ;
   ObjectDelete(tObjName9);  
   ObjectCreate(tObjName9, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName9, temp7, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName9, OBJPROP_CORNER, 0);
   ObjectSet(tObjName9, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName9, OBJPROP_YDISTANCE, 9*__Adjust_LineSpace + y); 

   string tObjName10   = "TZSTAT8"  ;
   ObjectDelete(tObjName10);  
   ObjectCreate(tObjName10, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName10, temp8, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName10, OBJPROP_CORNER, 0);
   ObjectSet(tObjName10, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName10, OBJPROP_YDISTANCE, 10*__Adjust_LineSpace + y); 

   string tObjName11   = "TZSTAT9"  ;
   ObjectDelete(tObjName11);  
   ObjectCreate(tObjName11, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName11, temp9, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName11, OBJPROP_CORNER, 0);
   ObjectSet(tObjName11, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName11, OBJPROP_YDISTANCE, 11*__Adjust_LineSpace + y); 

   string tObjName12   = "TZSTAT10"  ;
   ObjectDelete(tObjName12);  
   ObjectCreate(tObjName12, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName12, temp10, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName12, OBJPROP_CORNER, 0);
   ObjectSet(tObjName12, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName12, OBJPROP_YDISTANCE, 12*__Adjust_LineSpace + y); 

   string tObjName13   = "TZSTAT11"  ;
   ObjectDelete(tObjName13);  
   ObjectCreate(tObjName13, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName13, temp11, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName13, OBJPROP_CORNER, 0);
   ObjectSet(tObjName13, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName13, OBJPROP_YDISTANCE, 13*__Adjust_LineSpace + y); 

   string tObjName14   = "TZSTAT12"  ;
   ObjectDelete(tObjName14);  
   ObjectCreate(tObjName14, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName14, temp12, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName14, OBJPROP_CORNER, 0);
   ObjectSet(tObjName14, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName14, OBJPROP_YDISTANCE, 14*__Adjust_LineSpace + y); 

   string tObjName15   = "TZSTAT125"  ;
   ObjectDelete(tObjName15);  
   ObjectCreate(tObjName15, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName15, temp125, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName15, OBJPROP_CORNER, 0);
   ObjectSet(tObjName15, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName15, OBJPROP_YDISTANCE, 15*__Adjust_LineSpace + y); 

   string tObjName16   = "TZSTAT126"  ;
   ObjectDelete(tObjName16);  
   ObjectCreate(tObjName16, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName16, temp126, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName16, OBJPROP_CORNER, 0);
   ObjectSet(tObjName16, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName16, OBJPROP_YDISTANCE, 16*__Adjust_LineSpace + y); 

   string tObjName17   = "TZSTAT127"  ;
   ObjectDelete(tObjName17);  
   ObjectCreate(tObjName17, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName17, temp127, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName17, OBJPROP_CORNER, 0);
   ObjectSet(tObjName17, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName17, OBJPROP_YDISTANCE, 17*__Adjust_LineSpace + y); 

   string tObjName18   = "TZSTAT128"  ;
   ObjectDelete(tObjName18);  
   ObjectCreate(tObjName18, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName18, temp128, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName18, OBJPROP_CORNER, 0);
   ObjectSet(tObjName18, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName18, OBJPROP_YDISTANCE, 18*__Adjust_LineSpace + y); 

   string tObjName19   = "TZSTAT129"  ;
   ObjectDelete(tObjName19);  
   ObjectCreate(tObjName19, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName19, temp129, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName19, OBJPROP_CORNER, 0);
   ObjectSet(tObjName19, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName19, OBJPROP_YDISTANCE, 19*__Adjust_LineSpace + y); 

   string tObjName20   = "TZSTAT13"  ;
   ObjectDelete(tObjName20);  
   ObjectCreate(tObjName20, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName20, temp13, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName20, OBJPROP_CORNER, 0);
   ObjectSet(tObjName20, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName20, OBJPROP_YDISTANCE, 20*__Adjust_LineSpace + y); 

   string tObjName21   = "TZSTAT14"  ;
   ObjectDelete(tObjName21);  
   ObjectCreate(tObjName21, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName21, temp14, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName21, OBJPROP_CORNER, 0);
   ObjectSet(tObjName21, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName21, OBJPROP_YDISTANCE, 21*__Adjust_LineSpace + y); 

   string tObjName22   = "TZSTAT15"  ;
   ObjectDelete(tObjName22);  
   ObjectCreate(tObjName22, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName22, temp15, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName22, OBJPROP_CORNER, 0);
   ObjectSet(tObjName22, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName22, OBJPROP_YDISTANCE, 22*__Adjust_LineSpace + y); 

   string tObjName23   = "TZSTAT16"  ;
   ObjectDelete(tObjName23);  
   ObjectCreate(tObjName23, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName23, temp16, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName23, OBJPROP_CORNER, 0);
   ObjectSet(tObjName23, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName23, OBJPROP_YDISTANCE, 23*__Adjust_LineSpace + y); 

   string tObjName24   = "TZSTAT165"  ;
   ObjectDelete(tObjName24);  
   ObjectCreate(tObjName24, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName24, temp165, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName24, OBJPROP_CORNER, 0);
   ObjectSet(tObjName24, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName24, OBJPROP_YDISTANCE, 24*__Adjust_LineSpace + y);

   string tObjName25   = "TZSTAT166"  ;
   ObjectDelete(tObjName25);  
   ObjectCreate(tObjName25, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName25, temp166, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName25, OBJPROP_CORNER, 0);
   ObjectSet(tObjName25, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName25, OBJPROP_YDISTANCE, 25*__Adjust_LineSpace + y);

   string tObjName26   = "TZSTAT167"  ;
   ObjectDelete(tObjName26);  
   ObjectCreate(tObjName26, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName26, temp167, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName26, OBJPROP_CORNER, 0);
   ObjectSet(tObjName26, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName26, OBJPROP_YDISTANCE, 26*__Adjust_LineSpace + y);

   string tObjName27   = "TZSTAT168"  ;
   ObjectDelete(tObjName27);  
   ObjectCreate(tObjName27, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName27, temp168, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName27, OBJPROP_CORNER, 0);
   ObjectSet(tObjName27, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName27, OBJPROP_YDISTANCE, 27*__Adjust_LineSpace + y);

   string tObjName28   = "TZSTAT169"  ;
   ObjectDelete(tObjName28);  
   ObjectCreate(tObjName28, OBJ_LABEL, 0, 0, 0); 
   ObjectSetText(tObjName28, temp169, FontSize, FontStyle,  Default_StaticColor);
   ObjectSet(tObjName28, OBJPROP_CORNER, 0);
   ObjectSet(tObjName28, OBJPROP_XDISTANCE, x);
   ObjectSet(tObjName28, OBJPROP_YDISTANCE, 28*__Adjust_LineSpace + y);
   }
   return(0);
}

//+------------------------------------------------------------------+

double max(int index,int shift)
{
if (shift<0) {index=index+shift-1; shift=-shift;}  
double mx=-8888888;
for(int ind=index+1;ind<=index+shift;ind++) if (High[ind]>mx) mx=High[ind];
return mx;
}   

double min(int index,int shift)
{
if (shift<0) {index=index+shift-1; shift=-shift;} 
double mn=8888888;
for(int ind=index+1;ind<=index+shift;ind++) if (Low[ind]<mn) mn=Low[ind];
return mn;
}  
