//+------------------------------------------------------------------+
//|                                   mpurdy_RangeStatsIndicator.mq4 |
//|                                                    Matthew Purdy |
//|                                      mailto:mpurdy1973@yahoo.com |
//+------------------------------------------------------------------+
#property copyright "Matthew Purdy"
#property link      "mailto:mpurdy1973@yahoo.com"

#define MAX_OBJECTS 100
#define SUNDAY 0

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Black

//---- input parameters
extern int ExtLocation       = 1;
extern int ExtXPos           = 5;
extern int ExtYPos           = 5;
extern int ExtYDelta         = 15;
extern color ExtDailyColor   = Gold;
extern color ExtWeeklyColor  = SkyBlue;
extern color ExtMonthlyColor = LightGreen;
extern int ExtFontSize       = 10;
extern string ExtFont        = "Courier New";

//---- buffers
double ExtMapBuffer1_Range[];

//---- global variables
bool glob_bFirstTime = true;
string glob_objectArray[MAX_OBJECTS];
int glob_objectArrayCount = 0;

double glob_range              = 0.0;
double glob_lastRange          = 0.0;
double glob_range30            = 0.0;
double glob_range100           = 0.0;
double glob_range200           = 0.0;
double glob_highestHigh        = 0.0;
double glob_lowestLow          = 1000.0;
double glob_priceToLowPercent  = 0.0;
double glob_priceToHighPercent = 0.0;
double glob_fiftyPercent       = 0.0;
double glob_lastHigh           = 0.0;
double glob_lastLow            = 0.0;
double glob_lastFiftyPercent   = 0.0;

double glob_weeklyRange              = 0.0;
double glob_lastWeekRange            = 0.0;
double glob_weeklyHighestHigh        = 0.0;
double glob_weeklyLowestLow          = 1000.0;
double glob_weeklyPriceToLowPercent  = 0.0;
double glob_weeklyPriceToHighPercent = 0.0;
double glob_weeklyFiftyPercent       = 0.0;
double glob_lastWeekHigh             = 0.0;
double glob_lastWeekLow              = 0.0;
double glob_lastWeekFiftyPercent     = 0.0;


double glob_monthlyRange              = 0.0;
double glob_lastMonthRange            = 0.0;
double glob_monthlyHighestHigh        = 0.0;
double glob_monthlyLowestLow          = 1000.0;
double glob_monthlyPriceToLowPercent  = 0.0;
double glob_monthlyPriceToHighPercent = 0.0;
double glob_monthlyFiftyPercent       = 0.0;
double glob_lastMonthHigh             = 0.0;
double glob_lastMonthLow              = 0.0;
double glob_lastMonthFiftyPercent     = 0.0;

double glob_test = 0.0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   //---- indicators
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, ExtMapBuffer1_Range);
   SetIndexLabel(0, "range");
   return(0);
   
}//end function init
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
   deleteAllObjects();
   
   return(0);
   
}//end function deinit
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   double total = 0.0;
   
   double high  = 0.0;
   double low   = 0.0;
   double range = 0.0;
   int highPos  = 0;
   int lowPos   = 0;
   
   //do first time and every sixth hour
   if(glob_bFirstTime || (TimeHour(Time[0]) % 2 == 1 && TimeMinute(Time[0]) == 0))
      calculateStaticRanges();
   
   high = High[0];
   low  = Low[0];
   
   if(TimeDayOfWeek(Time[0]) == SUNDAY)
   {
//Print("today is Sunday");
      double friHigh = iHigh(NULL, PERIOD_D1, 1);
      double friLow  = iLow(NULL, PERIOD_D1, 1);
//Print("high = " + high + ", low = " + low);     
      high = MathMax(friHigh, high);
      low  = MathMin(friLow, low);
//Print("high = " + high + ", low = " + low); 

   }//end if Sunday - concat price range with previous friday  
   
   if(high > glob_highestHigh || low < glob_lowestLow)
      calculateNewRange();

   glob_priceToLowPercent = ((Close[0] - glob_lowestLow) / (glob_range * Point)) * 100;
   glob_priceToHighPercent = ((glob_highestHigh - Close[0]) / (glob_range * Point)) * 100;
   glob_weeklyPriceToLowPercent = ((Close[0] - glob_weeklyLowestLow) / (glob_weeklyRange * Point)) * 100;
   glob_weeklyPriceToHighPercent = ((glob_weeklyHighestHigh - Close[0]) / (glob_weeklyRange * Point)) * 100;
   glob_monthlyPriceToLowPercent = ((Close[0] - glob_monthlyLowestLow) / (glob_monthlyRange * Point)) * 100;
   glob_monthlyPriceToHighPercent = ((glob_monthlyHighestHigh - Close[0]) / (glob_monthlyRange * Point)) * 100;

   ExtMapBuffer1_Range[0] = glob_range;
    
   if(glob_bFirstTime || (TimeHour(Time[0]) % 2 == 1 && TimeMinute(Time[0]) == 0))
   {
      glob_bFirstTime = false;
      draw();
   
   }//end if first time or every sixth hour
   else
      updateDraw();
   
   return(0);
   
}//end function start

