mql5-indicator-patterns
MQL5 indicator development patterns. TRIGGERS - MQL5 indicator, OnCalculate, indicator buffers, MetaTrader 5.
By terrylica · 473 installs
npx skills add terrylica/cc-skills --skill mql5-indicator-patterns
Source repository · Upstream listing
MQL5 Visual Indicator Patterns
Battle tested patterns for creating custom MQL5 indicators with proper display, buffer management, and real time updates.
Self Evolving Skill : This skill improves through use. If instructions are wrong, parameters drifted, or a workaround was needed — fix this file immediately, don't defer. Only update for real, reproducible issues.
When to Use This Skill
Use this skill when:
Creating custom MQL5 indicators for MetaTrader 5
Debugging indicator display or buffer issues
Setting up OnCalculate with proper warmup handling
Implementing new bar detection patterns
Quick Reference
Essential Patterns
Display Scale (for small values < 1.0):
Buffer Setup (visible + hidden):
New Bar Detection (prevents drift):
Warmup Calculation :
Common Pitfalls
Blank Display : Set explicit scale (see Display Scale reference)
Rolling Window Drift : Use new bar detection with hidden buffer (see Recalculation reference)
Misaligned Plots : Calculate correct PLOT DRAW BEGIN (see Complete Template reference)
Forward Indexed Arrays : Always set ArraySetAsSeries(buffer, false)
Key Patterns
For production MQL5 indicators :
1. Explicit scale for small values (< 1.0 range)
2. Hidden buffers for recalculation tracking
3. New bar detection prevents rolling window drift
4. Static variables maintain state efficiently
5. Proper warmup calculation prevents misalignment
6. Forward indexing for code clarity
These patterns solve the most common indicator development issues encountered in real world MT5 development.
Troubleshooting
Issue Cause Solution
Blank indicator window Scale not set for small values Set INDICATOR MINIMUM/MAXIMUM explicitly
Values drifting over time Rolling window not reset Use new bar detection with hidden buffer
Misaligned plot start Wrong PLOT DRAW BEGIN Calculate: underlying warmup + own warmup
Reversed array indexing Series mode enabled Call ArraySetAsSeries(buffer, false)
Buffer values incorrect Wrong INDICATOR DATA type Use INDICATOR CALCULATIONS for hidden buffers
Compile error on buffer Buffer count mismatch Match property indicator buffers with SetIndexBuffer
Indicator not updating OnCalculate return wrong Return rates total to signal successful calculation
Performance issues Recalculating all bars Only recalculate from prev calculated onwards
Reference Documentation
For detailed information, see:
[Display Scale](./references/display scale.md) Fix blank indicator windows for small values
[Buffer Patterns](./references/buffer patterns.md) Visible and hidden buffer architecture
[Recalculation](./references/recalculation.md) Bar detection and rolling window state management
[Complete Template](./references/complete template.md) Full working example with all patterns
[Debugging](./references/debugging.md) Checklist for troubleshooting display issues
Post Execution Reflection
After this skill completes, check before closing:
1. Did the command succeed? — If not, fix the instruction or error table that caused the failure.
2. Did parameters or output change? — If the underlying tool's interface drifted, update Usage examples and Parameters table to match.
3. Was a workaround needed? — If you had to improvise (different flags, extra steps), update this SKILL.md so the next invocation doesn't need the same workaround.
Only update if the issue is real and reproducible — not speculative.