mql5-indicator-patterns
MQL5 indicator development patterns. TRIGGERS - MQL5 indicator, OnCalculate, indicator buffers, MetaTrader 5.
What this skill does
# 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): ```mql5 IndicatorSetDouble(INDICATOR_MINIMUM, 0.0); IndicatorSetDouble(INDICATOR_MAXIMUM, 0.1); ``` **Buffer Setup** (visible + hidden): ```mql5 SetIndexBuffer(0, BufVisible, INDICATOR_DATA); // Visible SetIndexBuffer(1, BufHidden, INDICATOR_CALCULATIONS); // Hidden ``` **New Bar Detection** (prevents drift): ```mql5 static int last_processed_bar = -1; bool is_new_bar = (i > last_processed_bar); ``` **Warmup Calculation**: ```mql5 int StartCalcPosition = underlying_warmup + own_warmup; PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, StartCalcPosition); ``` --- ## 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.
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.