//+------------------------------------------------------------------+
//|                                              Critical Levels.mq4 |
//+------------------------------------------------------------------+
//#property copyright "Copyright © 2011, David Louisson"
//#property link      "http://www.forexfactory.com/hanover"

#property indicator_chart_window

#include <hanover --- function header (np).mqh>

extern string     ParameterFile          = "NONE";
extern bool       TemplateSafe           = true;

extern string     NumDaysWeeksMonths     = "1,1,1";
extern color      ColorDailyHLs          = Gray;
extern color      ColorWeeklyHLs         = Silver;
extern color      ColorMonthlyHLs        = White;
extern string     DataTypes              = "OHLC";
extern string     ColorDailyPivotStd     = "DodgerBlue";
extern string     ColorWeeklyPivotStd    = "LimeGreen";
extern string     ColorMonthlyPivotStd   = "Aqua";
extern string     ColorDailyPivotFibo    = "";
extern string     ColorWeeklyPivotFibo   = "";
extern string     ColorMonthlyPivotFibo  = "";
extern string     ColorRoundNumbers      = "Red";
extern bool       Plot50Levels           = true;
extern bool       PlotLabels             = true;
extern string     MAsettings             = "EMA,10,20,50,100,200,D1=Orange";
extern string     FiboSettings           = "50,+0=Magenta,0,38.2,50,61.8,100";
extern int        LineStartPoint         = 2;
extern int        LineLength             = 15;
extern bool       ExtendLines            = false;
extern string     RefreshPeriod          = "+0";
extern string     Visibility             = "M1,M5,M15,M30,H1,H4,D1,W1,MN";
extern bool       ShowDescriptions       = true;

string   ccy, sym, IndiName, MAS[50], FS[50];
int      dig, tf, tmf, obj, vis, RefreshEveryXMins, spt, numDWM[3], nMAS, nFS, lookback, rev100;
double   spr, pnt, tickval, bidp, askp, minlot, lswap, sswap;
datetime prev_time;
bool     FirstTime;

//+------------------------------------------------------------------+
int init()  {
//+------------------------------------------------------------------+
  if (TemplateSafe)
    IndiName = "@CL-";
  else
    IndiName = NumberToStr(GetUniqueInt(),"'@CL-'Z6'-'");
    
  IndicatorShortName(IndiName);

  sym     = Symbol();
  ccy     = Symbol();
  tmf     = Period();
  bidp    = MarketInfo(ccy,MODE_BID);
  askp    = MarketInfo(ccy,MODE_ASK);
  pnt     = MarketInfo(ccy,MODE_POINT);
  dig     = MarketInfo(ccy,MODE_DIGITS);
  spr     = MarketInfo(ccy,MODE_SPREAD);
  tickval = MarketInfo(ccy,MODE_TICKVALUE);
  minlot  = MarketInfo(ccy,MODE_MINLOT);
  lswap   = MarketInfo(ccy,MODE_SWAPLONG);
  sswap   = MarketInfo(ccy,MODE_SWAPSHORT);
  if (dig == 3 || dig == 5) {
    pnt     *= 10;
    spr     /= 10;
    tickval *= 10;
  }  
  pnt = GetPipValue(sym);
  del_obj();
  plot_obj();

  return(0);
}

//+------------------------------------------------------------------+
int deinit()  {
//+------------------------------------------------------------------+
  del_obj();
  return(0);
}

//+------------------------------------------------------------------+
int start()  {
//+------------------------------------------------------------------+
  if (RefreshEveryXMins < 0)  {
    if (FirstTime)  {
      del_obj();
      plot_obj();
    }
    FirstTime = false;      
    return(0);
  }  
  if (RefreshEveryXMins == 0) {
    del_obj();
    plot_obj();    
  } else {
    if (prev_time != iTime(sym,RefreshEveryXMins,0))  {
      del_obj();
      plot_obj();
      prev_time = iTime(sym,RefreshEveryXMins,0);
  } }      
  return(0);
}

