﻿//+------------------------------------------------------------------+
#property copyright "© 2026, ChukwuBuikem"
#property link      "https://www.mql5.com/en/users/bikeen"
#property version   "1.00"
#property indicator_chart_window
#property indicator_plots 0
#property strict
#include <ChartObjects\ChartObjectsTxtControls.mqh>

#define PROG_NAME "Account Audit System"
#define OUTER_PANEL PROG_NAME + "_OuterPanel"
#define INNER_PANEL PROG_NAME + "_InnerPanel"
#define MAIN_HEADER PROG_NAME + "_Header"
#define START_BALANCE_LABEL PROG_NAME + "_StartBal"
#define END_BALANCE_LABEL PROG_NAME + "_EndBal"
#define NET_PROFIT_LABEL PROG_NAME + "_NetProfit"
#define LINE_SEPARATOR PROG_NAME + "_Separator"
#define TRADES_LABEL PROG_NAME + "_Trades"
#define WINS_LABEL PROG_NAME + "_Wins"
#define LOSSES_LABEL PROG_NAME + "_Losses"
#define WINRATE_LABEL PROG_NAME + "_WinRate"
#define WITHDRAWAL_LABEL PROG_NAME + "_Withdrawal"
#define PERFORMANCE_LABEL PROG_NAME + "_Performance"
#define RATING_LABEL PROG_NAME + "_Star"
#define CLR_CHARCOAL  C'30,30,30'
#define CHART_ID ChartID()
#define BUTTON_MENU PROG_NAME + "_ButtonMenu"
#define BUTTON_RESET PROG_NAME + "_ButtonReset"


//-Data structure
struct acc_Audit
  {
   //--Variables : Defined  audit metrics
   double            startBal, endBal;
   double            deposit, withdrawn, netProfit;
   int               winRate, totalTrades, wins;
   int               losses, stars;
   //-Constructor
                     acc_Audit()
     {
      startBal = 0;
      endBal = 0;
      withdrawn = 0;
      netProfit = 0;
      winRate = 0;
      totalTrades = 0;
      wins = 0;
      losses = 0;
      stars = 1;
     }
  };

acc_Audit accountAudit;
CChartObjectRectLabel rectLabel;
CChartObjectLabel label;
CChartObjectButton button;
//+------------------------------------------------------------------+
//|        Initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   createButton(BUTTON_MENU, 780, 40, 55, 50, clrBlue, clrBlack, "Show", 13, "Menu Button");
   ChartRedraw();

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                 Deinitialization function                          |
//+------------------------------------------------------------------+
void OnDeinit(const int32_t reason)
  {
//---
   ObjectsDeleteAll(0, PROG_NAME);//Clear chart
   ChartSetInteger(CHART_ID, CHART_SHOW_ONE_CLICK, true);
   ChartRedraw();
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int32_t rates_total,
                const int32_t 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 int32_t &spread[])
  {
//-Empty for now
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int32_t id, const long & lparam, const double & dparam, const string & sparam)
  {
//---
   if(StringFind(sparam, PROG_NAME) == -1)
      return;
   if(sparam == BUTTON_MENU)
     {
      if(toggleMenuButton())
        {
         showDashboard(accountAudit);
         ChartRedraw();
        }
      else
        {
         hideDashboard();
         ChartRedraw();
        }
     }
   if(sparam == BUTTON_RESET)
     {
      //-Audit engine logic

     }
  }
//+------------------------------------------------------------------+
//|        Function to create rectangle labels                       |
//+------------------------------------------------------------------+
bool createRectLabel(const string objName, const int xDistance, const int yDistance,
                     const int xSize, const int ySize, const color clr, int borderWidth,
                     const color borderColor  = clrNONE, const ENUM_BORDER_TYPE borderType  = BORDER_FLAT,
                     const ENUM_LINE_STYLE  borderStyle = STYLE_SOLID)
  {
//---
   if(rectLabel.Create(CHART_ID, objName, 0, 0, 0, 0, 0))
     {
      rectLabel.X_Distance(xDistance);
      rectLabel.Y_Distance(yDistance);
      rectLabel.X_Size(xSize);
      rectLabel.Y_Size(ySize);
      rectLabel.BackColor(clr);
      rectLabel.SetInteger(OBJPROP_BORDER_COLOR, borderColor);
      rectLabel.BorderType(borderType);
      rectLabel.Style(borderStyle);
      rectLabel.Corner(CORNER_LEFT_UPPER);
      rectLabel.Tooltip("\n");
      rectLabel.SetInteger(OBJPROP_HIDDEN, true);
      return true;
     }
   return false;
  }
