Article-22460-Custom-Tick-C.../README.md

5 KiB

Article-22460-Custom-Tick-Chart-MQL5

This repository is an article-derived reference project based on the original MQL5 article. It does not claim to reproduce the full original source code unless files are explicitly attached.

Overview

This project documents the implementation of a custom tick chart in MQL5. Instead of building candles on fixed time intervals, the described Expert Advisor aggregates a configurable number of ticks into synthetic OHLC bars and publishes them to a custom symbol.

The article focuses on:

  • creating or reusing a custom symbol;
  • optionally opening a chart for that symbol;
  • collecting live ticks from the source instrument;
  • forming OHLC bars after N ticks;
  • updating the currently forming bar in real time with CustomRatesUpdate;
  • ensuring monotonically increasing bar timestamps.

Original Article

Repository Purpose

This repository serves as a technical reference and possible reconstruction base for the article’s tick-chart EA.

Its purpose is to preserve the core architecture explained in the article for developers who want to study or reimplement:

  • activity-driven candles based on tick count;
  • custom-symbol chart rendering in MetaTrader 5;
  • real-time candle updates via CustomRatesUpdate;
  • timestamp management for synthetic bars.

Key Concepts

  • Custom symbol creation: using CustomSymbolCreate and copying essential symbol properties from the source symbol.
  • Chart lifecycle management: checking whether a chart for the custom symbol is already open and opening one if needed.
  • Tick aggregation: counting incoming ticks and grouping them into fixed-size bars.
  • OHLC tracking: setting open on the first tick, updating high/low during formation, and refreshing close on every tick.
  • Completed bar commit: pushing finalized MqlRates data to the custom symbol.
  • Live bar update: updating the currently forming candle on every incoming tick.
  • Monotonic timestamps: ensuring each synthetic bar has a unique increasing datetime.

Algorithm / Architecture Summary

  1. Initialization
  • Read user inputs such as custom symbol name, auto-open-chart flag, and ticks-per-bar.
  • Create the custom symbol if it does not already exist.
  • Copy selected market properties from the source symbol, including digits, point, tick size, and currency metadata.
  • Optionally open a chart for the custom symbol.
  1. Chart existence check
  • Iterate through currently open charts using ChartFirst() / ChartNext().
  • Compare symbol and timeframe to avoid opening duplicate charts.
  1. Tick processing
  • On every OnTick(), retrieve the latest tick using SymbolInfoTick.
  • Validate the tick and use the bid price as the aggregation reference.
  1. Bar formation
  • If this is the first tick of a new bar, initialize open, high, low, close, and bar time.
  • For subsequent ticks, update high, low, and close.
  • Increment the tick counter.
  1. Live bar rendering
  • Build a MqlRates structure for the currently forming bar.
  • Call CustomRatesUpdate so the chart reflects the live candle state on every tick.
  1. Bar finalization
  • When the configured tick count is reached, create a completed MqlRates record.
  • Enforce increasing timestamps using a last_bar_time reference.
  • Push the completed bar to the custom symbol with CustomRatesUpdate.
  • Reset internal state for the next bar.

Mentioned or Attached Files

Explicitly attached files

No attached source files were available in the processed input.

Files mentioned in the article text

The article describes an Expert Advisor implementation, but no concrete filename was provided in the processed content.

Statistics

  • Article ID: 22460
  • Language: en
  • Sections identified: 4 main sections
  • Code examples identified: 7
  • Attached files available: 0

Tags

MQL5, MetaTrader 5, Custom Symbol, Tick Chart, CustomRatesUpdate, Expert Advisor, Synthetic Bars, OHLC Aggregation

Difficulty

Intermediate

Requires familiarity with:

  • MQL5 event handling (OnInit, OnTick);
  • MqlTick and MqlRates;
  • chart and symbol management APIs;
  • custom symbol data updates in MetaTrader 5.

Limitations

  • The full original source code is unavailable in the processed input.
  • The repository can only be presented as a reference/reconstruction project based on article excerpts and explanations.
  • No complete EA file, project structure, or attachable implementation assets were provided.
  • Some metadata, naming, and packaging details may need manual reconstruction before use in MetaTrader 5.
  • The article demonstrates core logic, but does not provide enough repository-level detail to guarantee drop-in compilation without reconstruction.

Reference

Original article: https://www.mql5.com/en/articles/22460