//+------------------------------------------------------------------+
//|                                                FISHINGIND_V2_04  |
//|              MAX888 && PavelG && Pavka69 && Barrel && UserUserov |
//|             http://forum.tradelikeapro.ru/index.php?topic=4731.0 |
//|                                                          v. 2.04 |
//+------------------------------------------------------------------+
// v. 2.04
// - ищется второй экстремум, удовлетворяющий условию для линии. Может быть не соседний. Линия рисуется всегда.
// v. 2.03
// - добавлено пересчет заявленного количества свечей на каждом тике
// v. 2.02
// - добавлены рисование линий со старшего ТФ
//

#property copyright "MAX888 && PavelG && Pavka69 && Barrel && UserUserov"
#property link      "http://forum.tradelikeapro.ru/index.php?topic=4731.0"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Silver
#property indicator_color2 Silver
//--- input parameters
extern bool       Alerts=false;//алерт формирования фрактала                 
extern bool       Sound=false;
extern string     SoundFile="alert.wav";
extern bool       AlertBreakLines=false;//алерт пересечения линии
extern bool       SoundBreakLines=false;
extern string     SoundFileBreakLines="kuckuck.wav";
extern int        otstup = 50;//отступ от High Low в пунктах для рисования фрактала и линии
//extern bool       ShowBadLine = true;//оставлять линию, если образовался новый фрактал в том же направлении
//                                       //но по правилам, линия по нему строится не должна
extern int        lineupw = 2;//ширина линии вверх
extern color      lineupc = Blue;//цвет линии вверх
extern int        linednw = 2;//ширина линии вниз
extern color      linednc = Red;//цвет линии вниз
extern int        kolshow = 500; //количество свечей для расчета фракталов на графике
extern bool       linealways = true;//ищется ближайший экстремум, удовлетворяющий условию. линия рисуется всегда
//extern bool       glrefresh = false;//true - пересчет всех буферов на каждом тике (энергоемкий режим!!! применять осторожно!!!)
extern bool       showovertf  = false;//показывать линии со старшего ТФ
extern int        overtf      = 240;// ТФ, с которого показывать (1, 5, 15, 30, 60, 240, 1440, 10080, 43200)
extern int        ovlineupw = 1;//ширина линии вверх
extern color      ovlineupc = SteelBlue;//цвет линии вверх
extern int        ovlineups = 1;//тип линии
extern int        ovlinednw = 1;//ширина линии вниз
extern color      ovlinednc = Orchid;//цвет линии вниз
extern int        ovlinedns = 1;//тип линии
extern bool       setovertf = false;//выдавать данные для построения линий на другом графике

//--- buffers
double High_[];
double Low_[];

