//+------------------------------------------------------------------+
//|                                             weekly_open_line.mq4 |
//|                                    Copyright © 2008, NuckingFuts |
//+------------------------------------------------------------------+
//mod Monthly
#property indicator_chart_window
#property copyright "Copyright © 2008, NuckingFuts"
#property link      "www.forexfactory.com"

extern color   MonthlyOpen_Color           = Gray;
extern string  MonthlyOpen_Style           = "DASH";
extern int     MonthlyOpen_Width           = 1;
extern string  MonthlyOpen_Label           = "Monthly Open Line";
extern int     MonthlyOpen_Label_Offset    = 50;
extern string  MonthlyOpen_Label_Font      = "Arial";
extern int     MonthlyOpen_Label_Font_Size = 8;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
	// Stop out of bounds array
	if (MonthlyOpen_Label_Offset < 0) MonthlyOpen_Label_Offset = 0;
	
	// Only the style SOLID width can be greater than 1 
	if (MonthlyOpen_Style != "SOLID" && MonthlyOpen_Width > 1)
	  MonthlyOpen_Width = 1;
	
	return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
	// Delete lines
	ObjectDelete("Monthly_Open_Line");
	ObjectDelete("MO_Label");
	return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   // Current weekly bar open price
   double wo = iOpen(NULL, PERIOD_MN1, 0);
   
   // Weekly open line
   ObjectCreate("Monthly_Open_Line", OBJ_HLINE, 0, Time[0], wo);
   ObjectSet("Monthly_Open_Line", OBJPROP_COLOR, MonthlyOpen_Color);
   ObjectSet("Monthly_Open_Line", OBJPROP_STYLE, GetLineStyle());
   ObjectSet("Monthly_Open_Line", OBJPROP_WIDTH, MonthlyOpen_Width);
   
   // Monthly open label
   ObjectCreate("MO_Label", OBJ_TEXT, 0, Time[MonthlyOpen_Label_Offset], wo);
   ObjectSetText("MO_Label", 
                 MonthlyOpen_Label, 
                 MonthlyOpen_Label_Font_Size, 
                 MonthlyOpen_Label_Font, 
                 MonthlyOpen_Color);
   return (0);
}
//+------------------------------------------------------------------+
//| GetLineStyle int                                                 |
//+------------------------------------------------------------------+
int GetLineStyle()
{
   int ls = 0;
   string stylearray[5] = {"SOLID", "DASH", "DOT", "DASHDOT", "DASHDOTDOT"};
   
   if (MonthlyOpen_Style == stylearray[1])      ls = 1;
   else if (MonthlyOpen_Style == stylearray[2]) ls = 2;
   else if (MonthlyOpen_Style == stylearray[3]) ls = 3;
   else if (MonthlyOpen_Style == stylearray[4]) ls = 4;
   return(ls);
}
//+------------------------------------------------------------------+