//+------------------------------------------------------------------+
//| calculateStaticRanges                                            |
//+------------------------------------------------------------------+
void calculateStaticRanges()
{
   double high  = 0.0;
   double low   = 1000.0;
   double range = 0.0;
   double total = 0.0;
   
   int count = 0;
   int numOfPeriods = 300;
   for(int i = 1; i <= numOfPeriods; i++)
   {
      high  = iHigh(NULL, PERIOD_D1, i);
      low   = iLow(NULL, PERIOD_D1, i);
      
      datetime time = iTime(NULL, PERIOD_D1, i);
//if(i < 5)
//Print("calculateStaticRanges: time = " + TimeToStr(time) + ", day of week = " + TimeDayOfWeek(time));
      if(TimeDayOfWeek(time) == SUNDAY)
      {
//if(i < 5)
//Print("calculateStaticRanges: today is Sunday");
         double friHigh = iHigh(NULL, PERIOD_D1, i + 1);
         double friLow  = iLow(NULL, PERIOD_D1, i + 1);
         
         high = MathMax(friHigh, high);
         low  = MathMin(friLow, low);
         
         count--;
         total -= ((high - low) / Point);

      }//end if Sunday - concat price range with previous friday
      
      count++;
      range = (high - low) / Point;
     
      ExtMapBuffer1_Range[i] = range;
 
      total += range;
//if(i < 5)
//Print("i = " + i + ", count = " + count + ", high = " + high + ", low = " + low + ", range = " + range);
      if(i == 1)
      {
//Print("calculateStaticRanges: i = " + i);
         glob_lastRange = ((high - low) / Point);
         glob_lastHigh  = high;
         glob_lastLow   = low;
         glob_lastFiftyPercent = (MathRound(((glob_lastHigh + glob_lastLow) / 2.0) / Point) * Point);
//if(i < 5)
//Print("lastHigh = " + glob_lastHigh + ", lastLow = " + glob_lastLow + ", glob_lastRange = " + glob_lastRange);         
      }//end if yesterday 
    
      if(count == 30)
         glob_range30 = total / 30;
      
      if(count == 100)
         glob_range100 = total / 100;
         
      if(count == 200)
      {
         glob_range200 = total / 200;
         break;
         
      }//end if count equal 200
   
   }//end for the whole candle range
   
   //calculate weekly static ranges
   glob_lastWeekHigh         = iHigh(NULL, PERIOD_W1, 1);
   glob_lastWeekLow          = iLow(NULL, PERIOD_W1, 1);
   glob_lastWeekRange        = ((glob_lastWeekHigh - glob_lastWeekLow) / Point);
   glob_lastWeekFiftyPercent = (MathRound(((glob_lastWeekHigh + glob_lastWeekLow) / 2.0) / Point) * Point);

   //calculate monthly static ranges
   glob_lastMonthHigh         = iHigh(NULL, PERIOD_MN1, 1);
   glob_lastMonthLow          = iLow(NULL, PERIOD_MN1, 1);
   glob_lastMonthRange        = ((glob_lastMonthHigh - glob_lastMonthLow) / Point);
   glob_lastMonthFiftyPercent = (MathRound(((glob_lastMonthHigh + glob_lastMonthLow) / 2.0) / Point) * Point);

}//end function calculateStaticRanges
//--------------------------------------------------------------------

