Current Relative Retracement - MetaTrader 5 Expert | MT5 EA Download - MetaTrader 5 Resources
The DD_Relative function calculates the relative profit or loss (drawback) of the current trading account in percentage. To do this, it gets the current profit or loss of all open positions using the Current_LossOrProfit() function and then divides it by the current account balance obtained through the AccountInfoDouble(ACCOUNT_BALANCE) function.
After calculating the relative gain or loss as a percentage, the function uses the NormalizeDouble() function to round the result to two decimal places, and then uses the Comment() function to display the result in a chart comment. Finally, the function returns the relative gain or loss as a percentage result.
The Current_LossOrProfit() function is used to calculate the current profit or loss of all open positions in a trading account. Use a for loop to iterate through all open positions and for each position check whether its magic number matches the magic number specified in the ticker (MAGIC) and whether the symbol of the position is the same as the current symbol on the chart. If the position meets these conditions, the position's commission, overnight interest, and current profit and loss will be added to the Positionsprofit variable.
After adding up all profits and losses for the position, the function rounds the result to two decimal places using the NormalizeDouble() function and returns the value of the current profit or loss.
Attachment download
📎 dd_relative.mq5 (5.75 KB)
Source: MQL5 #42874
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •