//+------------------------------------------------------------------+
//|                                                     ay-pivot.mq4 |
//|                              Copyright © 2010, aye.bdg@gmail.com |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, ahmad.yani@hotmail.com"
#property link      ""

#property indicator_chart_window
#define PREFIX  "AYPIVOT-"

extern int   DaysToPlot            = 1;
extern int   WeeksToPlot           = 1;
extern int   MonthsToPlot          = 1;
extern bool  PivotAtOpenPrice      = false;
extern bool  UseFibonacci          = true;
extern bool  ShowNextDayPivot      = false;
extern bool  ShowNextWeekPivot     = false;
extern bool  ShowNextMonthPivot    = false;
extern bool  ShowDesc              = true;
extern bool  ShowDailyPivotPrice   = false;
extern bool  ShowWeeklyPivotPrice  = True;
extern bool  ShowMonthlyPivotPrice = True;
extern color PriceColor            = MidnightBlue;
extern bool  PrintPivot            = false;

double dp[2], ds1[2], ds2[2], ds3[2], dr1[2], dr2[2], dr3[2];
double wp[2], ws1[2], ws2[2], ws3[2], wr1[2], wr2[2], wr3[2];
double mp[2], ms1[2], ms2[2], ms3[2], mr1[2], mr2[2], mr3[2];

//pivot for next day/week/month
double dnp, dns1, dns2, dns3, dnr1, dnr2, dnr3;
double wnp, wns1, wns2, wns3, wnr1, wnr2, wnr3;
double mnp, mns1, mns2, mns3, mnr1, mnr2, mnr3;

int ShiftLastBar = 3;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
  ArrayResize(dp,  DaysToPlot);
  ArrayResize(ds1, DaysToPlot);
  ArrayResize(ds2, DaysToPlot);
  ArrayResize(ds3, DaysToPlot);
  ArrayResize(dr1, DaysToPlot);
  ArrayResize(dr2, DaysToPlot);
  ArrayResize(dr3, DaysToPlot);
  
  ArrayResize(wp,  WeeksToPlot);
  ArrayResize(ws1, WeeksToPlot);
  ArrayResize(ws2, WeeksToPlot);
  ArrayResize(ws3, WeeksToPlot);
  ArrayResize(wr1, WeeksToPlot);
  ArrayResize(wr2, WeeksToPlot);
  ArrayResize(wr3, WeeksToPlot); 

  ArrayResize(mp,  MonthsToPlot);
  ArrayResize(ms1, MonthsToPlot);
  ArrayResize(ms2, MonthsToPlot);
  ArrayResize(ms3, MonthsToPlot);
  ArrayResize(mr1, MonthsToPlot);
  ArrayResize(mr2, MonthsToPlot);
  ArrayResize(mr3, MonthsToPlot);
  

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   int objs = ObjectsTotal();
   string name;
   for(int cnt=ObjectsTotal()-1;cnt>=0;cnt--)
   {
      name=ObjectName(cnt);
      if (StringSubstr(name,0,StringLen(PREFIX)) == PREFIX) ObjectDelete(name); 
      WindowRedraw();
   }     
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
    int i, counted_bars=IndicatorCounted();
      
    //udpate pivot data only at first time indicator started/restarted or if the new bar is new day    
    if (newDay())
    {
      calculatePivot(PERIOD_D1,  DaysToPlot);
      calculatePivot(PERIOD_W1,  WeeksToPlot);
      calculatePivot(PERIOD_MN1, MonthsToPlot);
    }
   
    //for (i=0; i<WeeksToPlot; i++)  Print ("WP" +i +": ", wp[i]);
    
    //update the object (line, text, etc) at first time indicator started/restarted or if the new bar formed
    if(!newBar()) return(0);
    
    if (ShowNextDayPivot)   calculateNextPivot(PERIOD_D1);
    if (ShowNextWeekPivot)  calculateNextPivot(PERIOD_W1);
    if (ShowNextMonthPivot) calculateNextPivot(PERIOD_MN1);
    
    //Finally Draw the line   
    drawPivotLine();
    
    datetime t = Time[0] + ShiftLastBar * 60 * Period();
    
    if (ShowDesc) showDesc(t);
//----
   
//----
   return(0);
}
  