//+------------------------------------------------------------------+
//| caclulateNewRange                                                |
//+------------------------------------------------------------------+
void calculateNewRange()
{
   double high  = 0.0;
   double low   = 1000.0;
   double range = 0.0;
   
   //get current range
   high = iHigh(NULL, PERIOD_D1, 0); 
   low  = iLow(NULL, PERIOD_D1, 0);
   
   if(TimeDayOfWeek(Time[0]) == SUNDAY)
   {
//Print("today is Sunday");
      double friHigh = iHigh(NULL, PERIOD_D1, 1);
      double friLow  = iLow(NULL, PERIOD_D1, 1);
//Print("high = " + high + ", low = " + low);     
      high = MathMax(friHigh, high);
      low  = MathMin(friLow, low);
//Print("high = " + high + ", low = " + low); 

   }//end if Sunday - concat price range with previous friday 
   
   range      = high - low;
   glob_range = range / Point;
//Print("high = " + high + ", low = " + low + ", glob_highestHigh = " + glob_highestHigh + ", glob_lowestLow = " + glob_lowestLow + ", dif = " + (high - low)); 
   if(high > glob_highestHigh)
      glob_highestHigh = high;

   if(low < glob_lowestLow)
      glob_lowestLow = low;
//Print("high = " + high + ", low = " + low + ", glob_highestHigh = " + glob_highestHigh + ", glob_lowestLow = " + glob_lowestLow + ", dif = " + (high - low)); 
   glob_fiftyPercent = (MathRound(((high + low) / 2.0) / Point) * Point);
   
   ExtMapBuffer1_Range[0] = glob_range;
   
   if(glob_weeklyHighestHigh < glob_highestHigh || glob_weeklyLowestLow > glob_lowestLow)
      calculateNewWeeklyRange();
      
   if(glob_monthlyHighestHigh < glob_highestHigh || glob_monthlyLowestLow > glob_lowestLow)
      calculateNewMonthlyRange();

}//end function calculateNewRange
//--------------------------------------------------------------------

//+------------------------------------------------------------------+
//| caclulateNewRange                                                |
//+------------------------------------------------------------------+
void calculateNewWeeklyRange()
{
   double high  = 0.0;
   double low   = 1000.0;
   double range = 0.0;
   
   //get weekly range
   high = iHigh(NULL, PERIOD_W1, 0); 
   low  = iLow(NULL, PERIOD_W1, 0);

   range = high - low;
   glob_weeklyRange = range / Point;

   if(high > glob_weeklyHighestHigh)
      glob_weeklyHighestHigh = high;

   if(low < glob_weeklyLowestLow)
      glob_weeklyLowestLow = low;
   
   glob_weeklyFiftyPercent = (MathRound(((high + low) / 2.0) / Point) * Point);

}//end function calculateNewWeeklyRange
//--------------------------------------------------------------------

//+------------------------------------------------------------------+
//| calculateNewMonthlyRange                                         |
//+------------------------------------------------------------------+
void calculateNewMonthlyRange()
{
  double high  = 0.0;
   double low   = 1000.0;
   double range = 0.0;
   
   //get monthly range
   high = iHigh(NULL, PERIOD_MN1, 0); 
   low  = iLow(NULL, PERIOD_MN1, 0);

   range = high - low;
   glob_monthlyRange = range / Point;

   if(high > glob_monthlyHighestHigh)
      glob_monthlyHighestHigh = high;

   if(low < glob_monthlyLowestLow)
      glob_monthlyLowestLow = low;
   
   glob_monthlyFiftyPercent = (MathRound(((high + low) / 2.0) / Point) * Point);

}//end function calculateNewMonthlyRange

//--------------------------------------------------------------------

//+------------------------------------------------------------------+
//| draw                                                             |
//+------------------------------------------------------------------+
void draw()
{
   deleteAllObjects();

   int yCount = 0;

   ObjectCreate("currentRange", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("currentRange", "Range.......... " + DoubleToStr(glob_range, 0), ExtFontSize, ExtFont, ExtDailyColor);
   ObjectSet("currentRange", OBJPROP_CORNER, ExtLocation);
   ObjectSet("currentRange", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("currentRange", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;
   addObject("currentRange");

   ObjectCreate("lastRange", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("lastRange", "Yest Range..... " + DoubleToStr(glob_lastRange, 0), ExtFontSize, ExtFont, ExtDailyColor);
   ObjectSet("lastRange", OBJPROP_CORNER, ExtLocation);
   ObjectSet("lastRange", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("lastRange", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;
   addObject("lastRange");   

   ObjectCreate("range30", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("range30", "Range 30....... " + DoubleToStr(glob_range30, 0), ExtFontSize, ExtFont, ExtDailyColor);
   ObjectSet("range30", OBJPROP_CORNER, ExtLocation);
   ObjectSet("range30", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("range30", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;
   addObject("range30");

   ObjectCreate("range100", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("range100", "Range 100...... " + DoubleToStr(glob_range100, 0), ExtFontSize, ExtFont, ExtDailyColor);
   ObjectSet("range100", OBJPROP_CORNER, ExtLocation);
   ObjectSet("range100", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("range100", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;   
   addObject("range100");

   ObjectCreate("range200", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("range200", "Range 200...... " + DoubleToStr(glob_range200, 0), ExtFontSize, ExtFont, ExtDailyColor);
   ObjectSet("range200", OBJPROP_CORNER, ExtLocation);
   ObjectSet("range200", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("range200", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;  
   addObject("range200");

   ObjectCreate("lowPriceToRange", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("lowPriceToRange", "Low %......... " + DoubleToStr(glob_priceToLowPercent, 1), ExtFontSize, ExtFont, ExtDailyColor);
   ObjectSet("lowPriceToRange", OBJPROP_CORNER, ExtLocation);
   ObjectSet("lowPriceToRange", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("lowPriceToRange", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;  
   addObject("lowPriceToRange");

   ObjectCreate("highPriceToRange", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("highPriceToRange", "High %........ " + DoubleToStr(glob_priceToHighPercent, 1), ExtFontSize, ExtFont, ExtDailyColor);
   ObjectSet("highPriceToRange", OBJPROP_CORNER, ExtLocation);
   ObjectSet("highPriceToRange", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("highPriceToRange", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;   
   addObject("highPriceToRange");
   
   ObjectCreate("fiftyPercent", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("fiftyPercent", "50%......... " + DoubleToStr(glob_fiftyPercent, 4), ExtFontSize, ExtFont, ExtDailyColor);
   ObjectSet("fiftyPercent", OBJPROP_CORNER, ExtLocation);
   ObjectSet("fiftyPercent", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("fiftyPercent", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;   
   addObject("fiftyPercent");
   
   ObjectCreate("lastHigh", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("lastHigh", "Yest Hi..... " + DoubleToStr(glob_lastHigh, 4), ExtFontSize, ExtFont, ExtDailyColor);
   ObjectSet("lastHigh", OBJPROP_CORNER, ExtLocation);
   ObjectSet("lastHigh", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("lastHigh", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;
   addObject("lastHigh");
   
   ObjectCreate("lastLow", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("lastLow", "Yest Lo..... " + DoubleToStr(glob_lastLow, 4), ExtFontSize, ExtFont, ExtDailyColor);
   ObjectSet("lastLow", OBJPROP_CORNER, ExtLocation);
   ObjectSet("lastLow", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("lastLow", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;
   addObject("lastLow");
   
   ObjectCreate("lastFiftyPercent", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("lastFiftyPercent", "Yest 50%.... " + DoubleToStr(glob_lastFiftyPercent, 4), ExtFontSize, ExtFont, ExtDailyColor);
   ObjectSet("lastFiftyPercent", OBJPROP_CORNER, ExtLocation);
   ObjectSet("lastFiftyPercent", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("lastFiftyPercent", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;   
   addObject("lastFiftyPercent");     
   
   ObjectCreate("weeklyRange", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("weeklyRange", "Wk Range....... " + DoubleToStr(glob_weeklyRange, 0), ExtFontSize, ExtFont, ExtWeeklyColor);
   ObjectSet("weeklyRange", OBJPROP_CORNER, ExtLocation);
   ObjectSet("weeklyRange", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("weeklyRange", OBJPROP_YDISTANCE, ExtYPos+ (ExtYDelta * yCount));
   yCount++; 
   addObject("weeklyRange");

   ObjectCreate("weeklyLastRange", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("weeklyLastRange", "Last Wk ....... " + DoubleToStr(glob_lastWeekRange, 0), ExtFontSize, ExtFont, ExtWeeklyColor);
   ObjectSet("weeklyLastRange", OBJPROP_CORNER, ExtLocation);
   ObjectSet("weeklyLastRange", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("weeklyLastRange", OBJPROP_YDISTANCE, ExtYPos+ (ExtYDelta * yCount));
   yCount++; 
   addObject("weeklyLastRange");   

   ObjectCreate("weeklyLowPriceToRange", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("weeklyLowPriceToRange", "Wk Low %...... " + DoubleToStr(glob_weeklyPriceToLowPercent, 1), ExtFontSize, ExtFont, ExtWeeklyColor);
   ObjectSet("weeklyLowPriceToRange", OBJPROP_CORNER, ExtLocation);
   ObjectSet("weeklyLowPriceToRange", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("weeklyLowPriceToRange", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;  
   addObject("weeklyLowPriceToRange");

   ObjectCreate("weeklyHighPriceToRange", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("weeklyHighPriceToRange", "Wk High %..... " + DoubleToStr(glob_weeklyPriceToHighPercent, 1), ExtFontSize, ExtFont, ExtWeeklyColor);
   ObjectSet("weeklyHighPriceToRange", OBJPROP_CORNER, ExtLocation);
   ObjectSet("weeklyHighPriceToRange", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("weeklyHighPriceToRange", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;  
   addObject("weeklyHighPriceToRange");   
   
   ObjectCreate("weeklyFiftyPercent", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("weeklyFiftyPercent", "Wk 50%...... " + DoubleToStr(glob_weeklyFiftyPercent, 4), ExtFontSize, ExtFont, ExtWeeklyColor);
   ObjectSet("weeklyFiftyPercent", OBJPROP_CORNER, ExtLocation);
   ObjectSet("weeklyFiftyPercent", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("weeklyFiftyPercent", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;   
   addObject("weeklyFiftyPercent");
   
   ObjectCreate("lastWeekHigh", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("lastWeekHigh", "Last Wk Hi.. " + DoubleToStr(glob_lastWeekHigh, 4), ExtFontSize, ExtFont, ExtWeeklyColor);
   ObjectSet("lastWeekHigh", OBJPROP_CORNER, ExtLocation);
   ObjectSet("lastWeekHigh", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("lastWeekHigh", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;
   addObject("lastWeekHigh");
   
   ObjectCreate("lastWeekLow", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("lastWeekLow", "Last Wk Lo.. " + DoubleToStr(glob_lastWeekLow, 4), ExtFontSize, ExtFont, ExtWeeklyColor);
   ObjectSet("lastWeekLow", OBJPROP_CORNER, ExtLocation);
   ObjectSet("lastWeekLow", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("lastWeekLow", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;
   addObject("lastWeekLow");
   
   ObjectCreate("lastWeekFiftyPercent", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("lastWeekFiftyPercent", "Last Wk 50%. " + DoubleToStr(glob_lastWeekFiftyPercent, 4), ExtFontSize, ExtFont, ExtWeeklyColor);
   ObjectSet("lastWeekFiftyPercent", OBJPROP_CORNER, ExtLocation);
   ObjectSet("lastWeekFiftyPercent", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("lastWeekFiftyPercent", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;   
   addObject("lastWeekFiftyPercent");        
   
   ObjectCreate("monthlyRange", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("monthlyRange", "Mn Range....... " + DoubleToStr(glob_monthlyRange, 0), ExtFontSize, ExtFont, ExtMonthlyColor);
   ObjectSet("monthlyRange", OBJPROP_CORNER, ExtLocation);
   ObjectSet("monthlyRange", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("monthlyRange", OBJPROP_YDISTANCE, ExtYPos+ (ExtYDelta * yCount));
   yCount++; 
   addObject("monthlyRange");

   ObjectCreate("monthlyLastRange", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("monthlyLastRange", "Last Mn ....... " + DoubleToStr(glob_lastMonthRange, 0), ExtFontSize, ExtFont, ExtMonthlyColor);
   ObjectSet("monthlyLastRange", OBJPROP_CORNER, ExtLocation);
   ObjectSet("monthlyLastRange", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("monthlyLastRange", OBJPROP_YDISTANCE, ExtYPos+ (ExtYDelta * yCount));
   yCount++; 
   addObject("monthlyLastRange");   

   ObjectCreate("monthlyLowPriceToRange", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("monthlyLowPriceToRange", "Mn Low %...... " + DoubleToStr(glob_monthlyPriceToLowPercent, 1), ExtFontSize, ExtFont, ExtMonthlyColor);
   ObjectSet("monthlyLowPriceToRange", OBJPROP_CORNER, ExtLocation);
   ObjectSet("monthlyLowPriceToRange", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("monthlyLowPriceToRange", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;  
   addObject("monthlyLowPriceToRange");

   ObjectCreate("monthlyHighPriceToRange", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("monthlyHighPriceToRange", "Mn High %..... " + DoubleToStr(glob_monthlyPriceToHighPercent, 1), ExtFontSize, ExtFont, ExtMonthlyColor);
   ObjectSet("monthlyHighPriceToRange", OBJPROP_CORNER, ExtLocation);
   ObjectSet("monthlyHighPriceToRange", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("monthlyHighPriceToRange", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;  
   addObject("monthlyHighPriceToRange");   
   
   ObjectCreate("monthlyFiftyPercent", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("monthlyFiftyPercent", "Mn 50%...... " + DoubleToStr(glob_monthlyFiftyPercent, 4), ExtFontSize, ExtFont, ExtMonthlyColor);
   ObjectSet("monthlyFiftyPercent", OBJPROP_CORNER, ExtLocation);
   ObjectSet("monthlyFiftyPercent", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("monthlyFiftyPercent", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;   
   addObject("monthlyFiftyPercent");
   
   ObjectCreate("lastMonthHigh", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("lastMonthHigh", "Last Mn Hi.. " + DoubleToStr(glob_lastMonthHigh, 4), ExtFontSize, ExtFont, ExtMonthlyColor);
   ObjectSet("lastMonthHigh", OBJPROP_CORNER, ExtLocation);
   ObjectSet("lastMonthHigh", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("lastMonthHigh", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;
   addObject("lastMonthHigh");
   
   ObjectCreate("lastMonthLow", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("lastMonthLow", "Last Mn Lo.. " + DoubleToStr(glob_lastMonthLow, 4), ExtFontSize, ExtFont, ExtMonthlyColor);
   ObjectSet("lastMonthLow", OBJPROP_CORNER, ExtLocation);
   ObjectSet("lastMonthLow", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("lastMonthLow", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;
   addObject("lastMonthLow");
   
   ObjectCreate("lastMonthFiftyPercent", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("lastMonthFiftyPercent", "Last Mn 50%. " + DoubleToStr(glob_lastMonthFiftyPercent, 4), ExtFontSize, ExtFont, ExtMonthlyColor);
   ObjectSet("lastMonthFiftyPercent", OBJPROP_CORNER, ExtLocation);
   ObjectSet("lastMonthFiftyPercent", OBJPROP_XDISTANCE, ExtXPos);
   ObjectSet("lastMonthFiftyPercent", OBJPROP_YDISTANCE, ExtYPos + (ExtYDelta * yCount));
   yCount++;   
   addObject("lastMonthFiftyPercent"); 



}//end function draw
//--------------------------------------------------------------------

//+------------------------------------------------------------------+
//| updateDraw                                                       |
//+------------------------------------------------------------------+
void updateDraw()
{
   ObjectSetText("currentRange", "Range.......... " + DoubleToStr(glob_range, 0), ExtFontSize, ExtFont, ExtDailyColor);
   ObjectSetText("lowPriceToRange", "Low %......... " + DoubleToStr(glob_priceToLowPercent, 1), ExtFontSize, ExtFont, ExtDailyColor);
   ObjectSetText("highPriceToRange", "High %........ " + DoubleToStr(glob_priceToHighPercent, 1), ExtFontSize, ExtFont, ExtDailyColor);
   ObjectSetText("fiftyPercent", "50%......... " + DoubleToStr(glob_fiftyPercent, 4), ExtFontSize, ExtFont, ExtDailyColor);
   
   ObjectSetText("weeklyRange", "Wk Range....... " + DoubleToStr(glob_weeklyRange, 0), ExtFontSize, ExtFont, ExtWeeklyColor);   
   ObjectSetText("weeklyLowPriceToRange", "Wk Low %...... " + DoubleToStr(glob_weeklyPriceToLowPercent, 1), ExtFontSize, ExtFont, ExtWeeklyColor);
   ObjectSetText("weeklyHighPriceToRange", "Wk High %..... " + DoubleToStr(glob_weeklyPriceToHighPercent, 1), ExtFontSize, ExtFont, ExtWeeklyColor);
   ObjectSetText("weeklyFiftyPercent", "Wk 50%...... " + DoubleToStr(glob_weeklyFiftyPercent, 4), ExtFontSize, ExtFont, ExtWeeklyColor);
   
   ObjectSetText("monthlyRange", "Mn Range....... " + DoubleToStr(glob_monthlyRange, 0), ExtFontSize, ExtFont, ExtMonthlyColor);
   ObjectSetText("monthlyLowPriceToRange", "Mn Low %...... " + DoubleToStr(glob_monthlyPriceToLowPercent, 1), ExtFontSize, ExtFont, ExtMonthlyColor);   
   ObjectSetText("monthlyHighPriceToRange", "Mn High %..... " + DoubleToStr(glob_monthlyPriceToHighPercent, 1), ExtFontSize, ExtFont, ExtMonthlyColor);
   ObjectSetText("monthlyFiftyPercent", "Mn 50%...... " + DoubleToStr(glob_monthlyFiftyPercent, 4), ExtFontSize, ExtFont, ExtMonthlyColor);


}//end function updateDraw
//--------------------------------------------------------------------

//+------------------------------------------------------------------+
//| deleteAllObjects                                                 |
//+------------------------------------------------------------------+
void deleteAllObjects()
{
   for(int i = 0; i < glob_objectArrayCount; i++)
      ObjectDelete(glob_objectArray[i]);
      
   glob_objectArrayCount = 0;
      
}//end function deleteAllObjects
//--------------------------------------------------------------------

//+------------------------------------------------------------------+
//| addObject                                                        |
//+------------------------------------------------------------------+
void addObject(string sObj)
{
   if(glob_objectArrayCount <= MAX_OBJECTS)
   {
      glob_objectArray[glob_objectArrayCount] = sObj;
      glob_objectArrayCount++;
      
   }//end if room for more objects
      
}//end function deleteAllObjects
//--------------------------------------------------------------------


