mirror of
https://github.com/A6-9V/MQL5-Google-Onedrive.git
synced 2026-04-11 13:00:56 +00:00
Replaces `iHigh()` and `iLow()` function calls with direct array access on the `rates` buffer inside the `OnTick()` function. The `rates` array, containing the necessary high and low price data, was already copied into memory at the beginning of the function. The subsequent calls to `iHigh()` and `iLow()` were redundant and added unnecessary function call overhead to a performance-critical path that executes on every price tick. This change eliminates two function calls from this hot path, resulting in a more efficient Expert Advisor.
3 lines
No EOL
821 B
Markdown
3 lines
No EOL
821 B
Markdown
## 2024-07-25 - MQL5 Native Functions vs. Manual Loops
|
|
**Learning:** I incorrectly assumed that replacing MQL5's native, compiled functions (e.g., `iHighest`, `iLowest`) with a manual `for` loop in MQL5 script would be more performant due to avoiding "function call overhead." The code review made it clear that this is a false premise. The native functions are highly optimized C++ code, and a manual loop in the higher-level MQL5 is significantly slower and can introduce bugs (like using a hardcoded magic number for initialization).
|
|
**Action:** Always trust the platform's built-in, natively compiled functions for performance-critical operations over manual script loops. Do not attempt to micro-optimize these calls without concrete benchmark data proving an improvement. Always favor the robust, built-in solution. |