//+------------------------------------------------------------------+
//| Information EA-MT5 |
//| Copyright of Taube Adrian |
//| Started- 19, August, 2024 |
//| Modified- 28, August, 2024 |
//| Further Modified- 25, September, 2024 |
//| Further Modified- 02, October, 2024 |
//+------------------------------------------------------------------+
#property strict
// Input variables for customization
input int textX = 10; // X position on chart
input int textY = 10; // Y position on chart
input int textSize = 12; // Text size
input color textColor = clrWhite; // Text color
input int lineSpacing = 15; // Spacing between lines
input int timerInterval = 1; // Timer interval in seconds
// Variables to track equity changes for notifications
double initialEquity = 0; // Track the starting equity when EA is installed
// Track the last known day to reset daily values after 12 AM broker time
int lastDay = 0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Set the initial minEquity and daily values
initialEquity = AccountInfoDouble(ACCOUNT_EQUITY);
minEquity = initialEquity;
ResetDailyValues();
// Create text objects on the chart
CreateTextLabel("MaxDrawdown", "Maximum Account Drawdown = 0", textX, textY);
CreateTextLabel("DailyMaxDrawdown", "TODAY Maximum Account Drawdown = 0", textX, textY + lineSpacing);
CreateTextLabel("MaxTempProfit", "Maximum Account Temporary Profit = 0", textX, textY + 2 * lineSpacing);
CreateTextLabel("DailyMaxTempProfit", "TODAY Maximum Account Temporary Profit = 0", textX, textY + 3 * lineSpacing);
CreateTextLabel("MaxMargin", "Maximum Account Margin = 0", textX, textY + 4 * lineSpacing);
CreateTextLabel("DailyMaxMargin", "TODAY Maximum Account Margin = 0", textX, textY + 5 * lineSpacing);
CreateTextLabel("MaxEquity", "Maximum Account Equity = 0", textX, textY + 6 * lineSpacing);
CreateTextLabel("DailyMaxEquity", "TODAY Maximum Account Equity = 0", textX, textY + 7 * lineSpacing);
Assistant
Hello! It looks like you've shared the code for an Expert Advisor (EA) for MetaTrader 5 (MT5) that monitors and displays various account metrics, such as maximum drawdown, temporary profit, margin, equity, and sends notifications when the equity changes by a specified amount.
How can I assist you with this code? Are you experiencing any issues, or do you need help with understanding, modifying, or enhancing it? Please let me know how I can help!
// Send a notification if the equity change exceeds the threshold (positive or negative)
if (MathAbs(equityChange) >= equityChangeNotification)
{
// Determine if equity increased or decreased
string changeDirection = (equityChange > 0.0) ? "UP" : "DOWN";
code
// Get broker name and account type (LIVE=REAL or DEMO)
string brokerName = AccountInfoString(ACCOUNT_COMPANY);
string accountType = (AccountInfoInteger(ACCOUNT_TRADE_MODE) == ACCOUNT_TRADE_MODE_DEMO)
? "DEMO"
: "LIVE=REAL";
// Send notification
string message = StringFormat(
"Equity %s by %.2f %s.\n" // Line 1: Equity change (UP or DOWN)
"Current Equity = %.2f %s.\n" // Line 2: Current equity
"Broker: %s.\n" // Line 3: Broker name
"Account: %s.", // Line 4: Account type (LIVE=REAL or DEMO)
changeDirection, // Equity direction (UP or DOWN)
MathAbs(equityChange), // Absolute value of equity change
AccountInfoString(ACCOUNT_CURRENCY), // Currency (e.g., USD)
currentEquity, // Current equity value
AccountInfoString(ACCOUNT_CURRENCY), // Currency (e.g., USD)
brokerName, // Broker name
accountType // Account type (LIVE=REAL or DEMO)
);
SendNotification(message);
// Reset the initial equity to the current equity for tracking further changes
initialEquity = currentEquity;
}
// Reset daily values after 12 AM broker time
CheckAndResetDailyValues();
}
//+------------------------------------------------------------------+
//| Timer function for regular updates |
//+------------------------------------------------------------------+
void OnTimer()
{
UpdateAccountInfo();
}
//+------------------------------------------------------------------+
//| Function to update account info and text labels |
//+------------------------------------------------------------------+
void UpdateAccountInfo()
{
// Get the account currency symbol
string currencySymbol = AccountInfoString(ACCOUNT_CURRENCY);
// Get current account values
double equity = AccountInfoDouble(ACCOUNT_EQUITY);
double balance = AccountInfoDouble(ACCOUNT_BALANCE);
double margin = AccountInfoDouble(ACCOUNT_MARGIN);
// Set font size and color for all labels
SetTextProperties("MaxDrawdown");
SetTextProperties("DailyMaxDrawdown");
SetTextProperties("MaxTempProfit");
SetTextProperties("DailyMaxTempProfit");
SetTextProperties("MaxMargin");
SetTextProperties("DailyMaxMargin");
SetTextProperties("MaxEquity");
SetTextProperties("DailyMaxEquity");
SetTextProperties("MinEquity");
SetTextProperties("DailyMinEquity");
}
//+------------------------------------------------------------------+
//| Function to reset daily values |
//+------------------------------------------------------------------+
void ResetDailyValues()
{
dailyMaxDrawdown = 0;
dailyMaxTemporaryProfit = 0;
dailyMaxMargin = 0;
dailyMaxEquity = AccountInfoDouble(ACCOUNT_EQUITY);
dailyMinEquity = AccountInfoDouble(ACCOUNT_EQUITY);
}
//+------------------------------------------------------------------+
//| Function to create or update text label on the chart |
//+------------------------------------------------------------------+
void CreateTextLabel(string name, string text, int x, int y)
{
if (!ObjectFind(0, name))
{
ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_UPPER);
ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x);
ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y);
}
ObjectSetString(0, name, OBJPROP_TEXT, text);
}
//+------------------------------------------------------------------+
//| Function to set text properties for labels |
//+------------------------------------------------------------------+
void SetTextProperties(string name)
{
ObjectSetInteger(0, name, OBJPROP_COLOR, textColor);
ObjectSetInteger(0, name, OBJPROP_FONTSIZE, textSize);
}
//+------------------------------------------------------------------+
//| Function to check and reset daily values at 12 AM |
//+------------------------------------------------------------------+
void CheckAndResetDailyValues()
{
datetime currentTime = TimeCurrent();
int currentDay = TimeDay(currentTime);
// If the day has changed (i.e., it's a new day), reset daily values
if (currentDay != lastDay)
{
ResetDailyValues();
lastDay = currentDay;
}
}
//+------------------------------------------------------------------+