// https://forex-station.com/viewtopic.php?p=1295478806#p1295478806 //button code1
// https://forex-station.com/viewtopic.php?p=1295478883#p1295478883 //button code2
//+------------------------------------------------------------------+
//|                                                   Tipu Renko.mq4 |
//|                                    Copyright 2016, Kaleem Haider |
//|                      https://www.mql5.com/en/users/kaleem.haider |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Kaleem Haider"
#property link      "https://www.mql5.com/en/users/kaleem.haider"
#property version   "1.10"
#property strict
#property indicator_chart_window

#define PipsPoint Get_PipsPoint()
//Enumerations for Renko Mode
enum ENUM_RenkoMode
  {
   rClose = 0,       //Close
   rHighLow = 1,     //High/Low
  };
//Enumeration for type of marks
enum ENUM_RenkoMark
  {
   None=0,
   Brick=1,
   Arrows=2,
  };

input ENUM_RenkoMode      eRenkoMode        =  0;              //Box Mode
input ENUM_RenkoMark      eRenkoMark        =  1;              //Renko Mark
input double              iRenkoSize        =  5;              //Renko Size
input ENUM_LINE_STYLE     eRenkoStyle       =  0;              //Line Style
input int                 iRenkoWidth       =  1;              //Line Width
input color               cUpCandle         =  C'31,159,192';  //Up Color
input color               cDwnCandle        =  C'230,77,69';   //Down Color
input bool                bFill             =  true;           //Fill Candles
input bool                bAlertM           =  false;          //Alert Mobile
input bool                bAlertS           =  false;          //Alert Onscreen
input bool                bAlertE           =  false;          //Alert Email

//Forex-Station button template start41; copy and paste
extern string             button_note1_         = "------------------------------";
extern int                btn_Subwindow         = 0;                               // What window to put the button on.  If <0, the button will use the same sub-window as the indicator.
extern ENUM_BASE_CORNER   btn_corner            = CORNER_LEFT_UPPER;               // button corner on chart for anchoring
extern string             btn_text              = "RENKO";                         // a button name
extern string             btn_Font              = "Arial";                         // button font name
extern int                btn_FontSize          = 9;                               // button font size               
extern color              btn_text_ON_color     = clrLime;                         // ON color when the button is turned on
extern color              btn_text_OFF_color    = clrRed;                          // OFF color when the button is turned off
extern color              btn_background_color  = clrDimGray;                      // background color of the button
extern color              btn_border_color      = clrBlack;                        // border color the button
extern int                button_x              = 20;                              // x coordinate of the button     
extern int                button_y              = 25;                              // y coordinate of the button     
extern int                btn_Width             = 80;                              // button width
extern int                btn_Height            = 20;                              // button height
extern string             button_note2          = "------------------------------";

bool show_data, recalc=false;
string IndicatorObjPrefix, buttonId;
//Forex-Station button template end41; copy and paste

string short_name="tp_Renko";
string indicator_name="Tipu Renko";
int iLastTrend;
double dLowR=0,dHighR=0,dOpenR=0,dCloseR=0;
datetime dtPrevTime=0;
static datetime prevTime;
double dBuyCounter=0.0,dSellCounter=0.0;

