#property copyright "Don Isbell"
#property link      "disbellj@gmail.com"

#property indicator_chart_window

extern int StartWeeksBack = 0;
extern bool FixMT4WeekStartBar = False;

int init() {

   Comment("");
  
   return(0);

}

int deinit() {

  Comment(""); 

   return(0);

}

int start() {

   datetime OpenTime =  iTime(NULL,PERIOD_W1,StartWeeksBack);

   int StartBar = iBarShift(NULL,0,OpenTime);

   datetime StartBarTime = iTime(NULL,0,StartBar);


   if(FixMT4WeekStartBar == True) {

      if(StartBarTime < OpenTime) {

         StartBar = iBarShift(NULL,0,OpenTime)-1;

         StartBarTime = iTime(NULL,0,StartBar);

      } else {

         StartBar = iBarShift(NULL,0,OpenTime);

         StartBarTime = iTime(NULL,0,StartBar);

      }
   }

   string value1;
   if(StartBarTime < OpenTime) value1 = "No"; else value1 = "Yes";

   Comment(
   "OpenTime = " + TimeToStr(OpenTime) + "\n" +
   "StartBarTime = " + TimeToStr(StartBarTime) + "\n" +
   "Is this right?  " + value1
   );
   
   return(0);
   
}