#property copyright "Built with Grok 4"
#property link      ""
#property version   "1.02"
#property strict
#property indicator_chart_window

// Inputs for timeframes (Set to PERIOD_CURRENT or 0 to disable)
input ENUM_TIMEFRAMES TF1 = PERIOD_M1;
input ENUM_TIMEFRAMES TF2 = PERIOD_M5;
input ENUM_TIMEFRAMES TF3 = PERIOD_M15;
input ENUM_TIMEFRAMES TF4 = PERIOD_M30;
input ENUM_TIMEFRAMES TF5 = PERIOD_H1;
input ENUM_TIMEFRAMES TF6 = PERIOD_H4;
input ENUM_TIMEFRAMES TF7 = PERIOD_D1;
input ENUM_TIMEFRAMES TF8 = PERIOD_W1;
input ENUM_TIMEFRAMES TF9 = PERIOD_MN1;
input ENUM_TIMEFRAMES TF10 = PERIOD_CURRENT; // Set to 0/PERIOD_CURRENT to hide [cite: 41, 56]

// Display settings
input ENUM_BASE_CORNER ChartCorner = CORNER_RIGHT_UPPER;
input int X_Distance = 200;
input int Y_Distance = 20;
input int LineSpacing = 20;
input string Font = "Arial";
input int FontSize = 10;
input color UpColor = clrGreen;
input color DownColor = clrRed;
input color NeutralColor = clrGray;

//+------------------------------------------------------------------+
int OnInit()
{
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   ObjectsDeleteAll(0, "TFC_"); // Clean up all dashboard objects [cite: 46]
}

//+------------------------------------------------------------------+
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[])
{
   UpdateDashboard();
   return(rates_total);
}

//+------------------------------------------------------------------+
void UpdateDashboard()
{
   int y_pos = Y_Distance;
   
   // Title
   CreateLabel("TFC_Title", "Timeframe Continuity", ChartCorner, X_Distance, y_pos, Font, FontSize, clrWhite);
   y_pos += LineSpacing + 5;

   // Array of timeframes from inputs [cite: 53]
   ENUM_TIMEFRAMES tfs[10] = {TF1, TF2, TF3, TF4, TF5, TF6, TF7, TF8, TF9, TF10};
   
   double current_price = SymbolInfoDouble(_Symbol, SYMBOL_BID);
   
   for(int i = 0; i < 10; i++)
   {
      ENUM_TIMEFRAMES period = tfs[i];
      string objName = "TFC_TF" + IntegerToString(i + 1);
      
      // Logic: If timeframe is 0 (PERIOD_CURRENT), delete the object and skip 
      if(period == PERIOD_CURRENT) 
      {
         ObjectDelete(0, objName);
         continue;
      }
      
      double open_array[1];
      if(CopyOpen(_Symbol, period, 0, 1, open_array) <= 0) continue;
      double open_price = open_array[0];
      
      string tf_str = PeriodToStr(period);
      string dir_str;
      color dir_color;
      
      if(current_price > open_price + _Point)
      {
         dir_str = "Up";
         dir_color = UpColor;
      }
      else if(current_price < open_price - _Point)
      {
         dir_str = "Down";
         dir_color = DownColor;
      }
      else
      {
         dir_str = "Neutral";
         dir_color = NeutralColor;
      }
      
      string text = tf_str + ": " + dir_str;
      CreateLabel(objName, text, ChartCorner, X_Distance, y_pos, Font, FontSize, dir_color);
      y_pos += LineSpacing;
   }
}

//+------------------------------------------------------------------+
string PeriodToStr(ENUM_TIMEFRAMES period)
{
   switch(period)
   {
      case PERIOD_M1:   return("M1");
      case PERIOD_M5:   return("M5");
      case PERIOD_M15:  return("M15");
      case PERIOD_M30:  return("M30");
      case PERIOD_H1:   return("H1");
      case PERIOD_H4:   return("H4");
      case PERIOD_D1:   return("D1");
      case PERIOD_W1:   return("W1");
      case PERIOD_MN1:  return("MN");
      default:          return("TF " + IntegerToString(period));
   }
}

//+------------------------------------------------------------------+
void CreateLabel(string name, string text, ENUM_BASE_CORNER corner, int x, int y, string font, int size, color col)
{
   if(ObjectFind(0, name) < 0)
   {
      ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
      ObjectSetInteger(0, name, OBJPROP_CORNER, corner);
      ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x);
      ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y);
   }
   ObjectSetString(0, name, OBJPROP_TEXT, text);
   ObjectSetInteger(0, name, OBJPROP_FONTSIZE, size);
   ObjectSetString(0, name, OBJPROP_FONT, font);
   ObjectSetInteger(0, name, OBJPROP_COLOR, col);
}