void drawPivotLine()
{
    datetime TheBarTime;  //datetime of daily/weekly,monthly bar
    int      i, StartBarPer; //bar shift of TheBarTime at current Chart Timeframe
    datetime t1, t2;

    //Daily Pivot
    if (Period() < PERIOD_H4)
    {
      
      for (i=0; i<DaysToPlot; i++) 
      {
        TheBarTime =  iTime(NULL, PERIOD_D1, iBarShift( NULL, PERIOD_D1, Time[0],false) + i);
        StartBarPer = iBarShift(NULL, 0, TheBarTime);
        
        t1 = Time[StartBarPer];
        if (i==0) 
        {
          t2 = Time[0] + (ShiftLastBar+2) * 60 * Period();
          if (ShowDailyPivotPrice) drawFib(PREFIX+"DFibPrice", t2, dp[0], t2, ds3[0]);
        }
        else
          t2 = iTime(NULL, PERIOD_D1, iBarShift( NULL, PERIOD_D1, TheBarTime) - 1);
        
          
        DrawTl(PREFIX+ "DP-" + i, t1, dp[i],  t2, dp[i],  Chocolate, STYLE_SOLID, "Daily Pivot");
        DrawTl(PREFIX+ "DR1-"+ i, t1, dr1[i], t2, dr1[i], Green,     STYLE_SOLID, "Daily R1"); 
        DrawTl(PREFIX+ "DR2-"+ i, t1, dr2[i], t2, dr2[i], Green,     STYLE_SOLID, "Daily R2");
        DrawTl(PREFIX+ "DR3-"+ i, t1, dr3[i], t2, dr3[i], Green,     STYLE_SOLID, "Daily R3");
        DrawTl(PREFIX+ "DS1-"+ i, t1, ds1[i], t2, ds1[i], Maroon,    STYLE_SOLID, "Daily S1");
        DrawTl(PREFIX+ "DS2-"+ i, t1, ds2[i], t2, ds2[i], Maroon,    STYLE_SOLID, "Daily S2"); 
        DrawTl(PREFIX+ "DS3-"+ i, t1, ds3[i], t2, ds3[i], Maroon,    STYLE_SOLID, "Daily S3");
      }
      
      if (ShowNextDayPivot)
      {
        t1 = Time[0]+ ShiftLastBar * 60 * Period();
        t2 = t1 + 50 * 60 * Period();  
        DrawTl(PREFIX+ "DP-" + "Next", t1, dnp,  t2, dnp,  Chocolate, STYLE_DOT, "Daily Pivot");
        DrawTl(PREFIX+ "DR1-"+ "Next", t1, dnr1, t2, dnr1, Green,     STYLE_DOT, "Daily R1"); 
        DrawTl(PREFIX+ "DR2-"+ "Next", t1, dnr2, t2, dnr2, Green,     STYLE_DOT, "Daily R2");
        DrawTl(PREFIX+ "DR3-"+ "Next", t1, dnr3, t2, dnr3, Green,     STYLE_DOT, "Daily R3");
        DrawTl(PREFIX+ "DS1-"+ "Next", t1, dns1, t2, dns1, Maroon,    STYLE_DOT, "Daily S1");
        DrawTl(PREFIX+ "DS2-"+ "Next", t1, dns2, t2, dns2, Maroon,    STYLE_DOT, "Daily S2"); 
        DrawTl(PREFIX+ "DS3-"+ "Next", t1, dns3, t2, dns3, Maroon,    STYLE_DOT, "Daily S3");              
      }
    }

    //Weekly Pivot
    if (Period() < PERIOD_D1)
    {      
      for (i=0; i<WeeksToPlot; i++) 
      {
        TheBarTime =  iTime(NULL, PERIOD_W1, iBarShift( NULL, PERIOD_W1, Time[0],false) + i);
        StartBarPer = iBarShift(NULL, 0, TheBarTime);
        
        t1 = Time[StartBarPer];
        if (i==0) 
        {
          t2 = Time[0] + (ShiftLastBar+4) * 60 * Period();
          if (ShowWeeklyPivotPrice) drawFib(PREFIX+"WFibPrice", t2, wp[0], t2, ws3[0]);
        }
        else
          t2 = iTime(NULL, PERIOD_W1, iBarShift( NULL, PERIOD_W1, TheBarTime) - 1);
        
          
        DrawTl(PREFIX+ "WP-" + i, t1, wp[i],  t2, wp[i],  Chocolate, STYLE_SOLID, "Weekly Pivot");
        DrawTl(PREFIX+ "WR1-"+ i, t1, wr1[i], t2, wr1[i], Green,     STYLE_SOLID, "Weekly R1"); 
        DrawTl(PREFIX+ "WR2-"+ i, t1, wr2[i], t2, wr2[i], Green,     STYLE_SOLID, "Weekly R2");
        DrawTl(PREFIX+ "WR3-"+ i, t1, wr3[i], t2, wr3[i], Green,     STYLE_SOLID, "Weekly R3");
        DrawTl(PREFIX+ "WS1-"+ i, t1, ws1[i], t2, ws1[i], Maroon,    STYLE_SOLID, "Weekly S1");
        DrawTl(PREFIX+ "WS2-"+ i, t1, ws2[i], t2, ws2[i], Maroon,    STYLE_SOLID, "Weekly S2"); 
        DrawTl(PREFIX+ "WS3-"+ i, t1, ws3[i], t2, ws3[i], Maroon,    STYLE_SOLID, "Weekly S3");
      }
      if (ShowNextWeekPivot)
      {
        t1 = Time[0]+ ShiftLastBar * 60 * Period();
        t2 = t1 + 50 * 60 * Period();  
        DrawTl(PREFIX+ "WP-" + "Next", t1, wnp,  t2, wnp,  Chocolate, STYLE_SOLID, "Daily Pivot");
        DrawTl(PREFIX+ "WR1-"+ "Next", t1, wnr1, t2, wnr1, Green,     STYLE_SOLID, "Daily R1"); 
        DrawTl(PREFIX+ "WR2-"+ "Next", t1, wnr2, t2, wnr2, Green,     STYLE_SOLID, "Daily R2");
        DrawTl(PREFIX+ "WR3-"+ "Next", t1, wnr3, t2, wnr3, Green,     STYLE_SOLID, "Daily R3");
        DrawTl(PREFIX+ "WS1-"+ "Next", t1, wns1, t2, wns1, Maroon,    STYLE_SOLID,    "Daily S1");
        DrawTl(PREFIX+ "WS2-"+ "Next", t1, wns2, t2, wns2, Maroon,    STYLE_SOLID,    "Daily S2"); 
        DrawTl(PREFIX+ "WS3-"+ "Next", t1, wns3, t2, wns3, Maroon,    STYLE_SOLID,    "Daily S3");              
      }      
      
    } 
    
    //Monthly Pivot
    if (Period() < PERIOD_MN1)
    {
      
      for (i=0; i<MonthsToPlot; i++) 
      {
        TheBarTime =  iTime(NULL, PERIOD_MN1, iBarShift( NULL, PERIOD_MN1, Time[0],false) + i);
        StartBarPer = iBarShift(NULL, 0, TheBarTime);
        
        t1 = Time[StartBarPer];
        if (i==0)
        { 
          t2 = Time[0] + (ShiftLastBar+16) * 60 * Period();
          if (ShowMonthlyPivotPrice) drawFib(PREFIX+"MFibPrice", t2, mp[0], t2, ms3[0]);
        }
        else
          t2 = iTime(NULL, PERIOD_MN1, iBarShift( NULL, PERIOD_MN1, TheBarTime) - 1);
        
          
        DrawTl(PREFIX+ "MP-" + i, t1, mp[i],  t2, mp[i],  Chocolate, STYLE_DASH, "Monthly Pivot");
        DrawTl(PREFIX+ "MR1-"+ i, t1, mr1[i], t2, mr1[i], Green,     STYLE_DASH, "Monthly R1"); 
        DrawTl(PREFIX+ "MR2-"+ i, t1, mr2[i], t2, mr2[i], Green,     STYLE_DASH, "Monthly R2");
        DrawTl(PREFIX+ "MR3-"+ i, t1, mr3[i], t2, mr3[i], Green,     STYLE_DASH, "Monthly R3");
        DrawTl(PREFIX+ "MS1-"+ i, t1, ms1[i], t2, ms1[i], Maroon,    STYLE_DASH, "Monthly S1");
        DrawTl(PREFIX+ "MS2-"+ i, t1, ms2[i], t2, ms2[i], Maroon,    STYLE_DASH, "Monthly S2"); 
        DrawTl(PREFIX+ "MS3-"+ i, t1, ms3[i], t2, ms3[i], Maroon,    STYLE_DASH, "Monthly S3");
      }
      if (ShowNextMonthPivot)
      {
        t1 = Time[0]+ ShiftLastBar * 60 * Period();
        t2 = t1 + 50 * 60 * Period();  
        DrawTl(PREFIX+ "MP-" + "Next", t1, mnp,  t2, mnp,  Chocolate, STYLE_DASH, "Daily Pivot");
        DrawTl(PREFIX+ "MR1-"+ "Next", t1, mnr1, t2, mnr1, Green,     STYLE_DASH, "Daily R1"); 
        DrawTl(PREFIX+ "MR2-"+ "Next", t1, mnr2, t2, mnr2, Green,     STYLE_DASH, "Daily R2");
        DrawTl(PREFIX+ "MR3-"+ "Next", t1, mnr3, t2, wnr3, Green,     STYLE_DASH, "Daily R3");
        DrawTl(PREFIX+ "MS1-"+ "Next", t1, mns1, t2, mns1, Maroon,    STYLE_DASH,    "Daily S1");
        DrawTl(PREFIX+ "MS2-"+ "Next", t1, mns2, t2, mns2, Maroon,    STYLE_DASH,    "Daily S2"); 
        DrawTl(PREFIX+ "MS3-"+ "Next", t1, mns3, t2, mns3, Maroon,    STYLE_DASH,    "Daily S3");              
      }       
    }    

}  
void calculatePivot(int Per, int BarCount)
  {
    double o, h, l, c;
    double p, s1, s2, s3, r1, r2, r3;
    
    int TheBar =  iBarShift( NULL, Per, Time[0],false)+1; //the bar of previous day/week/month;
    
    for (int i=0; i<BarCount; i++)
    {
      
      o = iOpen (NULL, Per, TheBar + i);
      h = iHigh (NULL, Per, TheBar + i);
      l = iLow  (NULL, Per, TheBar + i);
      c = iClose(NULL, Per, TheBar + i);
      
      if (PivotAtOpenPrice)
        p = iOpen (NULL, Per, TheBar + i - 1);
      else
        p  = NormalizeDouble((h+l+c)/3, Digits);
      
      if (UseFibonacci)
      {         
         r1 = NormalizeDouble(p + ((h-l) * 0.382), Digits);
         r2 = NormalizeDouble(p + ((h-l) * 0.618), Digits);
         r3 = NormalizeDouble(p + ((h-l) * 1.000), Digits);
         s1 = NormalizeDouble(p - ((h-l) * 0.382), Digits);         
         s2 = NormalizeDouble(p - ((h-l) * 0.618), Digits);         
         s3 = NormalizeDouble(p - ((h-l) * 1.000), Digits);      
      }else
      {
         r1 = NormalizeDouble((2*p)-l, Digits);
         s1 = NormalizeDouble((2*p)-h, Digits);
         r2 = NormalizeDouble(p+(h - l), Digits);
         s2 = NormalizeDouble(p-(h - l), Digits);
         r3 = NormalizeDouble((2*p)+(h-(2*l)), Digits);
         s3 = NormalizeDouble((2*p)-((2* h)-l), Digits);               
      }
      
      switch(Per)
      {
        case PERIOD_D1:
          dp[i]=p; ds1[i]=s1; ds2[i]=s2; ds3[i]=s3; dr1[i]=r1; dr2[i]=r2; dr3[i]=r3; 
          break;
        case PERIOD_W1:
          wp[i]=p; ws1[i]=s1; ws2[i]=s2; ws3[i]=s3; wr1[i]=r1; wr2[i]=r2; wr3[i]=r3;
          break;
        case PERIOD_MN1:
          mp[i]=p; ms1[i]=s1; ms2[i]=s2; ms3[i]=s3; mr1[i]=r1; mr2[i]=r2; mr3[i]=r3;
          break;
      }
      
      if (i==0 && PrintPivot)
      {
        string text;
        text = "Pivot " + getTfName(Per) + "(P,S1,S2,S3,R1,R2,R3)|" + p+","+s1+","+s2+","+s3+","+r1+","+r2+","+r3;
        Print(text);      
      }
    }  

  } 

