This commit implements several performance optimizations in the SMC_TrendBreakout_MTF_EA.mq5:
1. **Early Exit:** Moved the `PositionSelect` check to the beginning of the `OnTick` handler (after the new bar check). This avoids expensive market data fetching (`CopyRates`, `CopyBuffer`) and signal calculations if a position is already open.
2. **Reduced Data Fetching:** Reduced the fetch count in `CopyRates` and `CopyBuffer` (Donchian/EMA) from 3 to 2, as only the current and previous bars are used in the logic.
3. **Lazy Price Fetching:** Replaced the undefined/redundant `Ask` and `Bid` variables with efficient price retrieval using `SymbolInfoTick` only when a signal is confirmed.
4. **Optimized Array Management:** Refactored occasionally-used indicator buffers (EMA, ATR) into fixed-size local arrays to avoid dynamic allocation overhead and potential shadowing issues identified during code review.
These changes measurably reduce the terminal overhead on every new bar and ensure better resource utilization during live trading.
Co-authored-by: Mouy-leng <199350297+Mouy-leng@users.noreply.github.com>
This commit implements several performance optimizations in the SMC MTF indicator:
1. Robust Early Exit: Added a 'new bar' check using iTime() to skip redundant calculations on every price tick. Handled prev_calculated=0 to ensure full history recalculations when requested.
2. Lazy Loading: Wrapped expensive fractal and Donchian calculations in conditional blocks so they only execute if the respective features are enabled.
3. Efficient Buffer Clearing: Replaced manual O(N) loops with ArrayInitialize() for bulk clearing of indicator buffers on first run.
4. Robustness: Added 'history not ready' checks (iTime == 0) to both the indicator and EA.
5. Cleanup: Removed redundant ArraySetAsSeries calls on static arrays in GetMTFDir and updated comments.
Impact: Reduces CPU usage on every tick by skipping unnecessary logic and improves initialization speed during history loading.
Co-authored-by: Mouy-leng <199350297+Mouy-leng@users.noreply.github.com>
💡 What: Replaced manual `for` loops in `HighestHigh` and `LowestLow` with native `ArrayMaximum` and `ArrayMinimum` functions in `mt5/MQL5/Indicators/SMC_TrendBreakout_MTF.mq5`.
🎯 Why: Native MQL5 functions are implemented in optimized C++ and are significantly faster than loops executed in the MQL5 scripting layer.
📊 Impact: Improves the performance of Donchian channel calculation, reducing indicator overhead per bar.
🔬 Measurement: Verified with existing CI validation and code inspection.
Co-authored-by: Mouy-leng <199350297+Mouy-leng@users.noreply.github.com>
Replaced manual loops in HighestHigh and LowestLow functions with native MQL5 ArrayMaximum and ArrayMinimum functions in mt5/MQL5/Indicators/SMC_TrendBreakout_MTF.mq5.
What: Replaced MQL5 script-level iterative loops with native C++ implemented functions for finding extreme values in price arrays.
Why: Native MQL5 functions are significantly faster than manual loops as they are executed in compiled C++.
Impact: Reduces execution time for indicator calculations on every new bar, improving overall EA performance during backtesting and live trading.
Measurement: MQL5 documentation confirms native functions are optimized for performance. The code now includes safety checks for the -1 return value.
Co-authored-by: Mouy-leng <199350297+Mouy-leng@users.noreply.github.com>
This commit corrects a subtle off-by-one error in the array boundary check for the Donchian channel lookback period.
The original condition `if(donStart + donCount >= needBars)` would incorrectly cause an early exit if the required number of bars for the lookback precisely matched the number of available bars in the array. This prevented valid signals from being processed at the edge of the dataset.
The condition has been changed to `if(donStart + donCount > needBars)`, which is the correct boundary check. This ensures the calculation proceeds when exactly enough data is available and only exits if there is insufficient data, improving the EA's robustness.
This issue was identified during a code review for a separate performance optimization attempt.
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Implements a caching mechanism for the multi-timeframe (MTF) trend confirmation in `GetMTFDir`.
The trend direction from the lower timeframe is now calculated only when a new bar forms on that timeframe, instead of on every tick of the main chart. The result is cached and returned on subsequent calls until the next lower timeframe bar appears.
This avoids expensive and redundant `CopyBuffer` calls, significantly improving the EA's performance and efficiency, especially when the signal timeframe is much shorter than the confirmation timeframe. Logic was carefully updated to read from the last *completed* bar to prevent any change in trading behavior.