//+------------------------------------------------------------------+
//|        Function to create  labels                                |
//+------------------------------------------------------------------+
bool createLabel(const string objName, const int xDistance, const int yDistance,
                 const color clr, const string display, const int fontSize = 15,
                 const string font = "Arial Bold", const string tooltip = "\n")
  {
//---
   if(label.Create(CHART_ID, objName, 0, 0, 0))
     {
      label.X_Distance(xDistance);
      label.Y_Distance(yDistance);
      label.Color(clr);
      label.Tooltip(tooltip);
      label.SetString(OBJPROP_TEXT, display);
      label.FontSize(fontSize);
      label.Font(font);
      label.SetInteger(OBJPROP_HIDDEN, true);
      return true;
     }
   return false;
  }
//+------------------------------------------------------------------+
//|        Function to star shapes for rating, using labels          |
//+------------------------------------------------------------------+
void createStars(const int earnedStar)
  {
//---
   int xDistance = 215;
   for(int w = 1; w <= 5; w++)
     {
      string name = RATING_LABEL + IntegerToString(w);
      createLabel(name, (w == 1) ? xDistance : xDistance += 35, 513, (w <= earnedStar) ? clrGold : clrGray, "★", 30, "Arial Bold", "Overall Rating");
     }
  }
//+------------------------------------------------------------------+
//|        Function to create clickable button                       |
//+------------------------------------------------------------------+
bool createButton(const string objName, const int xDistance, const int yDistance,
                  const int xSize, const int ySize, const color backColor, const color borderColor,
                  const string display, const int fontSize, const string toolTip)
  {
//---
   if(button.Create(CHART_ID, objName, 0, 0, 0, 0, 0))
     {
      button.X_Distance(xDistance);
      button.Y_Distance(yDistance);
      button.X_Size(xSize);
      button.Y_Size(ySize);
      button.BackColor(backColor);
      button.SetString(OBJPROP_TEXT, display);
      button.Color(clrWhite);
      button.BorderColor(borderColor);
      button.State(false);
      button.Selectable(false);
      button.FontSize(fontSize);
      button.Tooltip(toolTip);
      button.SetInteger(OBJPROP_HIDDEN, true);
      return true;
     }
   return false;
  }
//+------------------------------------------------------------------+
//|               Function to toggle menu button                     |
//+------------------------------------------------------------------+
bool toggleMenuButton()
  {
//---
   static bool isShow = false;
   isShow = !isShow;
   if(button.Attach(CHART_ID, BUTTON_MENU, 0, 1))
     {
      if(isShow)
        {
         button.State(false);
         button.BackColor(clrRed);
         button.SetString(OBJPROP_TEXT, "Hide");
         button.Tooltip("Hide Button");
        }
      else
        {
         button.State(false);
         button.BackColor(clrBlue);
         button.SetString(OBJPROP_TEXT, "Show");
         button.Tooltip("Show Button");
        }
      button.Detach();
     }
   return isShow;
  }
