#1
To calculate the closed profit within a day, three days, and a week, you can use the OrderSelect() function to retrieve information about each closed order, and then calculate the total profit of those orders. For example, to calculate the closed profit within a day, you can use the following code:

double profit_days = 0;
datetime now = TimeLocal();
datetime days_ago = now - 1 * 86400;

int total_orders = OrdersHistoryTotal();

for (int i = 0; i < total_orders; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) 
    {
        if (OrderCloseTime() >= days_ago && OrderCloseTime() < now && (OrderProfit() > 0 || OrderProfit() < 0)) 
        {
            profit_days += OrderProfit() + OrderSwap() + OrderCommission();
        }
    }
}
To calculate the closed profit within three days and a week, you can modify the value of the days_ago variable accordingly. For example, to calculate the closed profit within three days, you can use:

datetime days_ago = now - 3 * 86400;
And to calculate the closed profit within a week, you can use:

datetime days_ago = now - 7 * 86400;
Please note that the above code snippet only calculates the total profit of closed orders with positive or negative profit. If you want to calculate the total profit of all closed orders, including orders with negative profit, you need to modify the condition in the loop.

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