💡 What: This change defers the calculation of the Donchian Channel high and low within the `OnTick()` function, only performing the calculation if the Donchian breakout feature or the Donchian-based take-profit mode is enabled.
🎯 Why: Previously, the Donchian Channel values were calculated on every new bar, even if the user had disabled the features that rely on them. This caused unnecessary CPU load from the `iHighest` and `iLowest` function calls, which are expensive as they iterate over historical bar data.
📊 Impact: This optimization reduces CPU usage for users who are not utilizing the Donchian Channel features. The EA will run more efficiently, consuming fewer resources, especially on lower-end machines or in environments running many EAs simultaneously. The impact is most significant when the Donchian lookback period is large.
🔬 Measurement:
1. Run the EA in the Strategy Tester with `UseDonchianBreakout = false` and `TPMode != TP_DONCHIAN_WIDTH`.
2. Profile the execution time of the `OnTick()` function.
3. Compare the profiling results with the previous version of the code. The optimized version should show a measurable reduction in the average time spent inside `OnTick()`.
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>
💡 What: Added a lightweight new-bar check using `CopyTime()` at the very beginning of the `OnTick()` function. If a new bar hasn't formed since the last execution, the function exits immediately.
🎯 Why: The original code called the expensive `CopyRates()` function on every single price tick, even though the core logic only needs to run once per bar. This caused significant and unnecessary CPU load, especially during volatile periods.
📊 Impact: This change dramatically reduces the EA's CPU usage. Instead of executing heavy data-copying functions multiple times per second, it now only does so once when a new bar appears. This can lead to a >99% reduction in processing within the `OnTick` handler, improving backtesting speed and reducing the risk of missed ticks in live trading.
🔬 Measurement: The improvement can be verified by observing the EA's processing time in the MetaTrader 5 Strategy Tester's "Profile" tab. Before this change, the `OnTick` function would have a much higher total execution time and frequency of calls. After the change, both metrics will be significantly lower for the same testing period.
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Improves performance by caching the multi-timeframe (MTF) confirmation result.
Previously, the MTF confirmation logic (checking EMA crosses on a lower timeframe) was executed on every price tick. This involved expensive `CopyBuffer` calls, leading to unnecessary CPU usage.
This change introduces a caching mechanism where the MTF result is only recalculated when a new bar forms on the lower timeframe. This drastically reduces redundant computations, resulting in a more efficient Expert Advisor and Indicator, especially in volatile market conditions. The `CopyTime` function is used to efficiently check for a new bar on the `LowerTF`.
A bug in the initial implementation where the `_Symbol` was missing from the `CopyTime` call has been fixed and verified.
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.
- Fix cron entry to use absolute paths instead of variables
- Add parents=True to mkdir for better error handling
- Change PowerShell scheduled task to use Limited privileges for security
- All tests still passing
Co-authored-by: Mouy-leng <199350297+Mouy-leng@users.noreply.github.com>
- AUTOMATION_FEATURES.md with comprehensive feature overview
- Integration test suite for verifying all scripts
- Logs directory README for documentation
- All tests passing successfully
Co-authored-by: Mouy-leng <199350297+Mouy-leng@users.noreply.github.com>
- Python orchestrator with JSON config, logging, and monitoring
- Windows batch script for simple automation
- PowerShell script with scheduled task creation
- Linux/WSL shell script with systemd/cron support
- Detailed documentation and quick start guides
- Example custom script template
- Configuration file with MT5 paths
- Updated .gitignore for logs and temp files
Co-authored-by: Mouy-leng <199350297+Mouy-leng@users.noreply.github.com>
This change adds the ability for the Expert Advisor to send a web request to a user-defined URL when a trading signal is generated. This allows for integration with external services and websites.
The following changes were made:
- Added `EnableWebRequest` and `WebRequestURL` input parameters to the "Notifications" section of the EA.
- Created a new `SendWebRequest` function that sends a POST request with a JSON payload to the specified URL.
- Modified the `Notify` function to call `SendWebRequest` when a notification is triggered.
- Added a comment to the code to remind the user to add the URL to the MetaTrader 5 terminal's list of allowed URLs.