#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Chartreuse
#property indicator_color2 Magenta
#property indicator_color3 Aqua
//---- buffers
double monthlyopen[];
double weeklyopen[];
double line;
double m,w;
extern bool ShowPrice = TRUE;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
  
   SetIndexStyle(1,DRAW_LINE,1,2);
   SetIndexBuffer(1,weeklyopen);
      SetIndexStyle(2,DRAW_LINE,1,2);
   SetIndexBuffer(2,monthlyopen);
   
   string mopen, dopen, wopen;
   wopen = "Weekly Open";
   mopen = "Monthly Open";
   
   IndicatorShortName(mopen);
   IndicatorShortName(wopen);
   

   SetIndexLabel(1,wopen);
   SetIndexLabel(2,mopen);
   
   SetIndexDrawBegin(0,1);
   //SetIndexDrawBegin(1,1);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   //ObjectDelete("Weekly Open");

   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   int limit, i;
   string l_name_24;
   string l_name_32;
   string l_name_40;
//----
   if(counted_bars==0)
      {//0
       //d=Period();
       //if (d>240)return(-1);
       ObjectCreate("Weekly Open",OBJ_HLINE,0,0,0);
       ObjectCreate("Daily Open",OBJ_HLINE,0,0,0);
       ObjectCreate("Monthly Open",OBJ_HLINE,0,0,0);
       
      }//0
   
  
   if(counted_bars<0) return(-1);
   
   limit=(Bars-counted_bars)-1;
   
   for(i=limit; i>=0; i--)
      {//0
       if(1==TimeDayOfWeek(Time[i]) && 1!=TimeDayOfWeek(Time[i+1]))
         {//1
          w=Open[i];
          ObjectMove("Weekly Open",0,Time[i],line);
         }//2
       if (TimeDay(Time[i]) !=TimeDay(Time[i+1]))
         {//3
          
          m=Open[i];
          ObjectMove("Monthly Open",0,Time[i],line);
         }//3         
       weeklyopen[i]=w;
  
       monthlyopen[i]=m;
      }//0
   
if (ShowPrice) {
     
      l_name_32 = "Weekly Open";
      ObjectDelete(l_name_32);
      ObjectCreate(l_name_32, OBJ_ARROW, 0, 0, 0);
      ObjectSet(l_name_32, OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
      ObjectSet(l_name_32, OBJPROP_COLOR, Fuchsia);
      ObjectSet(l_name_32, OBJPROP_TIME1, Time[0]);
      ObjectSet(l_name_32, OBJPROP_PRICE1, weeklyopen[0]);
      l_name_40 = "Monthly Open";
      ObjectDelete(l_name_40);
      ObjectCreate(l_name_40, OBJ_ARROW, 0, 0, 0);
      ObjectSet(l_name_40, OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
      ObjectSet(l_name_40, OBJPROP_COLOR, Aqua);
      ObjectSet(l_name_40, OBJPROP_TIME1, Time[0]);
      ObjectSet(l_name_40, OBJPROP_PRICE1, monthlyopen[0]);

   }
      return(0);
  }
//+------------------------------------------------------------------+