Files
mql5/Scripts/AccountInfoDisplay.mq5
T
2025-07-12 13:04:56 +02:00

155 lines
12 KiB
Plaintext

//+------------------------------------------------------------------+
//| AccountInfoDisplay.mq5 |
//| Copyright 2000-2025, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2000-2025, MetaQuotes Ltd."
#property link "https://www.mql5.com"
//---
#include <Trade\AccountInfo.mqh>
#include <ChartObjects\ChartObjectsTxtControls.mqh>
//---
#include "AccountInfoDisplayInit.mqh"
//---
//+------------------------------------------------------------------+
//| Account Info Display script class |
//+------------------------------------------------------------------+
class CAccountInfoDisplay
{
protected:
CAccountInfo m_account;
//--- chart objects
CChartObjectLabel m_label[23];
CChartObjectLabel m_label_info[23];
public:
CAccountInfoDisplay(void);
~CAccountInfoDisplay(void);
//---
bool Init(void);
void Deinit(void);
void Processing(void);
private:
void AccountInfoToChart(void);
};
//---
CAccountInfoDisplay g_accountDisplay;
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
CAccountInfoDisplay::CAccountInfoDisplay(void)
{
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
CAccountInfoDisplay::~CAccountInfoDisplay(void)
{
}
//+------------------------------------------------------------------+
//| Method Init. |
//+------------------------------------------------------------------+
bool CAccountInfoDisplay::Init(void)
{
int i,sy=10;
int dy=16;
color color_label;
color color_info;
//--- tuning colors
color_info =(color)(ChartGetInteger(0,CHART_COLOR_BACKGROUND)^0xFFFFFF);
color_label=(color)(color_info^0x202020);
//---
if(ChartGetInteger(0,CHART_SHOW_OHLC))
sy+=16;
//--- creation Labels[]
for(i=0;i<23;i++)
{
m_label[i].Create(0,"Label"+IntegerToString(i),0,20,sy+dy*i);
m_label[i].Description(init_str[i]);
m_label[i].Color(color_label);
m_label[i].FontSize(8);
//---
m_label_info[i].Create(0,"LabelInfo"+IntegerToString(i),0,120,sy+dy*i);
m_label_info[i].Description(" ");
m_label_info[i].Color(color_info);
m_label_info[i].FontSize(8);
}
AccountInfoToChart();
//--- redraw chart
ChartRedraw();
//---
return(true);
}
//+------------------------------------------------------------------+
//| Method Deinit. |
//+------------------------------------------------------------------+
void CAccountInfoDisplay::Deinit(void)
{
}
//+------------------------------------------------------------------+
//| Method Processing. |
//+------------------------------------------------------------------+
void CAccountInfoDisplay::Processing(void)
{
AccountInfoToChart();
//--- redraw chart
ChartRedraw();
Sleep(50);
}
//+------------------------------------------------------------------+
//| Method InfoToChart. |
//+------------------------------------------------------------------+
void CAccountInfoDisplay::AccountInfoToChart(void)
{
// --- I. Basic Account Information ---
m_label_info[0].Description((string)m_account.Login());
m_label_info[1].Description(m_account.Name());
m_label_info[2].Description(m_account.Server());
m_label_info[3].Description(m_account.Company());
m_label_info[4].Description(m_account.Currency());
m_label_info[5].Description((string)m_account.InfoInteger(ACCOUNT_CURRENCY_DIGITS));
// --- II. Financial Status and Balances ---
m_label_info[6].Description(DoubleToString(m_account.Balance(),2));
m_label_info[7].Description(DoubleToString(m_account.Credit(),2));
m_label_info[8].Description(DoubleToString(m_account.Profit(),2));
m_label_info[9].Description(DoubleToString(m_account.Equity(),2));
// --- III. Margin and Risk Management ---
m_label_info[10].Description(DoubleToString(m_account.Margin(),2));
m_label_info[11].Description(DoubleToString(m_account.FreeMargin(),2));
m_label_info[12].Description(DoubleToString(m_account.MarginLevel(),2));
m_label_info[13].Description(DoubleToString(m_account.MarginCall(),2));
m_label_info[14].Description(DoubleToString(m_account.MarginStopOut(),2));
// --- IV. Trading Modes and Rules ---
m_label_info[15].Description(m_account.TradeModeDescription());
m_label_info[16].Description((string)m_account.Leverage());
m_label_info[17].Description(m_account.MarginModeDescription());
m_label_info[18].Description(m_account.StopoutModeDescription());
m_label_info[19].Description((string)m_account.InfoInteger(ACCOUNT_FIFO_CLOSE));
m_label_info[20].Description((string)m_account.InfoInteger(ACCOUNT_HEDGE_ALLOWED));
// --- V. Trading Permissions ---
m_label_info[21].Description((string)m_account.TradeAllowed());
m_label_info[22].Description((string)m_account.TradeExpert());
}
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart(void)
{
//--- call init function
if(g_accountDisplay.Init())
{
//--- cycle until the script is not halted
while(!IsStopped())
g_accountDisplay.Processing();
}
//--- call deinit function
g_accountDisplay.Deinit();
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+