mql5-indicator-patterns

Implement MQL5 indicator patterns with buffer management and multi-timeframe support.

62|10|Updated Dec 4, 2025
One-click install
npx skills add https://github.com/terrylica/cc-skills --skill mql5-indicator-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mql5-indicator-patterns
Source: https://github.com/terrylica/cc-skills/tree/main/plugins/mql5/skills/mql5-indicator-patterns
Command: npx skills add https://github.com/terrylica/cc-skills --skill mql5-indicator-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Provides battle-tested patterns for MQL5 indicators, including buffer handling and multi-timeframe considerations.

Core Features & Use Cases

  • Standard buffer architecture (visible/hidden)
  • New bar detection and warmup handling
  • Troubleshooting guidance for OnCalculate and plotting

Quick Start

Apply common patterns to a new MQL5 indicator project

Frequently Asked Questions about mql5-indicator-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure buffers correctly in MQL5 indicators?

MQL5 indicators use a dual-buffer architecture: visible buffers for chart display and hidden buffers to track recalculation state. Assign buffers with SetIndexBuffer(), set PLOT_DRAW_TYPE and PLOT_COLOR, manage array indexing carefully, and maintain proper buffer synchronization during OnCalculate() to prevent data drift and ensure accurate visual output.

What causes OnCalculate() errors and how do I debug them?

Common OnCalculate() failures stem from incorrect buffer indexing, missing warmup calculations, improper new-bar detection, or stale static state. Debug by validating array bounds, confirming rates_total and prev_calculated logic, ensuring buffers are initialized before plotting, and testing on both real-time and backtest data to catch timing issues.

How do I detect new bars in MQL5 to prevent indicator drift?

Implement new-bar detection by comparing the current bar time with a static variable storing the previous bar's timestamp. Process new bars only once per timeframe, reset rolling-window calculations, and use this pattern to prevent duplicate processing that causes indicator values to drift or recalculate unexpectedly.

Can I build multi-timeframe indicators in MetaTrader 5?

Yes. Multi-timeframe MQL5 indicators fetch data from higher timeframes using iClose(), iHigh(), and related functions, then aggregate or combine that data within your OnCalculate() logic. Implement separate buffers for each timeframe, handle asynchronous data loading, and apply warmup calculations to ensure stability across both real-time and backtest scenarios.

Why does my indicator show different values in backtest versus live trading?

Discrepancies occur when warmup calculations are skipped, new-bar detection fails, or static state persists incorrectly between sessions. Ensure prev_calculated resets appropriately, apply enough historical bars for indicator stabilization, and test forward indexing logic to confirm consistent behavior under both backtesting and live market conditions.

What's the best way to manage display scale and buffer visibility in MQL5?

Explicitly set display scale using SetIndexDrawBegin() and PLOT_DRAW_BEGIN, configure visible buffers with SetIndexBuffer(..., true) and hidden buffers with false, apply PLOT_SCALE_TYPE for normalization, and validate that chart-scaling settings don't override your indicator's intended visual range.