//+------------------------------------------------------------------+
//|                                                EMA Dashboard.mq4 |
//+------------------------------------------------------------------+

//#property show_inputs
#property indicator_chart_window

#include <hanover --- function header (np).mqh>

//extern string   Currencies            = "AUD,CAD,CHF,EUR,GBP,JPY,NZD,USD,TRY,SGD,DKK,HKD,NOK,SEK,PLN,HUF,CZK,ZAR";
extern string   Currencies            = "AUD,CAD,CHF,EUR,GBP,JPY,NZD,USD";
extern string   CurrencySuffix        = "";
extern string   TimeFrames            = "MN,W1,D1,H4,H1,M30,M15,M5,M1";
extern string   MAParameters          = "20,0,1,0,0";  // period, ma_shift, ma_method, applied_price, shift
extern string   FontName              = "Comic Sans MS";
extern int      FontSize              = 13;
extern color    FontColor             = White;
extern int      WingdingsSymbol       = 110;
extern color    BullishColor          = LimeGreen;
extern color    BearishColor          = Red;
extern int      Window                = 0;
extern int      Corner                = 1;
extern int      HorizPos              = 30;
extern int      HorizAdjust           = 120;
extern int      HorizSpacing          = 45;
extern int      VertPos               = 14;
extern int      VertSpacing           = 20;
extern string   RefreshPeriod         = "+0";
//extern string   UniqueID              = "Stoch0";

double   spr, pnt, tickval, bidp, askp, lswap, sswap;
int      dig, tf, ma[5], RefreshEveryXMins;
string   IndiName, ccy, sym, C[40], TFs[9];
datetime prev_time;

//+------------------------------------------------------------------+
int init()  {
//+------------------------------------------------------------------+
  RefreshEveryXMins = StrToTF(RefreshPeriod);

  Currencies  = StringUpper(Currencies);
  if (Currencies == "")  Currencies = StringSubstr(Symbol(),0,3) + "," + StringSubstr(Symbol(),3,3);
  StrToStringArray(Currencies,C,",");
  
  TimeFrames  = StringUpper(TimeFrames);
  if (TimeFrames == "")  TimeFrames = TFToStr(Period());
  StrToStringArray(TimeFrames,TFs,",");

  StrToIntegerArray(MAParameters,ma,",");

  IndiName = NumberToStr(GetUniqueInt(),"'MADash-'Z6");
  IndicatorShortName(IndiName);

  ccy     = Symbol();
  sym     = Symbol();
  tf      = 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);
  if (dig == 3 || dig == 5) {
    pnt     *= 10;
    spr     /= 10;
    tickval *= 10;
  }  

  del_obj();
  plot_obj();
  prev_time = -9999;
  return(0);
}
//+------------------------------------------------------------------+
int deinit()  {
//+------------------------------------------------------------------+
  del_obj();
  return(0);
}
//+------------------------------------------------------------------+
int start()  {
//+------------------------------------------------------------------+
  if (RefreshEveryXMins < 0)
    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_obj()   {
//+------------------------------------------------------------------+
  color colr = FontColor;      
  int c = 0;
  int xp = HorizPos;
  int yp = VertPos+c*VertSpacing;
  for (int t=0; t<9; t++)  {
    if (TFs[t] > "")   {
      string tstr1 = StrToStr(TFs[t],"R4");
      string objname = IndiName + "-hdg" + NumberToStr(-t-1,"T-6");
      PlotLabel (objname, false, Window, Corner, xp+HorizAdjust+t*HorizSpacing, yp, tstr1, FontColor, FontSize, FontName, 0, false, 0);      // Plot text label
  } }
  for (int i=0; i<40; i++)  {
    if (StringLen(C[i]) < 1)   continue;
    for (int j=0; j<40; j++)  {
      if (i==j)   continue;
      if (StringLen(C[j]) < 1)   continue;
      ccy     = C[i] + C[j] + CurrencySuffix;
      if (iClose(ccy,1440,0)==0)   continue;      
      c++;
      yp = VertPos+c*VertSpacing;
      objname = IndiName + NumberToStr(-i-1,"T-6") + NumberToStr(-j-1,"T-6");
      PlotLabel (objname, false, Window, Corner, xp, yp, ccy, FontColor, FontSize, FontName, 0, false, 0);      // Plot text label
      for (t=0; t<9; t++) {
        if (TFs[t] > "")    {
          double bidp = iClose(ccy,StrToTF(TFs[t]),0);
          double mval = iMA(ccy,StrToTF(TFs[t]),ma[0],ma[1],ma[2],ma[3],ma[4]);
          if (bidp > mval)
            colr = BullishColor;
          else
            colr = BearishColor;  
          objname = IndiName + NumberToStr(-i-1,"T-6") + NumberToStr(-j-1,"T-6") + NumberToStr(-t-1,"T-6");
          PlotLabel (objname, false, Window, Corner, xp+HorizAdjust+t*HorizSpacing, yp, CharToStr(WingdingsSymbol), colr, FontSize, "Wingdings", 0, false, 0);      // Plot text label
  } } } }
  return(0);
}

//+------------------------------------------------------------------+
#include <hanover --- extensible functions (np).mqh>