//+------------------------------------------------------------------+
void del_obj()  {
//+------------------------------------------------------------------+
  int k=0;
  while (k<ObjectsTotal())   {
    string objname = ObjectName(k);
    if (StringSubstr(objname,0,StringLen(IndiName)) == IndiName)  
      ObjectDelete(objname);
    else
      k++;
  }    
  return(0);
}

//+------------------------------------------------------------------+
void plot_line(double price, color clr, int width, int style, int start=0, bool label=false, string desc="")   {
//+------------------------------------------------------------------+
  obj++;
  string objname = IndiName + NumberToStr(obj,"Z4");
  ObjectCreate(objname,OBJ_TREND,0,Time[0]+start*60*Period(),price,Time[0]+(start+LineLength)*60*Period(),price);  
  ObjectSet(objname,OBJPROP_COLOR,clr);
  ObjectSet(objname,OBJPROP_WIDTH,width);
  ObjectSet(objname,OBJPROP_STYLE,style);
  ObjectSet(objname,OBJPROP_RAY,ExtendLines);
  ObjectSet(objname,OBJPROP_TIMEFRAMES,vis);
  if (ShowDescriptions)
    ObjectSetText(objname,desc,8,"Arial",Red);
  if (label && !ExtendLines)   {
    obj++;
    objname = IndiName + NumberToStr(obj,"Z4");
    ObjectCreate(objname,OBJ_ARROW,0,Time[0]+(start+LineLength+1)*60*Period(),price);  
    ObjectSet(objname,OBJPROP_COLOR,clr);
    ObjectSet(objname,OBJPROP_WIDTH,1);
    ObjectSet(objname,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
    ObjectSet(objname,OBJPROP_TIMEFRAMES,vis);
  }  
  return(0);
}

//+------------------------------------------------------------------+
void plot_fibo_lines()   {
//+------------------------------------------------------------------+
//  dd(nFS);
  if (nFS<2)    return(0);

  string arr1[2];
  lookback = MathAbs(StrToInteger(FS[0]));
  rev100   = MathSign(StrToInteger(FS[0]));

  for (int x=1; x<nFS; x++)   {
    int narr1 = StrToStringArray(FS[x],arr1,"=");
    if (IsAlpha(arr1[0],"1."))
      double x_type = -StrToNumber(arr1[0]);                                             // negative (or zero) if fibo level
    else
      x_type = StrToTF(arr1[0]);                                                         // positive if TF
    if (narr1>1)   {
      color c_color = StrToColor(ExtractAlpha(arr1[1],"Aa"));
      int   c_width = MathMax(1,StrToNumber(arr1[1]));
      int   c_style = STYLE_SOLID;
      if (c_width < 2)   c_style = StrToStyle((arr1[1]));
    }    
//    d("\nx=",x,FS[x],x_type,"["+arr1[0]+"]",arr1[1],c_color,c_width,c_style);
    for (int y=x+1; y<nFS; y++)   {
      narr1 = StrToStringArray(FS[y],arr1,"=");
      if (IsAlpha(arr1[0],"1."))
        double y_type = -StrToNumber(arr1[0]);
      else  
        y_type = StrToTF(arr1[0]);
      if (x_type*y_type > 0)   continue;                                                   // if same type (both pos, or both neg), then skip processing
      if (x_type*y_type == 0  &&  MathSign(x_type)+MathSign(y_type) < 0)   continue;       // if one value is zero, and the other negative, then both are fibo levels, hence skip processing
      if (narr1>1)   {
        c_color = StrToColor(ExtractAlpha(arr1[1],"Aa"));
        c_width = MathMax(1,StrToNumber(arr1[1]));
        c_style = STYLE_SOLID;
        if (c_width < 2)   c_style = StrToStyle((arr1[1]));
      }
      double c_fiblev = MathAbs(MathMin(x_type,y_type));
      int    c_TFper  = MathAbs(MathMax(x_type,y_type));
//      d("y=",y,FS[y],y_type,"["+arr1[0]+"]",arr1[1],c_fiblev,c_TFper,c_color,c_width,c_style);
      double fibprc   = get_fibo_value(c_TFper,c_fiblev);
      string descr    = TFToStr(c_TFper) + ": " + NumberToStr(c_fiblev,"'fib 'T-3.1");
      plot_line(fibprc,c_color,c_width,c_style,spt,false,descr);
  } }  

  return(0);
}

//+------------------------------------------------------------------+
double get_fibo_value(int tf, double level)   {
//+------------------------------------------------------------------+
  double zmax=0, zmin=999999, cmax=-1, cmin=-1;
  for (int i=0; i<=lookback; i++)   {
    double hi = iHigh(Symbol(),tf,i);
    double lo = iLow(Symbol(),tf,i);
    if (hi>zmax)   { zmax=hi; cmax=i; }
    if (lo<zmin)   { zmin=lo; cmin=i; }
  }  
  if ((cmax-cmin)*rev100 > 0)   
    double prc = (zmax-zmin)*level/100+zmin;
  else
    prc = (zmax-zmin)*(100-level)/100+zmin;
  return(prc);
}

//+------------------------------------------------------------------+
void plot_MA_lines()   {
//+------------------------------------------------------------------+
//  dd(nMAS);
  if (nMAS<2)    return(0);

  string arr1[2];
  string MAtypes[4] = {"SMA","EMA","SMMA","LWMA"};
  int    MAtype     = LookupStringArray(StringUpper(MAS[0]),MAtypes);

  for (int x=1; x<nMAS; x++)   {
    int narr1 = StrToStringArray(MAS[x],arr1,"=");
    if (IsAlpha(arr1[0],"1"))
      int x_type = -StrToNumber(arr1[0]);
    else
      x_type = StrToTF(arr1[0]);
    if (narr1>1)   {
      color c_color = StrToColor(ExtractAlpha(arr1[1],"Aa"));
      int   c_width = MathMax(1,StrToNumber(arr1[1]));
      int   c_style = STYLE_SOLID;
      if (c_width < 2)   c_style = StrToStyle((arr1[1]));
    }    
//    d("x=",x,MAS[x],x_type,"["+arr1[0]+"]",arr1[1],c_color,c_width,c_style);
    for (int y=x+1; y<nMAS; y++)   {
      narr1 = StrToStringArray(MAS[y],arr1,"=");
      if (IsAlpha(arr1[0],"1"))
        int y_type = -StrToNumber(arr1[0]);
      else  
        y_type = StrToTF(arr1[0]);
      if (x_type*y_type >= 0)   continue;
      if (narr1>1)   {
        c_color = StrToColor(ExtractAlpha(arr1[1],"Aa"));
        c_width = MathMax(1,StrToNumber(arr1[1]));
        c_style = STYLE_SOLID;
        if (c_width < 2)   c_style = StrToStyle((arr1[1]));
      }
      int c_MAper  = MathAbs(MathMin(x_type,y_type));
      int c_TFper  = MathAbs(MathMax(x_type,y_type));
//      d("y=",y,MAS[y],y_type,"["+arr1[0]+"]",arr1[1],c_MAper,c_TFper,c_color,c_width,c_style);
      double prc   = iMA(Symbol(),c_TFper,c_MAper,0,MAtype,PRICE_CLOSE,0);
      string descr = TFToStr(c_TFper) + ": " + MAS[0] + NumberToStr(c_MAper,"'('T6')'");
      plot_line(prc,c_color,c_width,c_style,spt,false,descr);
  } }  
  return(0);
}

//+------------------------------------------------------------------+
int StrToStyle(string str)   {
//+------------------------------------------------------------------+
  if (StringFind(str,"-..") >= 0)    return(STYLE_DASHDOTDOT);
  if (StringFind(str,"-.")  >= 0)    return(STYLE_DASHDOT);
  if (StringFind(str,"..")  >= 0)    return(STYLE_DOT);
  if (StringFind(str,"-")   >= 0)    return(STYLE_DASH);
  return(STYLE_SOLID);
}

//+------------------------------------------------------------------+
void plot_period_OHLC(int z, int perd, color colr, string desc)   {
//+------------------------------------------------------------------+
  string day = DateToStr(iTime(ccy,perd,z),"': 'w D n Y");
  if (StringFind(StringUpper(DataTypes),"H") >= 0)  {
    double value = iHigh(ccy,perd,z);
    string descr = desc + "high" + day; 
    plot_line(value,colr,1,STYLE_SOLID,spt,false,descr);
  }
  if (StringFind(StringUpper(DataTypes),"L") >= 0)  {
    value = iLow(ccy,perd,z);
    descr = desc + "low" + day; 
    plot_line(value,colr,1,STYLE_SOLID,spt,false,descr);
  }
  if (StringFind(StringUpper(DataTypes),"O") >= 0)  {
    value = iOpen(ccy,perd,z);
    descr = desc + "open" + day; 
    plot_line(value,colr,1,STYLE_SOLID,spt,false,descr);
  }
  if (StringFind(StringUpper(DataTypes),"C") >= 0)  {
    value = iClose(ccy,perd,z);
    descr = desc + "close" + day; 
    plot_line(value,colr,1,STYLE_SOLID,spt,false,descr);
  }
  return(0);
}

//+------------------------------------------------------------------+
void plot_obj()   {
//+------------------------------------------------------------------+
  CheckPresets();

  color col;
  double open, high, low, close;
  spt = LineStartPoint;
  // Daily, weekly, monthly highs/lows.......
  for (int i=1; i<=numDWM[0]; i++)                                 // daily
    plot_period_OHLC(i,StrToTF("D1"),ColorDailyHLs,"Daily ");
  for (i=1; i<=numDWM[1]; i++)                                     // weekly
    plot_period_OHLC(i,StrToTF("W1"),ColorWeeklyHLs,"Weekly ");
  for (i=1; i<=numDWM[2]; i++)                                     // monthly
    plot_period_OHLC(i,StrToTF("MN"),ColorMonthlyHLs,"Monthly ");
  
  // Daily pivot: standard.......
  if (ColorDailyPivotStd > "")   {
    col   = StrToColor(ColorDailyPivotStd);
    high  = iHigh(ccy,StrToTF("D1"),1);  
    low   = iLow(ccy,StrToTF("D1"),1);  
    close = iClose(ccy,StrToTF("D1"),1); 
    double PP = (high+low+close)/3;
    double S1 = 2*PP-high;
    double S2 = PP-(high-low);
    double S3 = 2*PP-(2*high-low);
    double R1 = 2*PP-low;
    double R2 = PP+(high-low);
    double R3 = 2*PP+(high-2*low);
    plot_line(PP,col,2,STYLE_SOLID,spt,false,"Daily Pivot (std)");
    plot_line(S1,col,1,STYLE_DOT,spt,false,"Daily S1 (std)");
    plot_line(S2,col,1,STYLE_DOT,spt,false,"Daily S2 (std)");
    plot_line(S3,col,1,STYLE_DOT,spt,false,"Daily S3 (std)");
    plot_line(R1,col,1,STYLE_DOT,spt,false,"Daily R1 (std)");
    plot_line(R2,col,1,STYLE_DOT,spt,false,"Daily R2 (std)");
    plot_line(R3,col,1,STYLE_DOT,spt,false,"Daily R3 (std)");
  }
  // Weekly pivot: standard.......
  if (ColorWeeklyPivotStd > "")   {
    col   = StrToColor(ColorWeeklyPivotStd);
    high  = iHigh(ccy,StrToTF("W1"),1);  
    low   = iLow(ccy,StrToTF("W1"),1);  
    close = iClose(ccy,StrToTF("W1"),1); 
    PP    = (high+low+close)/3;
    S1    = 2*PP-high;
    S2    = PP-(high-low);
    S3    = 2*PP-(2*high-low);
    R1    = 2*PP-low;
    R2    = PP+(high-low);
    R3    = 2*PP+(high-2*low);
    plot_line(PP,col,1,STYLE_SOLID,spt+2,false,"Weekly Pivot (std)");
    plot_line(S1,col,1,STYLE_DOT,spt+2,false,"Weekly S1 (std)");
    plot_line(S2,col,1,STYLE_DOT,spt+2,false,"Weekly S2 (std)");
    plot_line(S3,col,1,STYLE_DOT,spt+2,false,"Weekly S3 (std)");
    plot_line(R1,col,1,STYLE_DOT,spt+2,false,"Weekly R1 (std)");
    plot_line(R2,col,1,STYLE_DOT,spt+2,false,"Weekly R2 (std)");
    plot_line(R3,col,1,STYLE_DOT,spt+2,false,"Weekly R3 (std)");
  }
  // Monthly pivot: standard.......
  if (ColorMonthlyPivotStd > "")   {
    col   = StrToColor(ColorMonthlyPivotStd);
    high  = iHigh(ccy,StrToTF("MN"),1);  
    low   = iLow(ccy,StrToTF("MN"),1);  
    close = iClose(ccy,StrToTF("MN"),1); 
    PP    = (high+low+close)/3;
    S1    = 2*PP-high;
    S2    = PP-(high-low);
    S3    = 2*PP-(2*high-low);
    R1    = 2*PP-low;
    R2    = PP+(high-low);
    R3    = 2*PP+(high-2*low);
    plot_line(PP,col,1,STYLE_SOLID,spt+4,false,"Monthly Pivot (std)");
    plot_line(S1,col,1,STYLE_DOT,spt+4,false,"Monthly S1 (std)");
    plot_line(S2,col,1,STYLE_DOT,spt+4,false,"Monthly S2 (std)");
    plot_line(S3,col,1,STYLE_DOT,spt+4,false,"Monthly S3 (std)");
    plot_line(R1,col,1,STYLE_DOT,spt+4,false,"Monthly R1 (std)");
    plot_line(R2,col,1,STYLE_DOT,spt+4,false,"Monthly R2 (std)");
    plot_line(R3,col,1,STYLE_DOT,spt+4,false,"Monthly R3 (std)");
  }
  // Daily pivot: Fibo.......
  if (ColorDailyPivotFibo > "")   {
    col   = StrToColor(ColorDailyPivotFibo);
    high  = iHigh(ccy,StrToTF("D1"),1);  
    low   = iLow(ccy,StrToTF("D1"),1);  
    close = iClose(ccy,StrToTF("D1"),1); 
    PP    = (high+low+close)/3;
    S1    = PP-(high-low)*0.382;
    S2    = PP-(high-low)*0.618;
    S3    = PP-(high-low);
    R1    = PP+(high-low)*0.382;
    R2    = PP+(high-low)*0.618;
    R3    = PP+(high-low);
    plot_line(PP,col,2,STYLE_SOLID,spt,false,"Daily Pivot (fibo)");
    plot_line(S1,col,1,STYLE_DOT,spt,false,"Daily S1 (fibo)");
    plot_line(S2,col,1,STYLE_DOT,spt,false,"Daily S2 (fibo)");
    plot_line(S3,col,1,STYLE_DOT,spt,false,"Daily S3 (fibo)");
    plot_line(R1,col,1,STYLE_DOT,spt,false,"Daily R1 (fibo)");
    plot_line(R2,col,1,STYLE_DOT,spt,false,"Daily R2 (fibo)");
    plot_line(R3,col,1,STYLE_DOT,spt,false,"Daily R3 (fibo)");
  }
  // Weekly pivot: Fibo.......
  if (ColorWeeklyPivotFibo > "")   {
    col   = StrToColor(ColorWeeklyPivotFibo);
    high  = iHigh(ccy,StrToTF("W1"),1);  
    low   = iLow(ccy,StrToTF("W1"),1);  
    close = iClose(ccy,StrToTF("W1"),1); 
    PP    = (high+low+close)/3;
    S1    = PP-(high-low)*0.382;
    S2    = PP-(high-low)*0.618;
    S3    = PP-(high-low);
    R1    = PP+(high-low)*0.382;
    R2    = PP+(high-low)*0.618;
    R3    = PP+(high-low);
    plot_line(PP,col,1,STYLE_SOLID,spt+2,false,"Weekly Pivot (fibo)");
    plot_line(S1,col,1,STYLE_DOT,spt+2,false,"Weekly S1 (fibo)");
    plot_line(S2,col,1,STYLE_DOT,spt+2,false,"Weekly S2 (fibo)");
    plot_line(S3,col,1,STYLE_DOT,spt+2,false,"Weekly S3 (fibo)");
    plot_line(R1,col,1,STYLE_DOT,spt+2,false,"Weekly R1 (fibo)");
    plot_line(R2,col,1,STYLE_DOT,spt+2,false,"Weekly R2 (fibo)");
    plot_line(R3,col,1,STYLE_DOT,spt+2,false,"Weekly R3 (fibo)");
  }
  // Monthly pivot: Fibo.......
  if (ColorMonthlyPivotFibo > "")   {
    col   = StrToColor(ColorMonthlyPivotFibo);
    high  = iHigh(ccy,StrToTF("MN"),1);  
    low   = iLow(ccy,StrToTF("MN"),1);  
    close = iClose(ccy,StrToTF("MN"),1); 
    PP    = (high+low+close)/3;
    S1    = PP-(high-low)*0.382;
    S2    = PP-(high-low)*0.618;
    S3    = PP-(high-low);
    R1    = PP+(high-low)*0.382;
    R2    = PP+(high-low)*0.618;
    R3    = PP+(high-low);
    plot_line(PP,col,1,STYLE_SOLID,spt+4,false,"Monthly Pivot (fibo)");
    plot_line(S1,col,1,STYLE_DOT,spt+4,false,"Monthly S1 (fibo)");
    plot_line(S2,col,1,STYLE_DOT,spt+4,false,"Monthly S2 (fibo)");
    plot_line(S3,col,1,STYLE_DOT,spt+4,false,"Monthly S3 (fibo)");
    plot_line(R1,col,1,STYLE_DOT,spt+4,false,"Monthly R1 (fibo)");
    plot_line(R2,col,1,STYLE_DOT,spt+4,false,"Monthly R2 (fibo)");
    plot_line(R3,col,1,STYLE_DOT,spt+4,false,"Monthly R3 (fibo)");
  }
  // Round numbers........
  string mask = "'Price = 'T3.5";
  if (StringFind(Symbol(),"JPY") > 0)    mask = "'Price = 'T4.3";
  if (ColorRoundNumbers > "")   {
    col   = StrToColor(ColorRoundNumbers);
    bool   flag  = false;
//    double start = (WindowPriceMax()+WindowPriceMin())/2;
    double start = Bid;
    double incr  = 50*pnt;
    start = incr*MathInt(start/incr+0.5); 
//    log("---",start,incr);
    for (i=0; flag==false; i++)   {
      high = start+i*incr;
      PP   = (2*incr)*MathInt(high/(2*incr));
//      log("H",i,high,PP);
      if (MathAbs(high-PP)<0.00001) 
        plot_line(high,col,1,STYLE_SOLID,spt,PlotLabels,NumberToStr(high,mask));
      else if (Plot50Levels)
        plot_line(high,col,1,STYLE_DOT,spt,false,NumberToStr(high,mask));
      if (i==0)   continue;  
      low  = start-i*incr;
      PP   = (2*incr)*MathInt(low/(2*incr));
//      log("L",i,low,PP);
      if (MathAbs(low-PP)<0.00001) 
        plot_line(low,col,1,STYLE_SOLID,spt,PlotLabels,NumberToStr(low,mask));
      else if (Plot50Levels)
        plot_line(low,col,1,STYLE_DOT,spt,false,NumberToStr(low,mask));
//      if (high>WindowPriceMax() && low<WindowPriceMin())   flag=true;
      if (high>Bid+500*pnt && low<Bid-500*pnt)   flag=true;
  } }
  
  plot_MA_lines();
  plot_fibo_lines();
  return(0);
}
//+------------------------------------------------------------------+
int CheckPresets()    {
//+------------------------------------------------------------------+
//---------------------------------------------------------------------------------------------------------------
//    Enter the file name in here
//---------------------------------------------------------------------------------------------------------------
  ParameterFile = StringUpper(ParameterFile);
  string FileName = "Presets---CriticalLevels.TXT";
  if (ParameterFile > "")  FileName = "Presets---CriticalLevels." + ParameterFile;
//---------------------------------------------------------------------------------------------------------------
  int handle = FileOpen(FileName, FILE_CSV|FILE_READ,';');
  if (handle > 0)  {
    while(!FileIsEnding(handle))  {
      string text  = FileReadString(handle);
      int t0 = StringFind(text,"//",0);
      if (t0 == 0)       text = "";    
      else if (t0 > 0)   text = StringSubstr(text,0,t0);
      string temp  = "";
      int    quote = 0;
      for (int i=0; i<StringLen(text); i++)   {
        string char = StringSubstr(text,i,1);
        if (char == "\x22")    quote = 1 - quote;  
        else if (quote == 1)    temp  = temp + char;
        else if (char != " " && char != "_") temp  = temp + StringLower(char);  
      }
      if (StringLen(temp) > 0) {
        int equal = StringFind(temp,"=",0);
        int semic = StringFind(temp,";",0);
        string pname = "";
        pname   = StringSubstr(temp,0,equal);
        string pvalue = StringSubstr(temp,equal+1,semic-equal+1);
        if (pvalue != "*")  {
//---------------------------------------------------------------------------------------------------------------
//    Parameter assignment statements go in here
//---------------------------------------------------------------------------------------------------------------
          if (pname == "numdaysweeksmonths")              NumDaysWeeksMonths     = pvalue;                         else
          if (pname == "colordailyhls")                   ColorDailyHLs          = StrToColor(pvalue);             else
          if (pname == "colorweeklyhls")                  ColorWeeklyHLs         = StrToColor(pvalue);             else
          if (pname == "colormonthlyhls")                 ColorMonthlyHLs        = StrToColor(pvalue);             else
          if (pname == "datatypes")                       DataTypes              = pvalue;                         else
          if (pname == "colordailypivotstd")              ColorDailyPivotStd     = pvalue;                         else
          if (pname == "colorweeklypivotstd")             ColorWeeklyPivotStd    = pvalue;                         else
          if (pname == "colormonthlypivotstd")            ColorMonthlyPivotStd   = pvalue;                         else
          if (pname == "colordailypivotfibo")             ColorDailyPivotFibo    = pvalue;                         else
          if (pname == "colorweeklypivotfibo")            ColorWeeklyPivotFibo   = pvalue;                         else
          if (pname == "colormonthlypivotfibo")           ColorMonthlyPivotFibo  = pvalue;                         else
          if (pname == "colorroundnumbers")               ColorRoundNumbers      = pvalue;                         else
          if (pname == "plot50levels")                    Plot50Levels           = StrToBool(pvalue);              else
          if (pname == "plotlabels")                      PlotLabels             = StrToBool(pvalue);              else
          if (pname == "masettings")                      MAsettings             = pvalue;                         else
          if (pname == "fibosettings")                    FiboSettings           = pvalue;                         else
          if (pname == "linestartpoint")                  LineStartPoint         = StrToInteger(pvalue);           else
          if (pname == "linelength")                      LineLength             = StrToInteger(pvalue);           else
          if (pname == "extendlines")                     ExtendLines            = StrToBool(pvalue);              else
          if (pname == "refreshperiod")                   RefreshPeriod          = pvalue;                         else
          if (pname == "visibility")                      Visibility             = pvalue;                         else
          if (pname == "showdescriptions")                ShowDescriptions       = StrToBool(pvalue);

//          Debug("pname  = " + pname);
//          Debug("pvalue = " + pvalue);
//---------------------------------------------------------------------------------------------------------------
        }
      }  
      temp = FileReadString(handle);
    }
    FileClose(handle);
  }  

  RefreshEveryXMins = StrToTF(RefreshPeriod);
  prev_time = -9999;
  obj = 0;
  vis = GetVisibility(Visibility);
  StrToIntegerArray(NumDaysWeeksMonths,numDWM);

  nMAS = StrToStringArray(MAsettings,MAS);
  nFS  = StrToStringArray(FiboSettings,FS);
  
  return(0);
}

//+------------------------------------------------------------------+
#include <hanover --- extensible functions (np).mqh>


