#1
Here is an example of how to calculate current profit using a function in MQL4:

double Profit()
{
    double initialBalance = AccountBalance();  // Initial balance
    double currentBalance = AccountBalance();  // Current balance

// Iterate through all executed orders within the day
    for (int i = 0; i < OrdersTotal(); i++)
    {
        if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
        // Check if the order was executed within the day
            if (TimeDay(OrderOpenTime()) == TimeDay(TimeCurrent()))
            {
                double profit = OrderProfit();
                currentBalance += profit;
            }
        }
    }

    double dailyProfit = currentBalance - initialBalance;
    return dailyProfit;
}

void OnStart()
{
    double profit = Profit();
    Print("Profit: ", profit);
}
In the given example, the Profit() function calculates the profit for a day based on the executed orders within that day. It first retrieves the initial balance and the current balance of the account. Then, it iterates through all the orders executed within the day and calculates the profit for each order. Finally, it returns the total profit. In the OnStart() function, we call the Profit() function and print the daily profit to the Terminal window using the Print() function. You can modify or expand this source code to fit your requirements.

image quote pre code
Xem hướng dẫn đăng nhập để đăng bình luận Tại Đây
Chia sẻ: