//+------------------------------------------------------------------+
//|                                                          CSM.mq4 |
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_maximum 120
#property indicator_minimum -20

#include <hanover --- function header (np).mqh>

extern string   ParameterFile       = "NONE";
//extern string   Currencies          = "AUD,CAD,CHF,EUR,GBP,JPY,NZD,USD,TRY,SGD,DKK,HKD,NOK,SEK,PLN,HUF,CZK,ZAR";
//extern string   CurrencyPairs       = "AUD,CAD,CHF,EUR,GBP,JPY,NZD,USD";
extern string   CurrencyPairs       = "GU,UF,EU,UJ,UC,NU,AU,AN,AC,AF,AJ,CJ,FJ,EG,EA,EF,EJ,EN,EC,GF,GA,GC,GJ,GN,NJ,NC,CF,NF";
extern string   CurrencySuffix      = "";
extern string   TimeFrames          = "M1,M5,M15,M30,H1,H4,D1,W1,MN";
extern int      NumberOfCandles     = 25;
extern bool     ApplySmoothing      = true;
extern bool     TriangularWeighting = false;
extern int      HistoricalShift     = 0;
extern string   SortMethod          = "D";
extern int      ValuesSpacing       = 15;
//extern string   FontName            = "Placard MT Condensed";
extern string   FontName            = "CSM";
extern int      FontSize            = 12;
extern bool     SeparateWindow      = true;
extern int      HorizPos            = 20;
extern int      VertPos             = 180;
extern int      HorizSpacing        = 14;
extern string   Colors_AUD          = "100,SeaGreen,-1";
extern string   Colors_CAD          = "100,SaddleBrown,-1";
extern string   Colors_CHF          = "100,Gold,-1";
extern string   Colors_EUR          = "100,HotPink,-1";
extern string   Colors_GBP          = "100,Crimson,-1";
extern string   Colors_JPY          = "100,DarkOrchid,-1";
extern string   Colors_NZD          = "100,RoyalBlue,-1";
extern string   Colors_USD          = "100,White,-1";
extern string   TextFont            = "Comic Sans MS";
extern int      TextSize            = 12;
extern color    TextColor           = Silver;
extern string   RefreshPeriod       = "M1";
extern string   UniqueID            = "1";
extern string   OutputFilename      = "CSM.CSV";
extern bool     OutputGlobals       = false;
//extern bool     SeparateFiles       = false;
extern bool     HighlightBox        = true;
extern bool     DisplaySpread       = true;
extern int      SummarySpacing      = 2;
extern string   SummaryLevels       = "0,50,100";

double    spr, pnt, tickval, ccy_strength[8], ccy_val[9][8];
int       dig, tf, ccy_count[8], ccCP, wno, RefreshEveryXMins, nAltColors, nSL, SL[10];
string    IndiName, ccy, CP[99], arr[20], outf[2], clrs[50];
string    ccy_name[8] = {"AUD","CAD","CHF","EUR","GBP","JPY","NZD","USD"};
datetime  prev_time;
color     colr[8];

//+------------------------------------------------------------------+
int init()   {
//+------------------------------------------------------------------+

  ccy     = Symbol();
  tf      = Period();
  pnt     = MarketInfo(ccy,MODE_POINT);
  dig     = MarketInfo(ccy,MODE_DIGITS);
  spr     = MarketInfo(ccy,MODE_SPREAD);
  tickval = MarketInfo(ccy,MODE_TICKVALUE);
  if (dig == 3 || dig == 5) {
    pnt     *= 10;
    spr     /= 10;
    tickval *= 10;
  }
  CheckPresets();


  del_obj();
  plot_obj();    
  prev_time = -9999;

  wno = WindowFind(IndiName);
  if (wno < 0)
    wno = WindowsTotal();
  if (!SeparateWindow)
    wno = 0;  

  IndiName = "CSM-" + UniqueID + "-";
  IndicatorShortName(IndiName);
  GlobalVariablesDeleteAll(IndiName);
  return(0);
}

//+------------------------------------------------------------------+
int deinit()  {
//+------------------------------------------------------------------+
  del_obj();
  GlobalVariablesDeleteAll(IndiName);
  return(0);
}

//+------------------------------------------------------------------+
int start()  {
//+------------------------------------------------------------------+
  if (RefreshEveryXMins == 0) {
    del_obj();
    plot_obj();    
  }
  else {
    if(prev_time != iTime(Symbol(),RefreshEveryXMins,0))  {
      del_obj();
      plot_obj();
      prev_time = iTime(Symbol(),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_obj()   {
//+------------------------------------------------------------------+
//  CheckPresets();

/*  if (HighlightBox)   {
    PlotLabel (IndiName+"991", false, wno, 0,   1+HorizPos+(HorizSpacing*50), -156+VertPos, StringRepeat("—",8),  DimGray, 18, "Arial", 270, false, 0);      // Plot text label
    PlotLabel (IndiName+"992", false, wno, 0, -15+HorizPos+(HorizSpacing*50),   20+VertPos, StringRepeat("—",19/15*HorizSpacing), DimGray, 18, "Arial",   0, false, 0);      // Plot text label
    PlotLabel (IndiName+"993", false, wno, 0, 155+HorizPos+(HorizSpacing*70), -158+VertPos, StringRepeat("—",8),  DimGray, 18, "Arial", 270, false, 0);      // Plot text label
  }
*/  

  if (OutputFilename > "")   {
    StrToStringArray(OutputFilename,outf,"`");
    outf[0] = StringReplace(outf[0],"[#]",UniqueID);
    outf[0] = StringReplace(outf[0],"[sym]",Symbol());
    outf[0] = StringReplace(outf[0],"[tf]",TFToStr(Period()));
    if (outf[1] < "!")   outf[1] = "_Y-M-D_H-I-S";
    outf[0] = StringReplace(outf[0],"[dt]",DateToStr(TimeCurrent(),outf[1]));
    int ofnum = FileOpen(outf[0],FILE_CSV|FILE_WRITE,'~');
    if (ofnum >= 0)  {     
      string outstr = "TF ";
      for (int i=0; i<8; i++)   {
        outstr = outstr + ", " + ccy_name[i];
      }
      FileWrite(ofnum,outstr);
  } }  
    
  int hi_bar, lo_bar;
  double curr_bid, candle_high, candle_low, bid_ratio;
  int xp = HorizPos;
  int yp = VertPos;
  ArrayInitialize(ccy_strength,0.0);
  ArrayInitialize(ccy_count,0);

  double CandleSum = NumberOfCandles*(NumberOfCandles+1)/2;
  for (int t=0; t<9; t++)  {
    for (i=0; i<8; i++)     ccy_val[t][i] = 0;
    int tmf = (t==0) + 5*(t==1) + 15*(t==2) + 30*(t==3) + 60*(t==4) + 240*(t==5) + 1440*(t==6) + 10080*(t==7) + 43200*(t==8);
    if (StringFind(TimeFrames,TFToStr(tmf)+",") < 0)    continue;
    ArrayInitialize(ccy_strength,0);
    ArrayInitialize(ccy_count,0);
    for (i=0; i<ccCP; i++)   {
      curr_bid     = MarketInfo(CP[i],MODE_BID);
      if (curr_bid == 0)   continue;
      
      curr_bid = iClose(CP[i],tmf,HistoricalShift);
      if (ApplySmoothing)   {
        bid_ratio = 0;
        for (int k=1; k<=NumberOfCandles; k++)  {
          hi_bar       = iHighest(CP[i],tmf,MODE_HIGH,k,HistoricalShift);
          lo_bar       = iLowest(CP[i],tmf,MODE_LOW,k,HistoricalShift);
          candle_high  = iHigh(CP[i],tmf,hi_bar);
          candle_low   = iLow(CP[i],tmf,lo_bar);
          if (TriangularWeighting)
            bid_ratio    += DivZero(curr_bid - candle_low, candle_high - candle_low) * (NumberOfCandles+1-k)/CandleSum;
          else
            bid_ratio    += DivZero(curr_bid - candle_low, candle_high - candle_low) / NumberOfCandles;
        }
      } else {
        hi_bar       = iHighest(CP[i],tmf,MODE_HIGH,NumberOfCandles,HistoricalShift);
        lo_bar       = iLowest(CP[i],tmf,MODE_LOW,NumberOfCandles,HistoricalShift);
        candle_high  = iHigh(CP[i],tmf,hi_bar);
        candle_low   = iLow(CP[i],tmf,lo_bar);
        bid_ratio    = DivZero(curr_bid - candle_low, candle_high - candle_low);
      }
//      log(CP[i],TFToStr(tmf),bid_ratio);
/*
      double ind_strength = 0;
      if (bid_ratio >= 0.97)   ind_strength = 9;    else
      if (bid_ratio >= 0.90)   ind_strength = 8;    else
      if (bid_ratio >= 0.75)   ind_strength = 7;    else
      if (bid_ratio >= 0.60)   ind_strength = 6;    else
      if (bid_ratio >= 0.50)   ind_strength = 5;    else
      if (bid_ratio >= 0.40)   ind_strength = 4;    else
      if (bid_ratio >= 0.25)   ind_strength = 3;    else
      if (bid_ratio >= 0.10)   ind_strength = 2;    else
      if (bid_ratio >= 0.03)   ind_strength = 1;
*/      
      double ind_strength = 10 * bid_ratio;

      string temp = StringSubstr(CP[i],0,3);
      for (int j=0; j<8; j++)   {
        if (ccy_name[j] == temp)  {
          ccy_strength[j] += ind_strength;
          ccy_count[j]    += 1;
          break;
      } }    

      temp = StringSubstr(CP[i],3,3);
      for (j=0; j<8; j++)   {
        if (ccy_name[j] == temp)  {
          ccy_strength[j] += 10 - ind_strength;
          ccy_count[j]    += 1;
          break;
    } } }    

    // This routine loads the strength values and currency symbols into an array, and sorts the array......
    double loval = 999999, hival = 0;
    string array_to_sort[8];
    for (j=0; j<8; j++)  {
      array_to_sort[j] = "";
//      if (ccy_count[j] < 1)   continue;
      double out_value = DivZero(ccy_strength[j],ccy_count[j]);
      string text     = NumberToStr(out_value,"R-3.1") + ccy_name[j] + NumberToStr(colr[j],"12");
      array_to_sort[j] = text;
      hival = MathMax(hival,out_value);
      loval = MathMin(loval,out_value);
    }
    if (StringUpper(SortMethod) == "D")     ShellsortStringArray(array_to_sort,8,true);
    if (StringUpper(SortMethod) == "A")     ShellsortStringArray(array_to_sort,8,false);
                                                                       
    for (j=0; j<8; j++)  {
      ccy        = StringSubstr(array_to_sort[j],6,3);
      out_value  = StrToNumber(StringSubstr(array_to_sort[j],0,6));
//      color clr  = StrToNumber(StringSubstr(array_to_sort[j],9,12));
      color clr  = GetColor(ccy,10*out_value);
      text       = StringRepeat("I",MathFix(5*out_value,0));
      string objname = IndiName + "-" + TFToStr(tmf) + "-" + ccy; 
      PlotLabel (objname, false, wno, 0, xp, yp, text, clr, FontSize, FontName, 90, false, 0);      // Plot histogram bar
//      log(i,j,objname,out_value,text);

      objname = IndiName + "-" + TFToStr(tmf) + "-" + ccy + "-CCY"; 
      PlotLabel (objname, false, wno, 0, xp+3, yp+30, ccy, clr, 8, TextFont, 90, false, 0);         // Plot symbol ID below histogram bar

      if (j==4)   {
        objname = IndiName + "-" + TFToStr(tmf) + "-LBL"; 
        if (t>=5 && t<=7 && HighlightBox)  {
          int    xval = xp-HorizSpacing/2-38;
          string tftxt = "—— " + TFToStr(tmf) + " ——";
//          string tftxt = "««« " + TFToStr(tmf) + " »»»";
        } else {
          xval  = xp-HorizSpacing/2-5;
          tftxt = TFToStr(tmf);
        }  
        PlotLabel (objname, false, wno, 0, xval, yp+37, tftxt, TextColor, TextSize, TextFont, 0, false, 0);       // Plot TF ("M1", "M5" etc)
//        objname = IndiName + "-" + TFToStr(tmf) + "-ZLN"; 
//        PlotLabel (objname, false, wno, 0, xp-HorizSpacing/2-52, yp-9, StringRepeat("—",7), TextColor, 13, "Arial Bold", 0, false, 0);                              // Plot histogram zero line
        if (DisplaySpread)  {
          objname = IndiName + "-" + TFToStr(tmf) + "-DIF"; 
          PlotLabel (objname, false, wno, 0, xp-HorizSpacing/2-12, yp-168, NumberToStr(10*(hival-loval),"'<-'T4'->'"), TextColor, 8, TextFont, 0, false, 0);          // Plot spread/difference value "<n>"
      } }
      if (ValuesSpacing>0)   {
        objname = IndiName + "-" + TFToStr(tmf) + "-" + ccy + "-VAL"; 
//        PlotLabel (objname, false, wno, 0, xp+(HorizSpacing/2-3)*MathSign(HorizSpacing), yp-15*out_value-10, NumberToStr(10*out_value,"TR3"), clr, 8, TextFont, 90, false, 0);      // Plot strength value above histogram bar
        PlotLabel (objname, false, wno, 0, xp+3, yp-ValuesSpacing*out_value-10, NumberToStr(10*out_value,"TR3"), clr, 8, TextFont, 90, false, 0);      // Plot strength value above histogram bar
      }
      if (OutputGlobals)      GlobalVariableSet(IndiName+TFToStr(tmf)+"-"+ccy,10*out_value);     // output strength value to Global Variable
      xp += HorizSpacing;
//      if (SeparateFiles)  {
//        int hsf = FileOpen("CSM_"+ccy+"_"+TFToStr(tmf)+".CSV", FILE_CSV|FILE_WRITE,'~');
//        if (hsf >= 0)  {
//          FileWrite(hsf,NumberToStr(10*out_value,"TR3"));
//          FileClose(hsf);
//      } } 
    }      
    xp += HorizSpacing*2;
    if (ofnum >= 0)  {     
      outstr = StrToStr(TFToStr(tmf),"L3");
      for (i=0; i<8; i++)   {
        ccy_val[t][i] = 10*DivZero(ccy_strength[i],ccy_count[i]);
        outstr = outstr + NumberToStr(ccy_val[t][i],"','R4");
      }  
      FileWrite(ofnum,outstr);
    }
  }   
  if (ofnum >= 0)       
    FileClose(ofnum);
  if (SummarySpacing > 0)   plot_summary();  
  return(0);
}

//+------------------------------------------------------------------+
void plot_summary()   {
//+------------------------------------------------------------------+
  StrToStringArray(Colors_AUD,arr); colr[0] = StrToColor(arr[1]);
  StrToStringArray(Colors_CAD,arr); colr[1] = StrToColor(arr[1]);
  StrToStringArray(Colors_CHF,arr); colr[2] = StrToColor(arr[1]);
  StrToStringArray(Colors_EUR,arr); colr[3] = StrToColor(arr[1]);
  StrToStringArray(Colors_GBP,arr); colr[4] = StrToColor(arr[1]);
  StrToStringArray(Colors_JPY,arr); colr[5] = StrToColor(arr[1]);
  StrToStringArray(Colors_NZD,arr); colr[6] = StrToColor(arr[1]);
  StrToStringArray(Colors_USD,arr); colr[7] = StrToColor(arr[1]);

//  d(wno, SummarySpacing);
  for (int i=0; i<8; i++)   {
    for (int t=0; t<8; t++)   {
      int tmf = (t==0) + 5*(t==1) + 15*(t==2) + 30*(t==3) + 60*(t==4) + 240*(t==5) + 1440*(t==6) + 10080*(t==7) + 43200*(t==8);
      if (StringFind(TimeFrames,TFToStr(tmf)+",") < 0)    continue;
      string objname = IndiName + NumberToStr(i,"'-'1") + NumberToStr(t,"'-'1") + "-SUM"; 
      datetime time1  = Time[SummarySpacing*t];
      datetime time2  = Time[SummarySpacing*(t+1)];
      double   price1 = ccy_val[t][i];
      double   price2 = ccy_val[t+1][i];
      int width=2, style=0, ray=0, backg=0, vis=0;
      PlotTL (objname, true, wno, time1,  price1, time2, price2, colr[i], width, style, ray, backg, vis);       // Plot trendline: colored lines for each ccy
    }
    time1   = Time[SummarySpacing*(t+1)+3];
    price1  = 100-12.5*i;
    objname = IndiName+NumberToStr(i,"'-'1") + "-CCYS";
    PlotText  (objname, true, wno, time1,  price1, ccy_name[i], colr[i], FontSize, TextFont,  0.0, false, vis);       // Plot text
  }
  for (t=0; t<9; t++)   {
    tmf = (t==0) + 5*(t==1) + 15*(t==2) + 30*(t==3) + 60*(t==4) + 240*(t==5) + 1440*(t==6) + 10080*(t==7) + 43200*(t==8);
    objname = IndiName + NumberToStr(t,"'-'1") + "-SUMTXT"; 
    time1   = Time[SummarySpacing*t];
    PlotText (objname, true, wno, time1, 0.1, TFToStr(tmf), TextColor, TextSize-2, TextFont, 0, backg, vis);    // Plot text: timeframe names: MN, W1, etc
    objname = IndiName + NumberToStr(t,"'-'1") + "-SUMVL"; 
    PlotTL   (objname, true, wno, time1, 0.1, time1, 100, DimGray, 1, STYLE_DOT, ray, backg, vis);              // Plot trendline: dotted vertical lines
  }

  objname = IndiName + NumberToStr(t,"'-'1") + "-SUMM"; 
  time1   = Time[SummarySpacing*4];
  PlotText (objname, true, wno, time1, 115, "TREND SUMMARY", TextColor, TextSize, TextFont, 0, backg, vis);     // Plot text: "TREND SUMMARY" heading

  for (i=0; i<nSL; i++)  {
    objname = IndiName + NumberToStr(t,"'-'1") + NumberToStr(i,"'-SUM-'Z3"); 
    time1   = Time[SummarySpacing*8+1];
    time2   = Time[0];
    price1  = MathMax(SL[i],0.1);
    PlotTL (objname, true, wno, time1, price1, time2, price1, DimGray, 1, STYLE_DOT, ray, backg, vis, NumberToStr(SL[i],"T3"));          // Plot trendline: dotted lines at user defined values (default: 0, 50, 100)
  }
  if (HighlightBox)  {
    objname = IndiName + NumberToStr(t,"'-'1") + "-SUMH"; 
    time1   = Time[SummarySpacing*7];
    time2   = Time[SummarySpacing*5];
    PlotTL (objname, true, wno, time1, 100, time2, 100, DimGray, 2, STYLE_SOLID, ray, backg, vis);              // Plot trendline: horiz line highlighting W1,D1,H4
  } 
     
  return(0);
}

//+------------------------------------------------------------------+
color GetColor(string curr, int val)   {
//+------------------------------------------------------------------+
  string ccs = "100,Gray,-1";
  if (curr=="AUD")   ccs = Colors_AUD;
  if (curr=="CAD")   ccs = Colors_CAD;
  if (curr=="CHF")   ccs = Colors_CHF;
  if (curr=="EUR")   ccs = Colors_EUR;
  if (curr=="GBP")   ccs = Colors_GBP;
  if (curr=="JPY")   ccs = Colors_JPY;
  if (curr=="NZD")   ccs = Colors_NZD;
  if (curr=="USD")   ccs = Colors_USD;
  StrToStringArray(ccs,clrs);
  color colr = Gray;                             // default is first named color
  for (int k=0; k<10; k++)  {
    if (val <= StrToNumber(clrs[k*2]) && val > StrToNumber(clrs[k*2+2]))  {
      colr = StrToColor(clrs[k*2+1]);
      break;  
  } }
  return(colr);
}  

//+------------------------------------------------------------------+
int CheckPresets()    {
//+------------------------------------------------------------------+
//---------------------------------------------------------------------------------------------------------------
//    Enter the file name in here
//---------------------------------------------------------------------------------------------------------------
  ParameterFile = StringUpper(ParameterFile);
  string FileName = "Presets---CSM.TXT";
  if (ParameterFile > "")  FileName = "Presets---CSM." + 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 == "currencypairs")               CurrencyPairs             = pvalue;                  else
          if (pname == "currencysuffix")              CurrencySuffix            = pvalue;                  else
          if (pname == "timeframes")                  TimeFrames                = pvalue;                  else
          if (pname == "numberofcandles")             NumberOfCandles           = StrToInteger(pvalue);    else
          if (pname == "applysmoothing")              ApplySmoothing            = StrToBool(pvalue);       else
          if (pname == "triangularweighting")         TriangularWeighting       = StrToBool(pvalue);       else
          if (pname == "historicalshift")             HistoricalShift           = StrToInteger(pvalue);    else
          if (pname == "sortmethod")                  SortMethod                = pvalue;                  else
          if (pname == "valuesspacing")               ValuesSpacing             = StrToInteger(pvalue);    else
          if (pname == "fontname")                    FontName                  = pvalue;                  else
          if (pname == "fontsize")                    FontSize                  = StrToInteger(pvalue);    else
          if (pname == "separatewindow")              SeparateWindow            = StrToBool(pvalue);       else
          if (pname == "horizpos")                    HorizPos                  = StrToInteger(pvalue);    else
          if (pname == "vertpos")                     VertPos                   = StrToInteger(pvalue);    else
          if (pname == "horizspacing")                HorizSpacing              = StrToInteger(pvalue);    else
          if (pname == "colorsaud")                   Colors_AUD                = pvalue;                  else
          if (pname == "colorscad")                   Colors_CAD                = pvalue;                  else
          if (pname == "colorschf")                   Colors_CHF                = pvalue;                  else
          if (pname == "colorseur")                   Colors_EUR                = pvalue;                  else
          if (pname == "colorsgbp")                   Colors_GBP                = pvalue;                  else
          if (pname == "colorsjpy")                   Colors_JPY                = pvalue;                  else
          if (pname == "colorsnzd")                   Colors_NZD                = pvalue;                  else
          if (pname == "colorsusd")                   Colors_USD                = pvalue;                  else
          if (pname == "textfont")                    TextFont                  = pvalue;                  else
          if (pname == "textsize")                    TextSize                  = StrToInteger(pvalue);    else
          if (pname == "textcolor")                   TextColor                 = StrToColor(pvalue);      else
          if (pname == "refreshperiod")               RefreshPeriod             = pvalue;                  else
          if (pname == "uniqueid")                    UniqueID                  = pvalue;                  else
          if (pname == "outputfilename")              OutputFilename            = pvalue;                  else
          if (pname == "outputglobals")               OutputGlobals             = StrToBool(pvalue);       else
          if (pname == "highlightbox")                HighlightBox              = StrToBool(pvalue);       else
          if (pname == "displayspread")               DisplaySpread             = StrToBool(pvalue);       else
          if (pname == "summaryspacing")              SummarySpacing            = StrToInteger(pvalue);    else
          if (pname == "summarylevels")               SummaryLevels             = pvalue;                  

//          Debug("pname  = " + pname);
//          Debug("pvalue = " + pvalue);
//---------------------------------------------------------------------------------------------------------------
        }
      }  
      temp = FileReadString(handle);
    }
    FileClose(handle);
  }
    
  RefreshEveryXMins = StrToTF(RefreshPeriod);

  NumberOfCandles = MathMax(NumberOfCandles,1);
  
  if (CurrencyPairs == "")  CurrencyPairs = Symbol();
  CurrencyPairs  = AppendIfMissing(StringUpper(CurrencyPairs),",");
  ccCP = StrToStringArray(CurrencyPairs,CP);
  for (i=0; i<=ccCP; i++)
    CP[i] = ExpandCcy(CP[i]) + CurrencySuffix;

  if (TimeFrames == "")  TimeFrames = TFToStr(Period());
  TimeFrames  = AppendIfMissing(StringUpper(TimeFrames),",");

  nSL        = StrToIntegerArray(SummaryLevels,SL);
  
  IndiName = "CSM-" + UniqueID + "-";
  IndicatorShortName(IndiName);
  GlobalVariablesDeleteAll(IndiName);
  
  return(0);
}
//+------------------------------------------------------------------+
#include <hanover --- extensible functions (np).mqh>