//+------------------------------------------------------------------+
//|        Function to assemble Dashboard                            |
//+------------------------------------------------------------------+
void showDashboard(acc_Audit & audit)
  {
//---
   ChartSetInteger(CHART_ID, CHART_SHOW_ONE_CLICK, false);//-Should be executed before others
   createRectLabel(OUTER_PANEL, 30, 50, 400, 530, CLR_CHARCOAL, 1, clrDarkBlue, BORDER_FLAT, STYLE_SOLID);
   createRectLabel(INNER_PANEL, 55, 120, 350, 450, CLR_CHARCOAL, 1, clrDarkBlue, BORDER_FLAT, STYLE_DASHDOTDOT);
   createLabel(MAIN_HEADER, 70, 70, clrGold, "Account Audit", 25);
   createLabel(START_BALANCE_LABEL, 75, 135, clrWhiteSmoke, "Start Balance :", 15);
   createLabel(START_BALANCE_LABEL + "Value", 250, 135, clrWheat, DoubleToString(audit.startBal, 2), 15);
   createLabel(END_BALANCE_LABEL, 75, 175, clrWhiteSmoke, "End Balance :", 15);
   createLabel(END_BALANCE_LABEL + "Value", 250, 175, clrWheat, DoubleToString(audit.endBal, 2), 15);
   createLabel(NET_PROFIT_LABEL, 75, 215, clrWhiteSmoke, "Net Profit :", 15);
   createLabel(NET_PROFIT_LABEL + "Value", 250, 215, clrWheat, DoubleToString(audit.netProfit, 2), 15);
   createLabel(LINE_SEPARATOR + "0", 75, 250, clrGray, "___________________________________", 11);
   createLabel(TRADES_LABEL, 75, 290, clrWhiteSmoke, "Trades :", 15);
   createLabel(TRADES_LABEL + "Value", 250, 290, clrWheat, IntegerToString(audit.totalTrades), 15);
   createLabel(WINS_LABEL, 75, 330, clrWhiteSmoke, "Wins :", 15);
   createLabel(WINS_LABEL + "Value", 250, 330, clrLime, IntegerToString(audit.wins), 15);
   createLabel(LOSSES_LABEL, 75, 370, clrWhiteSmoke, "Losses :", 15);
   createLabel(LOSSES_LABEL + "Value", 250, 370, clrCrimson, IntegerToString(audit.losses), 15);
   createLabel(WINRATE_LABEL, 75, 410, clrWhiteSmoke, "Winrate :", 15);
   createLabel(WINRATE_LABEL + "Value", 250, 410, clrWheat, IntegerToString(audit.winRate) + "%", 15);
   createLabel(LINE_SEPARATOR + "1", 75, 450, clrGray, "___________________________________", 11);
   createLabel(WITHDRAWAL_LABEL, 75, 490, clrWhiteSmoke, "Withdrawn :", 15);
   createLabel(WITHDRAWAL_LABEL + "Value", 250, 490, clrWheat, "- " + DoubleToString(audit.withdrawn, 2), 15);
   createLabel(PERFORMANCE_LABEL, 75, 530, clrWhiteSmoke, "Performance :", 15);
   createStars(audit.stars);
   createButton(BUTTON_RESET, 335, 70, 55, 35, clrCrimson, clrWhiteSmoke, "Reset", 13, "Reset Button");
   ChartRedraw();
  }
//+------------------------------------------------------------------+
//|  Function to hide dashboard and re-enable one-click trading      |
//+------------------------------------------------------------------+
void hideDashboard()
  {
//---
   ObjectDelete(CHART_ID, OUTER_PANEL);
   ObjectDelete(CHART_ID, INNER_PANEL);
   ObjectDelete(CHART_ID, MAIN_HEADER);
   ObjectDelete(CHART_ID, BUTTON_RESET);
   ObjectsDeleteAll(CHART_ID, START_BALANCE_LABEL);
   ObjectsDeleteAll(CHART_ID, END_BALANCE_LABEL);
   ObjectsDeleteAll(CHART_ID, NET_PROFIT_LABEL);
   ObjectsDeleteAll(CHART_ID, TRADES_LABEL);
   ObjectsDeleteAll(CHART_ID, LINE_SEPARATOR);
   ObjectsDeleteAll(CHART_ID, TRADES_LABEL);
   ObjectsDeleteAll(CHART_ID, WINS_LABEL);
   ObjectsDeleteAll(CHART_ID, LOSSES_LABEL);
   ObjectsDeleteAll(CHART_ID, WINRATE_LABEL);
   ObjectsDeleteAll(CHART_ID, WITHDRAWAL_LABEL);
   ObjectDelete(CHART_ID, PERFORMANCE_LABEL);
   ObjectsDeleteAll(CHART_ID, RATING_LABEL);
   ChartSetInteger(CHART_ID, CHART_SHOW_ONE_CLICK, true);
   ChartRedraw();
  }
//+------------------------------------------------------------------+
