- Implement lazy loading for MTF direction confirmation to avoid redundant data copying.
- Use native `ArrayFill` for faster indicator buffer clearing in `OnCalculate`.
- Replace `CopyTime` with `iTime` for more efficient lower timeframe bar checks.
- Declare fractal buffers as `static` to reduce memory allocation overhead.
- All changes verified with repository validation and integration tests.
Co-authored-by: Mouy-leng <199350297+Mouy-leng@users.noreply.github.com>
This commit implements several performance optimizations in the SMC_TrendBreakout_MTF_EA.mq5 Expert Advisor:
1. **Early Exit for Open Positions**: Moved the PositionSelect check to the top of the OnTick handler, immediately after the new bar check. This skips expensive indicator data fetching (CopyRates, CopyBuffer) when a position is already open.
2. **Minimized Data Payload**: Reduced the number of bars fetched from 3 to 2 for CopyRates and all CopyBuffer calls. The current strategy logic only requires the current and previous bars.
3. **Lazy Evaluation of Prices and Indicators**: Deferred SymbolInfoTick and ATR fetching until a trade signal is confirmed.
4. **Atomic Price Retrieval**: Replaced non-standard Ask/Bid variables with SymbolInfoTick for more efficient and robust price retrieval in MQL5.
These changes significantly reduce terminal overhead and data transfer per tick, particularly improving performance during optimization and backtesting.
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.