//+------------------------------------------------------------------+
//|                                              MTF_Dashboard.mq5   |
//+------------------------------------------------------------------+
#property copyright "Custom Dashboard"
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots   0

//--- Inputs
input int      inpLength      = 14;           // Fast MA Period
input int      inpSlowLength  = 34;           // Slow MA Period
input color    ColorBull      = clrLimeGreen; // Bullish Color
input color    ColorBear      = clrRed;       // Bearish Color
input int      X_Offset       = 50;           // Distance from left
input int      Y_Offset       = 50;           // Distance from top

//--- Timeframes to monitor
ENUM_TIMEFRAMES TFs[] = {PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1};

int Handles[];

//+------------------------------------------------------------------+
//| Initialization                                                   |
//+------------------------------------------------------------------+
int OnInit()
{
   ArrayResize(Handles, ArraySize(TFs));
   
   // Create handles for each timeframe
   for(int i=0; i<ArraySize(TFs); i++)
   {
      Handles[i] = iMA(_Symbol, TFs[i], inpLength, 0, MODE_EMA, PRICE_CLOSE);
      if(Handles[i] == INVALID_HANDLE) return(INIT_FAILED);
   }
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Deinitialization                                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   for(int i=0; i<ArraySize(TFs); i++) IndicatorRelease(Handles[i]);
   ObjectsDeleteAll(0, "DB_");
}

//+------------------------------------------------------------------+
//| Main calculation                                                 |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], 
                const double &open[], const double &high[], const double &low[], const double &close[],
                const long &tick_volume[], const long &volume[], const int &spread[])
{
   for(int i=0; i<ArraySize(TFs); i++)
   {
      double maBuffer[];
      ArraySetAsSeries(maBuffer, true);
      
      // Copy latest MA value
      if(CopyBuffer(Handles[i], 0, 0, 1, maBuffer) <= 0) continue;
      
      // Determine State
      bool isBullish = (close[rates_total-1] > maBuffer[0]);
      
      // Draw Dashboard Element
      string name = "DB_" + EnumToString(TFs[i]);
      DrawBox(name, i, isBullish ? ColorBull : ColorBear, EnumToString(TFs[i]));
   }
   
   return(rates_total);
}

//+------------------------------------------------------------------+
//| Helper: Draw/Update Rectangle                                    |
//+------------------------------------------------------------------+
void DrawBox(string name, int row, color col, string text)
{
   int boxSize = 20;
   int spacing = 5;
   int x = X_Offset;
   int y = Y_Offset + (row * (boxSize + spacing));
   
   if(ObjectFind(0, name) < 0)
   {
      ObjectCreate(0, name, OBJ_RECTANGLE_LABEL, 0, 0, 0);
      ObjectSetInteger(0, name, OBJPROP_XSIZE, boxSize);
      ObjectSetInteger(0, name, OBJPROP_YSIZE, boxSize);
      ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_UPPER);
   }
   
   ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x);
   ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y);
   ObjectSetInteger(0, name, OBJPROP_BGCOLOR, col);
   ObjectSetInteger(0, name, OBJPROP_BORDER_COLOR, clrBlack);
}