void calculateNextPivot(int Per)
{
    double o, h, l, c;
    double p, s1, s2, s3, r1, r2, r3;
    
    int TheBar =  iBarShift( NULL, Per, Time[0],false); //the bar of Current day/week/month;
    
    o = iOpen (NULL, Per, TheBar);
    h = iHigh (NULL, Per, TheBar);
    l = iLow  (NULL, Per, TheBar);
    c = iClose(NULL, Per, TheBar);
    
    if (PivotAtOpenPrice) //use close price of Per TF
      p = c;
    else
      p  = NormalizeDouble((h+l+c)/3, Digits);
    
    if (UseFibonacci)
    {         
       r1 = NormalizeDouble(p + ((h-l) * 0.382), Digits);
       r2 = NormalizeDouble(p + ((h-l) * 0.618), Digits);
       r3 = NormalizeDouble(p + ((h-l) * 1.000), Digits);
       s1 = NormalizeDouble(p - ((h-l) * 0.382), Digits);         
       s2 = NormalizeDouble(p - ((h-l) * 0.618), Digits);         
       s3 = NormalizeDouble(p - ((h-l) * 1.000), Digits);      
    }else
    {
       r1 = NormalizeDouble((2*p)-l, Digits);
       s1 = NormalizeDouble((2*p)-h, Digits);
       r2 = NormalizeDouble(p+(h - l), Digits);
       s2 = NormalizeDouble(p-(h - l), Digits);
       r3 = NormalizeDouble((2*p)+(h-(2*l)), Digits);
       s3 = NormalizeDouble((2*p)-((2* h)-l), Digits);               
    }
    

    switch(Per)
    {
      case PERIOD_D1:
        dnp=p; dns1=s1; dns2=s2; dns3=s3; dnr1=r1; dnr2=r2; dnr3=r3;
        break;
      case PERIOD_W1:
        wnp=p; wns1=s1; wns2=s2; wns3=s3; wnr1=r1; wnr2=r2; wnr3=r3;
        break;
      case PERIOD_MN1:
        mnp=p; mns1=s1; mns2=s2; mns3=s3; mnr1=r1; mnr2=r2; mnr3=r3;
        break;
    }
    
    if (PrintPivot)
    {
      string text;
      text = "Next Pivot " + getTfName(Per) + "(P,S1,S2,S3,R1,R2,R3)|" + p+","+s1+","+s2+","+s3+","+r1+","+r2+","+r3;
      Print(text);
    }    

}
   