double dTrendBuffer[],dSignalBuffer[],dBuyCountBuffer[],dSellCountBuffer[];
//+------------------------------------------------------------------------------------------------------------------+
//Forex-Station button template start42; copy and paste
int OnInit()
{
   IndicatorDigits(Digits);
   IndicatorObjPrefix = "__" + btn_text + "__";
   
   // The leading "_" gives buttonId a *unique* prefix.  Furthermore, prepending the swin is usually unique unless >2+ of THIS indy are displayed in the SAME sub-window. (But, if >2 used, be sure to shift the buttonId position)
   buttonId = "_" + IndicatorObjPrefix + "_BT_";
   if (ObjectFind(buttonId)<0) 
      createButton(buttonId, btn_text, btn_Width, btn_Height, btn_Font, btn_FontSize, btn_background_color, btn_border_color, btn_text_ON_color);
   ObjectSetInteger(0, buttonId, OBJPROP_YDISTANCE, button_y);
   ObjectSetInteger(0, buttonId, OBJPROP_XDISTANCE, button_x);

   init2();

   show_data = ObjectGetInteger(0, buttonId, OBJPROP_STATE);
   
   if (show_data) ObjectSetInteger(0,buttonId,OBJPROP_COLOR,btn_text_ON_color); 
   else ObjectSetInteger(0,buttonId,OBJPROP_COLOR,btn_text_OFF_color);

   IndicatorSetString(INDICATOR_SHORTNAME,indicator_name);

   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------------------------------------------------------+
void createButton(string buttonID,string buttonText,int width2,int height,string font,int fontSize,color bgColor,color borderColor,color txtColor)
{
      ObjectDelete    (0,buttonID);
      ObjectCreate    (0,buttonID,OBJ_BUTTON,btn_Subwindow,0,0);
      ObjectSetInteger(0,buttonID,OBJPROP_COLOR,txtColor);
      ObjectSetInteger(0,buttonID,OBJPROP_BGCOLOR,bgColor);
      ObjectSetInteger(0,buttonID,OBJPROP_BORDER_COLOR,borderColor);
      ObjectSetInteger(0,buttonID,OBJPROP_BORDER_TYPE,BORDER_RAISED);
      ObjectSetInteger(0,buttonID,OBJPROP_XSIZE,width2);
      ObjectSetInteger(0,buttonID,OBJPROP_YSIZE,height);
      ObjectSetString (0,buttonID,OBJPROP_FONT,font);
      ObjectSetString (0,buttonID,OBJPROP_TEXT,buttonText);
      ObjectSetInteger(0,buttonID,OBJPROP_FONTSIZE,fontSize);
      ObjectSetInteger(0,buttonID,OBJPROP_SELECTABLE,0);
      ObjectSetInteger(0,buttonID,OBJPROP_CORNER,btn_corner);
      ObjectSetInteger(0,buttonID,OBJPROP_HIDDEN,1);
      ObjectSetInteger(0,buttonID,OBJPROP_XDISTANCE,9999);
      ObjectSetInteger(0,buttonID,OBJPROP_YDISTANCE,9999);
      // Upon creation, set the initial state to "true" which is "on", so one will see the indicator by default
      ObjectSetInteger(0, buttonId, OBJPROP_STATE, true);
}
//+------------------------------------------------------------------------------------------------------------------+
void OnDeinit(const int reason) 
{
   deinit2();
   // If just changing a TF', the button need not be deleted, therefore the 'OBJPROP_STATE' is also preserved.
   if(reason != REASON_CHARTCHANGE) ObjectDelete(buttonId);
}
//+------------------------------------------------------------------------------------------------------------------+
void OnChartEvent(const int id, //don't change anything here
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
   // If another indy on the same chart has enabled events for create/delete/mouse-move, just skip this events up front because they aren't
   //    needed, AND in the worst case, this indy might cause MT4 to hang!!  Skipping the events seems to help, along with other (major) changes to the code below.
   if(id==CHARTEVENT_OBJECT_CREATE || id==CHARTEVENT_OBJECT_DELETE) return; // This appears to make this indy compatible with other programs that enabled CHART_EVENT_OBJECT_CREATE and/or CHART_EVENT_OBJECT_DELETE
   if(id==CHARTEVENT_MOUSE_MOVE    || id==CHARTEVENT_MOUSE_WHEEL)   return; // If this, or another program, enabled mouse-events, these are not needed below, so skip it unless actually needed. 

   if (id==CHARTEVENT_OBJECT_CLICK && sparam == buttonId)
   {
      show_data = ObjectGetInteger(0, buttonId, OBJPROP_STATE);
      
      if (show_data)
      {
         ObjectSetInteger(0,buttonId,OBJPROP_COLOR,btn_text_ON_color); 
//         init2();
         // Is it a problem to call 'start()' ??  Possibly it makes no difference, but now calling "mystart()" instead of "start()"; and "start()" simply runs "mystart()", so should be same as before.
         recalc=true;
         mystart();
      }
      else
      {
         ObjectSetInteger(0,buttonId,OBJPROP_COLOR,btn_text_OFF_color);
         deinit2();
      }
   }
}
//Forex-Station button template end42; copy and paste
//+------------------------------------------------------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init2()
  {
//Delete for templates
   DeleteBricks();

   int n=0;
//--- indicator buffers mapping
   IndicatorBuffers(4);

//---Holder for the signals, and trend
   SetIndexBuffer(n,dSignalBuffer,INDICATOR_CALCULATIONS); n++;
   SetIndexBuffer(n,dTrendBuffer,INDICATOR_CALCULATIONS);  n++;
   SetIndexBuffer(n,dBuyCountBuffer,INDICATOR_CALCULATIONS); n++;
   SetIndexBuffer(n,dSellCountBuffer,INDICATOR_CALCULATIONS); n++;

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit2 ()
  {
//Delete the Bricks
   DeleteBricks();
   return (0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------------------------------------------------------+
int start() {return(mystart()); }
//+------------------------------------------------------------------------------------------------------------------+
int mystart()
  {
   if (show_data)
      {
        if(recalc) 
        {
           // If a button goes from off-to-on, everything must be recalculated.  The 'recalc' variable is used as a trigger to do this.
           recalc=false;
        }
        int limit;
        string sMsg,sSubject;
        bool bBuy=false,bSell=false;

        ArraySetAsSeries(dTrendBuffer,true);
        ArraySetAsSeries(dSignalBuffer,true);
        ArraySetAsSeries(dBuyCountBuffer,true);
        ArraySetAsSeries(dSellCountBuffer,true);

        {
          limit = Bars-1;
          dLowR  = Low[limit];
          dOpenR = Open[limit];
          dtPrevTime=Time[limit];
        }

   for(int i=limit-1; i>=0; i--)
     {
      double dcheck=iRenkoSize*PipsPoint;
      switch(eRenkoMode)
        {
         case 0:
            bBuy=Close[i]>=dOpenR+dcheck;
            bSell=Close[i]<=dOpenR-dcheck;
            break;

         case 1:
            bBuy=High[i]>=dOpenR+dcheck;
            bSell=Low[i]<=dOpenR-dcheck;
            break;
        }

      if(bBuy)
        {
         dCloseR=NormalizeDouble(dOpenR,_Digits)+dcheck;
         if(ObjectFind(0,short_name+(string)Time[i])<0 && eRenkoMark==1)
            RectangleCreate(0,short_name+(string)Time[i],0,dtPrevTime,dOpenR,Time[i],dCloseR,cUpCandle,eRenkoStyle,iRenkoWidth,bFill,false,false,false,0);
         dOpenR=dCloseR;
         dtPrevTime=Time[i];
         dSellCounter=0; dSellCountBuffer[i]=dSellCounter;
         if(dTrendBuffer[i+1]!=OP_BUY)
           {
            dSignalBuffer[i]=OP_BUY;
            dTrendBuffer[i]=dSignalBuffer[i];
            dBuyCounter=1;  dBuyCountBuffer[i]=dBuyCounter;
            if(ObjectFind(0,short_name+(string)Time[i])<0 && eRenkoMark==2)
               ArrowCreate(0,short_name+(string)Time[i],0,Time[i],Low[i],233,ANCHOR_TOP,cUpCandle,eRenkoStyle,iRenkoWidth,false,false,false);
           }
         else
           {dBuyCounter++;     dBuyCountBuffer[i]=dBuyCounter;}
        }
      if(bSell)
        {
         dCloseR=NormalizeDouble(dOpenR,_Digits)-dcheck;
         if(ObjectFind(0,short_name+(string)Time[i])<0 && eRenkoMark==1)
            RectangleCreate(0,short_name+(string)Time[i],0,dtPrevTime,dOpenR,Time[i],dCloseR,cDwnCandle,eRenkoStyle,iRenkoWidth,bFill,false,false,false,0);
         dOpenR=dCloseR;
         dtPrevTime=Time[i];
         dBuyCounter=0;  dBuyCountBuffer[i]=dBuyCounter;
         if(dTrendBuffer[i+1]!=OP_SELL)
           {
            dSignalBuffer[i]=OP_SELL;
            dTrendBuffer[i]=dSignalBuffer[i];
            dSellCounter=1; dSellCountBuffer[i]=dSellCounter;
            if(ObjectFind(0,short_name+(string)Time[i])<0 && eRenkoMark==2)
               ArrowCreate(0,short_name+(string)Time[i],0,Time[i],High[i],234,ANCHOR_BOTTOM,cDwnCandle,eRenkoStyle,iRenkoWidth,false,false,false);
           }
         else
           {dSellCounter++;   dSellCountBuffer[i]=dSellCounter;}
        }

      if(dTrendBuffer[i]!=OP_BUY && dTrendBuffer[i]!=OP_SELL)
         dTrendBuffer[i]=dTrendBuffer[i+1];
      if(dBuyCountBuffer[i] == EMPTY_VALUE)
         dBuyCountBuffer[i] = dBuyCountBuffer[i+1];
      if(dSellCountBuffer[i] == EMPTY_VALUE)
         dSellCountBuffer[i] = dSellCountBuffer[i+1];
     }
//Alerts
   if(dSignalBuffer[0]==OP_BUY)
     {
      sMsg=indicator_name+" "+_Symbol+"\n "+"Buy Alert: "+
           "\n Time: "+TimeToString(TimeCurrent(),TIME_DATE|TIME_MINUTES)+
           "\n Current Chart Period: "+StringTime(_Period);
      sSubject=indicator_name+" "+_Symbol+" "+"Buy Alert - Current Chart Period: "+StringTime(_Period);
      SendAlert(bAlertM,bAlertS,bAlertE,sMsg,sSubject);
      dTrendBuffer[0]=OP_BUY;
     }
   if(dSignalBuffer[0]==OP_SELL)
     {
      sMsg=indicator_name+" "+_Symbol+"\n "+"Sell Alert: "
           "\n Time: "+TimeToString(TimeCurrent(),TIME_DATE|TIME_MINUTES)+
           "\n Current Chart Period: "+StringTime(_Period);
      sSubject=indicator_name+" "+_Symbol+" "+"Sell Alert - Current Chart Period: "+StringTime(_Period);
      SendAlert(bAlertM,bAlertS,bAlertE,sMsg,sSubject);
      dTrendBuffer[0]=OP_SELL;
     }
      } //if (show_data)  

//--- return value of prev_calculated for next call
   return(0);
  }
//+------------------------------------------------------------------+

double Get_PipsPoint()
  {
   double PP=(_Digits==5 || _Digits==3)?_Point*10:_Point;
   return (PP);
  }
//+------------------------------------------------------------------------------+
//| The following code is taken from:                                            |
//| https://docs.mql4.com/constants/objectconstants/enum_object/obj_rectangle    |
//+------------------------------------------------------------------------------+
bool RectangleCreate(const long            chart_ID=0,        // chart's ID
                     const string          name="Rectangle",  // rectangle name
                     const int             sub_window=0,      // subwindow index 
                     datetime              time1=0,           // first point time
                     double                price1=0,          // first point price
                     datetime              time2=0,           // second point time
                     double                price2=0,          // second point price
                     const color           clr=clrRed,        // rectangle color
                     const ENUM_LINE_STYLE style=STYLE_SOLID, // style of rectangle lines
                     const int             width=1,           // width of rectangle lines
                     const bool            fill=false,        // filling rectangle with color
                     const bool            back=false,        // in the background
                     const bool            selection=true,    // highlight to move
                     const bool            hidden=true,       // hidden in the object list
                     const long            z_order=0,         // priority for mouse click
                     const string          tooltip="Rectangle",// tooltip
                     const int             timeframes=OBJ_ALL_PERIODS) //show on timeframes)
  {

   ResetLastError();
//--- create a rectangle by the given coordinates
   if(!ObjectCreate(chart_ID,name,OBJ_RECTANGLE,sub_window,time1,price1,time2,price2))
     {
      Print(__FUNCTION__,
            ": failed to create a rectangle! Name: "+name+" Error code = ",GetLastError());
      return(false);
     }

   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
   ObjectSetInteger(chart_ID,name,OBJPROP_FILL,fill);
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
   ObjectSetString(chart_ID,name,OBJPROP_TOOLTIP,tooltip);
   ObjectSetInteger(chart_ID,name,OBJPROP_TIMEFRAMES,timeframes);

//--- successful execution
   return(true);
  }
//+------------------------------------------------------------------------------+
//| The following code is taken from:                                            |
//| https://docs.mql4.com/constants/objectconstants/enum_object/obj_arrow        |
//+------------------------------------------------------------------------------+
bool ArrowCreate(const long              chart_ID=0,           // chart's ID
                 const string            name="Arrow",         // arrow name
                 const int               sub_window=0,         // subwindow index
                 datetime                time=0,               // anchor point time
                 double                  price=0,              // anchor point price
                 const uchar             arrow_code=252,       // arrow code
                 const ENUM_ARROW_ANCHOR anchor=ANCHOR_BOTTOM, // anchor point position
                 const color             clr=clrRed,           // arrow color
                 const ENUM_LINE_STYLE   style=STYLE_SOLID,    // border line style
                 const int               width=3,              // arrow size
                 const bool              back=false,           // in the background
                 const bool              selection=true,       // highlight to move
                 const bool              hidden=true,          // hidden in the object list
                 const long              z_order=0,            // priority for mouse click
                 const string            tooltip="Arrow",      // tooltip
                 const int               timeframes=OBJ_ALL_PERIODS) //show on timeframes)                 
  {

//--- reset the error value
   ResetLastError();
//--- create an arrow
   if(!ObjectCreate(chart_ID,name,OBJ_ARROW,sub_window,time,price))
     {
      Print(__FUNCTION__,
            ": failed to create an arrow! Error code = ",GetLastError());
      return(false);
     }
   ObjectSetInteger(chart_ID,name,OBJPROP_ARROWCODE,arrow_code);
   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
   ObjectSetString(chart_ID,name,OBJPROP_TOOLTIP,tooltip);
   ObjectSetInteger(chart_ID,name,OBJPROP_TIMEFRAMES,timeframes);
//--- successful execution
   return(true);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool EditCreate(const long             chart_ID=0,               // chart's ID
                const string           name="Edit",              // object name
                const int              sub_window=0,             // subwindow index
                const int              x=0,                      // X coordinate
                const int              y=0,                      // Y coordinate
                const int              width=50,                 // width
                const int              height=18,                // height
                const string           text="Text",              // text
                const string           font="Arial",             // font
                const int              font_size=10,             // font size
                const ENUM_ALIGN_MODE  align=ALIGN_CENTER,       // alignment type
                const bool             read_only=false,          // ability to edit
                const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // chart corner for anchoring
                const color            clr=clrBlack,             // text color
                const color            back_clr=clrWhite,        // background color
                const color            border_clr=clrNONE,       // border color
                const bool             back=false,               // in the background
                const bool             selection=false,          // highlight to move
                const bool             hidden=true,              // hidden in the object list
                const long             z_order=0,                // priority for mouse click
                const string           tooltip="Edit",// tooltip
                const int              timeframes=OBJ_ALL_PERIODS) //show on timeframes                
  {
//--- reset the error value
   ResetLastError();
//--- create edit field
   if(!ObjectCreate(chart_ID,name,OBJ_EDIT,sub_window,0,0))
     {
      Print(__FUNCTION__,
            ": failed to create \"Edit\" object! Error code = ",GetLastError());
      return(false);
     }
//--- set object coordinates
   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
   ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);
   ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
   ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
   ObjectSetInteger(chart_ID,name,OBJPROP_ALIGN,align);
   ObjectSetInteger(chart_ID,name,OBJPROP_READONLY,read_only);
   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
   ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);
   ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,border_clr);
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
   ObjectSetString(chart_ID,name,OBJPROP_TOOLTIP,tooltip);
   ObjectSetInteger(chart_ID,name,OBJPROP_TIMEFRAMES,timeframes);
//--- successful execution
   return(true);
  }
//+------------------------------------------------------------------+
//|Delete Bricks                                                     |
//+------------------------------------------------------------------+
void DeleteBricks()
  {
   for(int i=ObjectsTotal()-1; i>=0; i--)
     {
      string name=ObjectName(i);
      if(StringFind(name,short_name,0)>=0) ObjectDelete(0,name);
     }

   return;
  }
//+------------------------------------------------------------------+
//| Send Alerts                                                      |
//+------------------------------------------------------------------+
void SendAlert(bool bMobile,bool bScreen,bool bEmail,string sMsg,string sSub)
  {
   if(bMobile || bScreen || bEmail)
     {
      if(sMsg!="")
        {
         if(prevTime<iTime(_Symbol,_Period,0))
           {
            prevTime=iTime(_Symbol,_Period,0);
            if(bMobile) SendNotification(sSub);
            if(bScreen) Alert(sSub);
            if(bEmail) SendMail(sSub,sMsg);
           }
        }
     }
  }
//+------------------------------------------------------------------+
string StringTime(int iTimeSeek)
  {
   string sTime="";

   switch(iTimeSeek)
     {
      case 1: sTime = "PERIOD_M1"; break;
      case 2: sTime = "PERIOD_M2"; break;
      case 3: sTime = "PERIOD_M3"; break;
      case 4: sTime = "PERIOD_M4"; break;
      case 5: sTime = "PERIOD_M5"; break;
      case 6: sTime = "PERIOD_M6"; break;
      case 10: sTime = "PERIOD_M10"; break;
      case 12: sTime = "PERIOD_M12"; break;
      case 15: sTime = "PERIOD_M15"; break;
      case 20: sTime = "PERIOD_M20"; break;
      case 30: sTime = "PERIOD_M30"; break;
      case 60: sTime = "PERIOD_H1"; break;
      case 120: sTime = "PERIOD_H2"; break;
      case 180: sTime = "PERIOD_H3"; break;
      case 240: sTime = "PERIOD_H4"; break;
      case 360: sTime = "PERIOD_H6"; break;
      case 480: sTime = "PERIOD_H8"; break;
      case 720: sTime = "PERIOD_H12"; break;
      case 1440: sTime= "PERIOD_D1"; break;
      case 10080: sTime = "PERIOD_W1"; break;
      case 43200: sTime = "PERIOD_MN1"; break;
     }
   return(sTime);
  }
//+------------------------------------------------------------------+
