//+------------------------------------------------------------------+
//|                                            Terminal_EDIT_AI.mq4 |
//|                        Custom indicator for displaying info     |
//|                        Balance, Equity, Margin, and Profit      |
//|                        with color-coded profit                  |
//+------------------------------------------------------------------+
#property strict
#property indicator_chart_window

//--- Input parameters
input color   TextColor         = clrBlack;        // Base Text color
input int     FontSize          = 20;             // Font size
input string  FontType          = "Arial Black";  // Font type
 int     Info_X_Distance   = 10;             // X Distance for Info Label
 int     Info_Y_Distance   = 840;             // Y Distance for Info Label
int     Profit_X_Distance = 1010;             // X Distance for Profit Label
int     Profit_Y_Distance = 840;             // Y Distance for Profit Label

//--- Global variables
string infoLabelName = "InfoDisplayLabel";
string profitLabelName = "ProfitDisplayLabel";

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   //--- Create the main info label object
   ObjectCreate(0, infoLabelName, OBJ_LABEL, 0, 0, 0);
   ObjectSetInteger(0, infoLabelName, OBJPROP_CORNER, CORNER_LEFT_UPPER);
   ObjectSetInteger(0, infoLabelName, OBJPROP_XDISTANCE, Info_X_Distance);
   ObjectSetInteger(0, infoLabelName, OBJPROP_YDISTANCE, Info_Y_Distance);
   ObjectSetInteger(0, infoLabelName, OBJPROP_COLOR, TextColor);
   ObjectSetInteger(0, infoLabelName, OBJPROP_FONTSIZE, FontSize);
   ObjectSetString(0, infoLabelName, OBJPROP_FONT, FontType);

   //--- Create the profit label object
   ObjectCreate(0, profitLabelName, OBJ_LABEL, 0, 0, 0);
   ObjectSetInteger(0, profitLabelName, OBJPROP_CORNER, CORNER_LEFT_UPPER);
   ObjectSetInteger(0, profitLabelName, OBJPROP_XDISTANCE, Profit_X_Distance);
   ObjectSetInteger(0, profitLabelName, OBJPROP_YDISTANCE, Profit_Y_Distance);
   ObjectSetInteger(0, profitLabelName, OBJPROP_FONTSIZE, FontSize);
   ObjectSetString(0, profitLabelName, OBJPROP_FONT, FontType);

   //--- Timer for updating the display
   EventSetTimer(1);
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Timer function for updating the display                          |
//+------------------------------------------------------------------+
void OnTimer()
{
   double balance = AccountInfoDouble(ACCOUNT_BALANCE);
   double equity  = AccountInfoDouble(ACCOUNT_EQUITY);
   double margin  = AccountInfoDouble(ACCOUNT_MARGIN);
   double profit  = AccountInfoDouble(ACCOUNT_PROFIT);

   //--- Determine profit color
   color profitColor;
   if(profit > 0)
      profitColor = clrLime;
   else if(profit < 0)
      profitColor = clrRed;
   else
      profitColor = TextColor; // Default color for zero profit

   //--- Format the main information
   string infoText = StringFormat("Balance: %.2f || Equity: %.2f || Margin: %.2f ||",
                                  balance, equity, margin);

   //--- Format the profit information
   string profitText = StringFormat("Profit: %.2f", profit);

   //--- Update the main label text
   ObjectSetString(0, infoLabelName, OBJPROP_TEXT, infoText);

   //--- Update the profit label text and color
   ObjectSetString(0, profitLabelName, OBJPROP_TEXT, profitText);
   ObjectSetInteger(0, profitLabelName, OBJPROP_COLOR, profitColor);
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   //--- Remove the label objects
   ObjectDelete(infoLabelName);
   ObjectDelete(profitLabelName);
   EventKillTimer();
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
{
   return(rates_total);
}
//+------------------------------------------------------------------+