bool newBar()
{
   static datetime lastbar;
   datetime curbar = Time[0];
   if(lastbar!=curbar)
   {
      lastbar=curbar;
      return (true);
   }
   else
   {
      return(false);
   }
} 
  
bool newDay()
  {
    static int LastDay;
    int CurrDay = TimeDay(Time[0]);
    
    if(LastDay!=CurrDay)
    {
      LastDay=CurrDay;
      return (true);
    }
    else
    {
      return(false);
    }
    
  }
   
void DrawTl(string tlName, datetime t1, double v1, datetime t2, double v2, color tlColor, int style = STYLE_SOLID, string desc="")
{
   if(ObjectFind(tlName) != 0)
   {
      ObjectCreate(
            tlName
            , OBJ_TREND
            , 0
            , t1
            , v1
            , t2
            , v2
            );      
   }else
   {
      ObjectMove(tlName, 0, t1, v1);   
      ObjectMove(tlName, 1, t2, v2);
   }
   ObjectSet(tlName, OBJPROP_COLOR, tlColor);
   ObjectSet(tlName, OBJPROP_RAY, false);
   ObjectSet(tlName, OBJPROP_STYLE, style);
   ObjectSetText(tlName, desc);
}

void showDesc(datetime t)
{
  if (Period() < PERIOD_H4)
  {
    DrawText(PREFIX+"txtDP","DP",   t+4*60*Period(), dp[0],  Chocolate);
    DrawText(PREFIX+"txtDR1","DR1", t+4*60*Period(), dr1[0], Green);
    DrawText(PREFIX+"txtDR2","DR2", t+4*60*Period(), dr2[0], Green);
    DrawText(PREFIX+"txtDR3","DR3", t+4*60*Period(), dr3[0], Green);
    DrawText(PREFIX+"txtDS1","DS1", t+4*60*Period(), ds1[0], Maroon);
    DrawText(PREFIX+"txtDS2","DS2", t+4*60*Period(), ds2[0], Maroon);
    DrawText(PREFIX+"txtDS3","DS3", t+4*60*Period(), ds3[0], Maroon);
  }
  
  if (Period() < PERIOD_D1)
  {
    DrawText(PREFIX+"txtWP","WP",   t+8*60*Period(), wp[0],  Chocolate); 
    DrawText(PREFIX+"txtWR1","WR1", t+8*60*Period(), wr1[0], Green);
    DrawText(PREFIX+"txtWR2","WR2", t+8*60*Period(), wr2[0], Green);
    DrawText(PREFIX+"txtWR3","WR3", t+8*60*Period(), wr3[0], Green);
    DrawText(PREFIX+"txtWS1","WS1", t+8*60*Period(), ws1[0], Maroon);
    DrawText(PREFIX+"txtWS2","WS2", t+8*60*Period(), ws2[0], Maroon);
    DrawText(PREFIX+"txtWS3","WS3", t+8*60*Period(), ws3[0], Maroon);
  }
  
  if (Period() < PERIOD_MN1)
  { 
    DrawText(PREFIX+"txtMP","MP",   t+16*60*Period(), mp[0],  Chocolate);         
    DrawText(PREFIX+"txtMR1","MR1", t+16*60*Period(), mr1[0], Green);          
    DrawText(PREFIX+"txtMR2","MR2", t+16*60*Period(), mr2[0], Green);             
    DrawText(PREFIX+"txtMR3","MR3", t+16*60*Period(), mr3[0], Green);          
    DrawText(PREFIX+"txtMS1","MS1", t+16*60*Period(), ms1[0], Maroon);         
    DrawText(PREFIX+"txtMS2","MS2", t+16*60*Period(), ms2[0], Maroon);        
    DrawText(PREFIX+"txtMS3","MS3", t+16*60*Period(), ms3[0], Maroon); 
  }         
}

void DrawText(string txtName, string txt, datetime t1, double v1, color txtColor)
{
   
   if(ObjectFind(txtName) != 0)
      ObjectCreate(
            txtName
            , OBJ_TEXT
            , 0
            , t1
            , v1
            );      
   else
      ObjectMove(txtName, 0, t1, v1);   

   ObjectSetText(txtName,txt,8,"Arial Narrow", txtColor);
   
} 

void drawFib(string fibname, datetime t1, double v1, datetime t2, double v2)
{
  if(ObjectFind(fibname) != 0)
    ObjectCreate(fibname, OBJ_FIBO, 0, t1, v1, t2, v2);
  else
  {
    ObjectMove(fibname, 0, t1, v1);
    ObjectMove(fibname, 1, t2, v2);
  }
  
  ObjectSet(fibname, OBJPROP_RAY, false);
  ObjectSet(fibname, OBJPROP_COLOR, CLR_NONE);
  //Print(ObjectGet(fibname, OBJPROP_FIRSTLEVEL+1));
  ObjectSet(fibname, OBJPROP_LEVELCOLOR, PriceColor);
  ObjectSet(fibname, OBJPROP_LEVELSTYLE, STYLE_SOLID);
  ObjectSet(fibname, OBJPROP_FIBOLEVELS, 7);
  ObjectSet(fibname, OBJPROP_FIRSTLEVEL+1, 0.382);
  ObjectSet(fibname, OBJPROP_FIRSTLEVEL+2, 0.618);
  ObjectSet(fibname, OBJPROP_FIRSTLEVEL+3, 1.0);
  ObjectSet(fibname, OBJPROP_FIRSTLEVEL+4, 1.382);
  ObjectSet(fibname, OBJPROP_FIRSTLEVEL+5, 1.618);
  ObjectSet(fibname, OBJPROP_FIRSTLEVEL+6, 2);
  
  ObjectSetFiboDescription(fibname, 0, "%$");
  ObjectSetFiboDescription(fibname, 1, "%$");
  ObjectSetFiboDescription(fibname, 2, "%$");
  ObjectSetFiboDescription(fibname, 3, "%$");
  ObjectSetFiboDescription(fibname, 4, "%$");
  ObjectSetFiboDescription(fibname, 5, "%$");
  ObjectSetFiboDescription(fibname, 6, "%$");

  
}
string getTfName(int tf)
{
  string n;
  switch (tf)
  {
    case PERIOD_MN1:  
      n= "MN1"; break;
    case PERIOD_W1:   
      n= "W1";  break;
    case PERIOD_D1:   
      n= "D1";  break;
    case PERIOD_H4:   
      n= "H4";  break;
    case PERIOD_H1:   
      n= "H1";  break;
    case PERIOD_M30:  
      n= "M30"; break;
    case PERIOD_M15:   
      n= "M15";  break;
    case PERIOD_M5:   
      n= "M5";  break;
    case PERIOD_M1:   
      n= "M1";  break;   
  }
  
  return(n);
}   
//+------------------------------------------------------------------+