Changing Moving Average Parameters with MQL5 Chart Events
Summary
The article shows how an MQL5 custom moving average indicator can respond to keyboard events so a trader can change its method, period, and chart shift while it is running. Because indicator input parameters cannot be modified directly in code, the implementation copies their roles into variables and uses terminal global variables to hold the current settings. An event handler updates those values and triggers recalculation.
The example describes handling key presses, recalculating the indicator history when settings change, and retaining incremental calculation when they do not. It also adjusts the linear weighted moving average calculation to avoid a persistent weight sum becoming incorrect after repeated parameter changes. The author demonstrates the behavior with an example and video, but provides no performance measurements. A key limitation is that manually editing a terminal global variable does not itself trigger an indicator event; a suitable key press is needed to force a full update. The technique suits indicators whose full recalculation is inexpensive.
Key ideas
- An MQL5 indicator can use chart events to change its settings through keyboard input.
- Mutable global variables can replace input parameters when settings must change during runtime.
- Changed settings require recalculating indicator values across the available history.
- A persistent weight sum can become stale when a moving average period changes.
- Manual edits to terminal global variables may not update the indicator until another event triggers recalculation.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.