bool alert1, alert2;
static int prevtime = 0;
string tlu = "TrendlineUp";
string tld = "TrendlineDn";
string tlu1 = "1TrendlineUp";
string tld1 = "1TrendlineDn";

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,217);
   SetIndexBuffer(0,High_);
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,218);
   SetIndexBuffer(1,Low_);
   SetIndexEmptyValue(1,0.0);
   SetIndexDrawBegin(0,kolshow);
   SetIndexDrawBegin(1,kolshow);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   if(ObjectFind(tld)!=-1) ObjectDelete(tld);
   if(ObjectFind(tlu)!=-1) ObjectDelete(tlu);
   if(ObjectFind(tld1)!=-1) ObjectDelete(tld1);
   if(ObjectFind(tlu1)!=-1) ObjectDelete(tlu1);
   if(ObjectFind("FTLUp"+Symbol()+overtf)!=-1) ObjectDelete("FTLUp"+Symbol()+overtf);
   if(ObjectFind("FTLDn"+Symbol()+overtf)!=-1) ObjectDelete("FTLDn"+Symbol()+overtf); 
   if(setovertf)
   {
      GlobalVariablesDeleteAll("FTLUp"+Symbol()+Period());
      GlobalVariablesDeleteAll("FTLDn"+Symbol()+Period());     
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
//   if (iTime(Symbol(), 0, 0) != prevtime)
//   {//----
//      prevtime = iTime(Symbol(),0,0);
   
   int    counted_bars=IndicatorCounted();
   int count, m;
   if (Bars <= 4) return (0);
   count = kolshow;
   ArrayInitialize(High_,0.0);
   ArrayInitialize(Low_,0.0);
//   for (m=count+3;m>=0;m--)
//   {
//      High_[m]=0.0;
//      Low_[m]=0.0;
//   }
   
   for (int i = count; i >= 0; i--)
   {
      if(High[i+2]>High[i+1] && High[i+2]>=High[i+3]) High_[i+2] = High[i+2]+Point*otstup;
      if(Low[i+2]<Low[i+1] && Low[i+2]<=Low[i+3]) Low_[i+2] = Low[i+2]-Point*otstup;
   }

   if(High_[2]>0)
   {
      if(Alerts) Alert(Symbol() + "," + GetNameTF(Period()) + ": Up extremum !!!");
      if(Sound) PlaySound (SoundFile);
   }
   if(Low_[2]>0)
   {
      if(Alerts) Alert(Symbol() + "," + GetNameTF(Period()) + ": Down extremum !!!");
      if(Sound) PlaySound (SoundFile);
   }

   double zzUp1=0,zzUp2=0;   
   double zzDn1=0,zzDn2=0;
   double zz1Up1=0,zz1Up2=0;   
   double zz1Dn1=0,zz1Dn2=0;
   datetime t1Up1, t1Up2, t1Dn1, t1Dn2;
   int iUp1,iUp2,iDn1,iDn2;
   double zzTmp;
   int j=0;
   int prnoedit=0;

   for(i=1;i<=kolshow;i++)
   {
      zzTmp=0;//current
      if(Low_[i]>0) zzTmp=Low_[i];
   
      if(zzTmp>0.0 && j==0 && zzTmp==Low_[i] && zzDn1==0)  {zzDn1=zzTmp; iDn1=i; continue;}
      if(zzDn1!=0) j = 1;
      if (linealways == false)
      {
         if(zzTmp>0.0 && zzTmp==Low_[i] && zzDn2==0)  
         {
            zzDn2=zzTmp; 
            iDn2=i; 
            break;
         }
      }
      else
      {
         if(zzTmp>0.0 && zzTmp==Low_[i] && zzDn2!=zzTmp && zzTmp <= zzDn1)
         {
            zzDn2=zzTmp; 
            iDn2=i; 
            break;
         }
      }
      if(zzDn1!=0 && zzDn2!=0) break;
   }

   j=0;
   for(i=1;i<=kolshow;i++)
   {
      zzTmp=0;//current
      if(High_[i]>0) zzTmp=High_[i];
   
      if(zzTmp>0.0 && j==0 && zzTmp==High_[i] && zzUp1==0) {zzUp1=zzTmp; iUp1=i; continue;}
      if(zzUp1!=0) j = 1;
      if (linealways == false)
      {
         if(zzTmp>0.0 && zzTmp==High_[i] && zzUp2==0) 
         {
            zzUp2=zzTmp; 
            iUp2=i; 
            break;
         }
      }
      else
      {
         if(zzTmp>0.0 && zzTmp==High_[i] && zzUp2!=zzTmp && zzTmp >= zzUp1)
         {
            zzUp2=zzTmp; 
            iUp2=i; 
            break;            
         }
      }
      if(zzUp1!=0 && zzUp2!=0) break;
   }
   
   if(zzUp1!=0.0 && zzUp2!=0.0 && zzUp1<=zzUp2)
   {// trend down
      if(ObjectFind(tld1)>-1)
      {
         t1Up1 = ObjectGet(tld1,OBJPROP_TIME2);
         zz1Up1 = ObjectGet(tld1,OBJPROP_PRICE2);
         t1Up2 = ObjectGet(tld1,OBJPROP_TIME1);
         zz1Up2 = ObjectGet(tld1,OBJPROP_PRICE1);
         if (zz1Up1==zzUp1 && zz1Up2==zzUp2 && t1Up1==iTime(NULL,0,iUp1) && t1Up2 == iTime(NULL,0,iUp2))
         {
            prnoedit = 1;
         }
         else
         {
            ObjectDelete(tld1);
         }
      
      }
   
      if (prnoedit == 0)
      {
         if(ObjectFind(tld)==-1)
          {
            if(ObjectCreate(tld,OBJ_TREND,0,iTime(NULL,0,iUp2),zzUp2,iTime(NULL,0,iUp1),zzUp1))
            {
                 ObjectSet(tld,OBJPROP_COLOR,linednc);                
                 ObjectSet(tld,OBJPROP_WIDTH,linednw);
                 ObjectSet(tld,OBJPROP_RAY,TRUE);
                 alert2 = true;
            }
          }
         else 
         {
            t1Up1 = ObjectGet(tld,OBJPROP_TIME2);
            zz1Up1 = ObjectGet(tld,OBJPROP_PRICE2);
            t1Up2 = ObjectGet(tld,OBJPROP_TIME1);
            zz1Up2 = ObjectGet(tld,OBJPROP_PRICE1);
            if (zz1Up1!=zzUp1 || zz1Up2!=zzUp2 || t1Up1!=iTime(NULL,0,iUp1) || t1Up2 != iTime(NULL,0,iUp2))
            {
               ObjectSet(tld,OBJPROP_TIME1,iTime(NULL,0,iUp2));
               ObjectSet(tld,OBJPROP_PRICE1,zzUp2);
               ObjectSet(tld,OBJPROP_TIME2,iTime(NULL,0,iUp1));
               ObjectSet(tld,OBJPROP_PRICE2,zzUp1);
               alert2 = true;
            }
         }
      }
   }// trend down
   else 
   {
//      if(zzUp1!=0.0)
//      {
//         if(ShowBadLine==false)
//         {
            if(ObjectFind(tld1)!=-1) ObjectDelete(tld1);
            if(ObjectFind(tld)!=-1) ObjectDelete(tld);
//         }
//      }
   }

   if(zzDn1!=0.0 && zzDn2!=0.0 && zzDn1>=zzDn2)
   {// trend up
      prnoedit = 0;

      if(ObjectFind(tlu1)>-1)
      {
         t1Dn1 = ObjectGet(tlu1,OBJPROP_TIME2);
         zz1Dn1 = ObjectGet(tlu1,OBJPROP_PRICE2);
         t1Dn2 = ObjectGet(tlu1,OBJPROP_TIME1);
         zz1Dn2 = ObjectGet(tlu1,OBJPROP_PRICE1);
         if (zz1Dn1==zzDn1 && zz1Dn2==zzDn2 && t1Dn1==iTime(NULL,0,iDn1) && t1Dn2 == iTime(NULL,0,iDn2))
         {
            prnoedit = 1;
         }
         else
         {
            ObjectDelete(tlu1);
         }
      
      }
   
      if (prnoedit == 0)
      {

         if(ObjectFind(tlu)==-1)
         {

            if(ObjectCreate(tlu,OBJ_TREND,0,iTime(NULL,0,iDn2),zzDn2,iTime(NULL,0,iDn1),zzDn1))
            {
                 ObjectSet(tlu,OBJPROP_COLOR,lineupc);                
                 ObjectSet(tlu,OBJPROP_WIDTH,lineupw);
                 ObjectSet(tlu,OBJPROP_RAY,TRUE);
                 alert1 = true;
            }
      
         }
         else 
         {
            t1Dn1 = ObjectGet(tlu,OBJPROP_TIME2);
            zz1Dn1 = ObjectGet(tlu,OBJPROP_PRICE2);
            t1Dn2 = ObjectGet(tlu,OBJPROP_TIME1);
            zz1Dn2 = ObjectGet(tlu,OBJPROP_PRICE1);
            if (zz1Dn1!=zzDn1 || zz1Dn2!=zzDn2 || t1Dn1!=iTime(NULL,0,iDn1) || t1Dn2!=iTime(NULL,0,iDn2))
            {
               ObjectSet(tlu,OBJPROP_TIME1,iTime(NULL,0,iDn2));
               ObjectSet(tlu,OBJPROP_PRICE1,zzDn2);
               ObjectSet(tlu,OBJPROP_TIME2,iTime(NULL,0,iDn1));
               ObjectSet(tlu,OBJPROP_PRICE2,zzDn1);
               alert1 = true;
            }
         }
      }
   }// trend up
   else
   {
//      if(zzDn1!=0.0)
//      {
//         if(ShowBadLine==false)
//         {
            if(ObjectFind(tlu1)!=-1) ObjectDelete(tlu1);
            if(ObjectFind(tlu)!=-1) ObjectDelete(tlu);
//         }
//      }
//   }
   }//----
      
   string nameup, namedn, nameup1, namedn1;
   string vupt1, vupt2, vupp1, vupp2;
   string vdnt1, vdnt2, vdnp1, vdnp2;
   datetime tDn1, tDn2, tUp1, tUp2;

   nameup1 = "FTLUp"+Symbol()+Period();
   vupt1 = nameup1 + "t1";
   vupt2 = nameup1 + "t2";
   vupp1 = nameup1 + "p1";
   vupp2 = nameup1 + "p2";
   namedn1 = "FTLDn"+Symbol()+Period();
   vdnt1 = namedn1 + "t1";
   vdnt2 = namedn1 + "t2";
   vdnp1 = namedn1 + "p1";
   vdnp2 = namedn1 + "p2";
   
   if (setovertf)
   {
      if(ObjectFind(tlu)!=-1)
      {
         t1Dn1 = ObjectGet(tlu,OBJPROP_TIME2);
         zz1Dn1 = ObjectGet(tlu,OBJPROP_PRICE2);
         t1Dn2 = ObjectGet(tlu,OBJPROP_TIME1);
         zz1Dn2 = ObjectGet(tlu,OBJPROP_PRICE1);
         zzDn1 = GlobalVariableGet(vdnp1);
         zzDn2 = GlobalVariableGet(vdnp2);
         tDn1 = GlobalVariableGet(vdnp1);
         tDn2 = GlobalVariableGet(vdnp2);
         if (zz1Dn1!=zzDn1 || zz1Dn2!=zzDn2 || t1Dn1!=tDn1 || t1Dn2!=tDn2)
         {
            GlobalVariableSet(vupp1,zz1Dn1);
            GlobalVariableSet(vupp2,zz1Dn2);
            GlobalVariableSet(vupt1,t1Dn1);
            GlobalVariableSet(vupt2,t1Dn2);
         }
      }
      else
      {
         if(ObjectFind(tlu1)!=-1)
         {
            t1Dn1 = ObjectGet(tlu1,OBJPROP_TIME2);
            zz1Dn1 = ObjectGet(tlu1,OBJPROP_PRICE2);
            t1Dn2 = ObjectGet(tlu1,OBJPROP_TIME1);
            zz1Dn2 = ObjectGet(tlu1,OBJPROP_PRICE1);
            zzDn1 = GlobalVariableGet(vdnp1);
            zzDn2 = GlobalVariableGet(vdnp2);
            tDn1 = GlobalVariableGet(vdnp1);
            tDn2 = GlobalVariableGet(vdnp2);
            if (zz1Dn1!=zzDn1 || zz1Dn2!=zzDn2 || t1Dn1!=tDn1 || t1Dn2!=tDn2)
            {
               GlobalVariableSet(vupp1,zz1Dn1);
               GlobalVariableSet(vupp2,zz1Dn2);
               GlobalVariableSet(vupt1,t1Dn1);
               GlobalVariableSet(vupt2,t1Dn2);
            }
         }
         else
         {
            GlobalVariablesDeleteAll(nameup1);
         }
      }      

      if(ObjectFind(tld)!=-1)
      {
         t1Up1 = ObjectGet(tld,OBJPROP_TIME2);
         zz1Up1 = ObjectGet(tld,OBJPROP_PRICE2);
         t1Up2 = ObjectGet(tld,OBJPROP_TIME1);
         zz1Up2 = ObjectGet(tld,OBJPROP_PRICE1);
         zzUp1 = GlobalVariableGet(vupp1);
         zzUp2 = GlobalVariableGet(vupp2);
         tUp1 = GlobalVariableGet(vupp1);
         tUp2 = GlobalVariableGet(vupp2);
         if (zz1Up1!=zzUp1 || zz1Up2!=zzUp2 || t1Up1!=tUp1 || t1Up2!=tUp2)
         {
            GlobalVariableSet(vdnp1,zz1Up1);
            GlobalVariableSet(vdnp2,zz1Up2);
            GlobalVariableSet(vdnt1,t1Up1);
            GlobalVariableSet(vdnt2,t1Up2);
         }
      }
      else
      {
         if(ObjectFind(tld1)!=-1)
         {
            t1Up1 = ObjectGet(tld1,OBJPROP_TIME2);
            zz1Up1 = ObjectGet(tld1,OBJPROP_PRICE2);
            t1Up2 = ObjectGet(tld1,OBJPROP_TIME1);
            zz1Up2 = ObjectGet(tld1,OBJPROP_PRICE1);
            zzUp1 = GlobalVariableGet(vupp1);
            zzUp2 = GlobalVariableGet(vupp2);
            tUp1 = GlobalVariableGet(vupp1);
            tUp2 = GlobalVariableGet(vupp2);
            if (zz1Up1!=zzUp1 || zz1Up2!=zzUp2 || t1Up1!=tUp1 || t1Up2!=tUp2)
            {
               GlobalVariableSet(vdnp1,zz1Up1);
               GlobalVariableSet(vdnp2,zz1Up2);
               GlobalVariableSet(vdnt1,t1Up1);
               GlobalVariableSet(vdnt2,t1Up2);
            }
         }
         else
         {
            GlobalVariablesDeleteAll(namedn1);
         }
      }      
   }
   
   nameup = "FTLUp"+Symbol()+overtf;
   vupt1 = nameup + "t1";
   vupt2 = nameup + "t2";
   vupp1 = nameup + "p1";
   vupp2 = nameup + "p2";
   namedn = "FTLDn"+Symbol()+overtf;
   vdnt1 = namedn + "t1";
   vdnt2 = namedn + "t2";
   vdnp1 = namedn + "p1";
   vdnp2 = namedn + "p2";

   if (showovertf && Period()<overtf)
   {
      if(GlobalVariableCheck(vupt1) && GlobalVariableCheck(vupt2) && GlobalVariableCheck(vupp1) && GlobalVariableCheck(vupp2))
      {
         tDn1 = GlobalVariableGet(vupt1);
         tDn2 = GlobalVariableGet(vupt2);
         zzDn1 = GlobalVariableGet(vupp1);
         zzDn2 = GlobalVariableGet(vupp2);
         if(ObjectFind(nameup)==-1)
         {
            if(ObjectCreate(nameup,OBJ_TREND,0,tDn2,zzDn2,tDn1,zzDn1))
            {
                 ObjectSet(nameup,OBJPROP_COLOR,ovlineupc);                
                 ObjectSet(nameup,OBJPROP_WIDTH,ovlineupw);
                 ObjectSet(nameup,OBJPROP_STYLE,ovlineups);
                 ObjectSet(nameup,OBJPROP_RAY,TRUE);
            }
      
         }
         else 
         {
            t1Dn1 = ObjectGet(nameup,OBJPROP_TIME2);
            zz1Dn1 = ObjectGet(nameup,OBJPROP_PRICE2);
            t1Dn2 = ObjectGet(nameup,OBJPROP_TIME1);
            zz1Dn2 = ObjectGet(nameup,OBJPROP_PRICE1);
            if (zz1Dn1!=zzDn1 || zz1Dn2!=zzDn2 || t1Dn1!=tDn1 || t1Dn2!=tDn2)
            {
               ObjectSet(nameup,OBJPROP_TIME1,tDn2);
               ObjectSet(nameup,OBJPROP_PRICE1,zzDn2);
               ObjectSet(nameup,OBJPROP_TIME2,tDn1);
               ObjectSet(nameup,OBJPROP_PRICE2,zzDn1);
            }
         }
      }
      else
      {
         if(ObjectFind(nameup)!=-1) ObjectDelete(nameup);
      }
      
      if(GlobalVariableCheck(vdnt1) && GlobalVariableCheck(vdnt2) && GlobalVariableCheck(vdnp1) && GlobalVariableCheck(vdnp2))
      {
         tUp1 = GlobalVariableGet(vdnt1);
         tUp2 = GlobalVariableGet(vdnt2);
         zzUp1 = GlobalVariableGet(vdnp1);
         zzUp2 = GlobalVariableGet(vdnp2);
         if(ObjectFind(namedn)==-1)
         {
            if(ObjectCreate(namedn,OBJ_TREND,0,tUp2,zzUp2,tUp1,zzUp1))
            {
                 ObjectSet(namedn,OBJPROP_COLOR,ovlinednc);                
                 ObjectSet(namedn,OBJPROP_WIDTH,ovlinednw);
                 ObjectSet(namedn,OBJPROP_STYLE,ovlinedns);
                 ObjectSet(namedn,OBJPROP_RAY,TRUE);
            }
      
         }
         else 
         {
            t1Up1 = ObjectGet(namedn,OBJPROP_TIME2);
            zz1Up1 = ObjectGet(namedn,OBJPROP_PRICE2);
            t1Up2 = ObjectGet(namedn,OBJPROP_TIME1);
            zz1Up2 = ObjectGet(namedn,OBJPROP_PRICE1);
            if (zz1Up1!=zzUp1 || zz1Up2!=zzUp2 || t1Up1!=tUp1 || t1Up2!=tUp2)
            {
               ObjectSet(namedn,OBJPROP_TIME1,tUp2);
               ObjectSet(namedn,OBJPROP_PRICE1,zzUp2);
               ObjectSet(namedn,OBJPROP_TIME2,tUp1);
               ObjectSet(namedn,OBJPROP_PRICE2,zzUp1);
            }
         }
      }
      else
      {
         if(ObjectFind(namedn)!=-1) ObjectDelete(namedn);
      }
   }
   else
   {
      if(ObjectFind(nameup)!=-1) ObjectDelete(nameup);
      if(ObjectFind(namedn)!=-1) ObjectDelete(namedn);      
   }

   if((AlertBreakLines || SoundBreakLines))
   {
      if(ObjectFind(tlu1)!=-1 && alert1 == true)
      {
         if(Close[0]<=ObjectGetValueByShift(tlu1,0))
         {
            alert1 = false;
            if(AlertBreakLines) Alert(Symbol() + "," + GetNameTF(Period()) + ": Break TrendLineUp DOWN !!!");
            if(SoundBreakLines) PlaySound (SoundFileBreakLines);
            //Sleep(1000);
         }
      }
      if(ObjectFind(tlu)!=-1 && alert1 == true)
      {
         if(Close[0]<=ObjectGetValueByShift(tlu,0))
         {
            alert1 = false;
            if(AlertBreakLines) Alert(Symbol() + "," + GetNameTF(Period()) + ": Break TrendLineUp DOWN !!!");
            if(SoundBreakLines) PlaySound (SoundFileBreakLines);
            //Sleep(1000);
         }
      }
      if(ObjectFind(tld1)!=-1 && alert2 == true)
      {
         if(Close[0]>=ObjectGetValueByShift(tld1,0))
         {
            alert2 = false;
            if(AlertBreakLines) Alert(Symbol() + "," + GetNameTF(Period()) + ": Break TrendLineDn UP !!!");
            if(SoundBreakLines) PlaySound (SoundFileBreakLines);
            //Sleep(1000);
         }
      }
      if(ObjectFind(tld)!=-1 && alert2 == true)
      {
         if(Close[0]>=ObjectGetValueByShift(tld,0))
         {
            alert2 = false;
            if(AlertBreakLines) Alert(Symbol() + "," + GetNameTF(Period()) + ": Break TrendLineDn UP !!!");
            if(SoundBreakLines) PlaySound (SoundFileBreakLines);
            //Sleep(1000);
         }
      }
   }
//----
   return(0);
}
//+------------------------------------------------------------------+

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 01.09.2005                                                     |
//|  Описание : Возвращает наименование таймфрейма                             |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    TimeFrame - таймфрейм (количество секунд)      (0 - текущий ТФ)         |
//+----------------------------------------------------------------------------+
string GetNameTF(int TimeFrame=0) {
  if (TimeFrame==0) TimeFrame=Period();
  switch (TimeFrame) {
    case PERIOD_M1:  return("M1");
    case PERIOD_M5:  return("M5");
    case PERIOD_M15: return("M15");
    case PERIOD_M30: return("M30");
    case PERIOD_H1:  return("H1");
    case PERIOD_H4:  return("H4");
    case PERIOD_D1:  return("Daily");
    case PERIOD_W1:  return("Weekly");
    case PERIOD_MN1: return("Monthly");
    default:         return("UnknownPeriod");
  }
}