//+------------------------------------------------------------------+
//|                                              mn Period Boxess    +                
//+------------------------------------------------------------------+

#property indicator_chart_window
#property copyright "mn"

extern int   mNmbOfBoxes = 10, mWidth = 2;
extern color mCol1 = Blue;   
extern bool  mFilledBox = false;      
extern int   mPeriod = 10080;   // 43200, 10080, 1440, 240
            
double mData[][6];
int mTime, mArrSize;   
//-------------------------------------------------------- 
int init()
  {
   ArrayCopyRates(mData, Symbol(), mPeriod);
   mArrSize = ArraySize(mData);
   
   return(0);
  }
  
//-------------------------------------------------------- 
int deinit()
  {
   DeleteObjects();

   return(0);
  }

//--------------------------------------------------------- 
int start()
 {
  if(Time[0] > mTime)
  {
   DeleteObjects();
   for(int i = mArrSize; i >= 0; i--)
    {
     mDrawBoxes(i);
    }
    mTime = Time[0];
   }

   return(0);
}

//--------------------------------------------------------
void mDrawBoxes(int j)
 {
  int mT1Adj = 0, mPrdOpen;

  if(j <= mNmbOfBoxes)
   {
     mPrdOpen = mData[j][0];
    if(mPeriod > 1000)
       {
        while((TimeDayOfWeek(mPrdOpen) == 6 || TimeDayOfWeek(mPrdOpen) == 0))
          mPrdOpen += (Period() * 60);
       }
 
     ObjectSet("mBox"+(j+1), OBJPROP_TIME2, mPrdOpen+5);
     ObjectCreate("mBox"+j, OBJ_RECTANGLE, 0, 0, 0, 0);
     ObjectSet("mBox"+j, OBJPROP_PRICE1, mData[j][3]);
     ObjectSet("mBox"+j, OBJPROP_PRICE2, mData[j][2]);
     ObjectSet("mBox"+j, OBJPROP_TIME1, mPrdOpen+5);
     if(j > 0)
       ObjectSet("mBox"+j, OBJPROP_TIME2, mData[j-1][0]);
     else
       ObjectSet("mBox"+j, OBJPROP_TIME2, Time[0]);
     ObjectSet("mBox"+j, OBJPROP_COLOR, mCol1);
     ObjectSet("mBox"+j, OBJPROP_WIDTH, mWidth);
     if(mFilledBox)
       ObjectSet("mBox"+j, OBJPROP_BACK, true);
     else
       ObjectSet("mBox"+j, OBJPROP_BACK, false);
   }
     
   return(0);
 }
 
//--------------------------------------------------------
void DeleteObjects()
 {
   string mObj;
   for(int m = ObjectsTotal()-1; m >= 0; m--)
    {
      mObj = ObjectName(m);
      if (StringFind(mObj,"mBox", 0) > -1)
       ObjectDelete(mObj);
    }
  }
//+------------------------------------------------------------------+

