版本 1.1
2024.12.03
👋 Hello everyone!
I want to share a little anecdote with you about an error I recently encountered in our Expert Advisor (EA) and how I fixed it. 🛠️
🔍 The Problem
I was conducting some tests and noticed that the terminal was slowing down more than expected during historical backtesting. Upon investigating, I discovered that a function I had created, Display_Info(), was executing even when it shouldn't.
🤦♂️ What Did I Do Wrong?
The logic I used to control when Display_Info() should execute was incorrect. Initially, the condition I implemented was:
if(ShowInfo && (!MQLInfoInteger(MQL_OPTIMIZATION) || (MQLInfoInteger(MQL_VISUAL_MODE))))
{
Display_Info();
}
I thought this would ensure that the function only executed during live trading or historical backtesting in visual mode. However, the logic allowed Display_Info() to run in undesired contexts, such as during optimizations or non-visual tests, which caused the terminal to slow down.
🔧 The Solution
After carefully analyzing the issue, I adjusted the condition to ensure that Display_Info() only executes in the correct scenarios:
if(ShowInfo &&
(
(!MQLInfoInteger(MQL_OPTIMIZATION) && !MQLInfoInteger(MQL_TESTER)) ||
(MQLInfoInteger(MQL_TESTER) && MQLInfoInteger(MQL_VISUAL_MODE))
)
)
{
Display_Info();
}
✅ Result
Performance Improvement: The terminal no longer slows down during optimizations or non-visual tests.
More Accurate Calculations: Display_Info() now only runs when it is truly necessary, ensuring the accuracy of historical profit calculations.
This author's advisors are some of the best i've seen on the market. With proper risk management, they generate excellent profits - even in such a market as it is now. I recommend it!