//+------------------------------------------------------------------+
//|                                             PriceChangeChart.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Marc Newlin"
#property link      "syntax@gmail.com"

#property indicator_chart_window

extern int candleSize = 500;

double openPrice = 0;
datetime openTime = 0;


int init()
{

}


int deinit()
{
   ObjectsDeleteAll(0, OBJ_RECTANGLE);
   return(0);
}


int start()
{

   int    countedBars=IndicatorCounted();
   
   int pos = Bars - countedBars - 1;
   int x = 0;
   
   while(pos>=0)
   {
      // Look for the week's opening bar, which starts on Monday 12am with FXDD
      if(TimeDay(Time[pos]) == 1 && TimeDay(Time[pos + 1]) > 1)
      {
         openPrice = Open[pos];
         openTime = Time[pos];
      }
      
      // Look for a complete Long rectangle
      if(High[pos] - openPrice >= candleSize * Point && openPrice != 0)
      {
         ObjectCreate("Long." + pos, OBJ_RECTANGLE, 0, openTime, openPrice, Time[pos], openPrice + candleSize * Point);
         ObjectSet("Long." + pos, OBJPROP_COLOR, Green);
         
         openPrice = openPrice + candleSize * Point;
         openTime = Time[pos];
      }
      
      // Look for a complete Short rectangle
      if(openPrice - Low[pos] >= candleSize * Point && openPrice != 0)
      {
         ObjectCreate("Short." + pos, OBJ_RECTANGLE, 0, openTime, openPrice, Time[pos], openPrice - candleSize * Point);
         ObjectSet("Short." + pos, OBJPROP_COLOR, Red);         
         
         openPrice = openPrice - candleSize * Point;
         openTime = Time[pos];         
      }      
   
      pos--; 
   }

   return(0);
}

