Canvas Tabs: A Lightweight Tab Bar for MQL5 using C Canvas
Info
The Canvas Tabs: A Lightweight Tab Bar for MQL5 using C Canvas is a Expert Advisor for MetaTrader 5 that canvastabs draws a tab bar on a chart using the standard ccanvas class. It is provided as a single include file with no dependencies on DLLs, trading functions, or built-in persistence.
Usage
This tool is typically used for automated trading on major forex pairs and gold.
Platform
This Expert Advisor works exclusively on MetaTrader 5 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL5/Experts folder via File ? Open Data Folder in MetaTrader 5.
How to Install and Use Canvas Tabs: A Lightweight Tab Bar for MQL5 using C Canvas
1. Installation: Open the "File" menu, select "Open Data Folder," navigate to MQL/Experts, paste your file, and restart the terminal.
2. Activation: Drag the EA from the Navigator onto a chart, ensure "Allow live trading" is checked in the Common tab, and verify the AutoTrading button is green.
3. Optimization: Right-click your chart, choose "Expert List," click "Properties" to adjust inputs, and save your preferred setup as a set file for future use.
4. Maintenance: Regularly check the "Experts" tab in the terminal window to monitor trade logs and potential execution errors.
Frequently Asked Questions
Q: Why is my EA not opening trades? A: Check the "AutoTrading" button, ensure "Allow live trading" is enabled, and verify your broker allows automated trading on your account type.
Q: Can I run multiple EAs on one chart? A: No, each chart can only host one active EA; however, you can open multiple charts for different currency pairs to run several EAs.
Q: What does the "smiley face" icon mean? A: A smiley face in the top-right corner of the chart indicates the EA is successfully running; a frowny face means it is disabled.
What this tool does
CanvasTabs draws a tab bar on a chart using the standard CCanvas class.
Typical Use Case
This Expert Advisor excels in automated trading and technical analysis on MetaTrader 5.
Compatible Platform & Setup
This Expert Advisor works on MetaTrader 5. Place the file in the MQL5/Experts folder and restart the terminal.
Description & Settings
Related: 21Hour Pending Order EA - another powerful expert for MetaTrader 5 traders.
CanvasTabs draws a tab bar on a chart using the standard CCanvas class. It is provided as a single include file with no dependencies on DLLs, trading functions, or built-in persistence. This tool is designed for panels that require simple tab functionality without the overhead of a large GUI framework.Also recommended: Expert Advisor: Exp Color Zerolag Tri XO SMA - similar expert with strong performance on MetaTrader 5.
Features
- Tab titles, an active tab indicator, and a simple hover state.
- Selection via mouse click or programmatically using SetActiveTab().
- Width adjustments are handled without recreating the chart object via the Resize() function.
- Long tab titles are automatically shortened to fit within their tab boundaries, with an ellipsis displayed when space permits.
- Supports multiple independent instances on a single chart, each with its own unique object and resource names.
- Height, padding, and font size are scaled dynamically based on the screen's DPI.
- The Destroy() function safely removes the instance's specific objects and resources and can be called multiple times without issue.
Interface
- Create(chart, id, x, y, width, titles): Initializes a new tab instance.
- ActiveTab(): Returns the index of the currently active tab.
- SetActiveTab(index): Programmatically sets the active tab.
- Resize(width): Adjusts the width of the tab bar.
- OnChartEvent(id, lparam, dparam, sparam): Handles chart events, returning true only when a click changes the selected tab.
- Destroy(): Removes the tab instance and its associated resources.
Tab indices are zero-based. The OnChartEvent function returns true exclusively when a mouse click results in a change of the selected tab; hover events, clicks on the already active tab, and clicks outside the tab bar area return false. Coordinates and widths are measured in chart pixels. The minimum supported width is calculated as tab_count * (2 * padding + 2). Invalid width values or tab indices are rejected, and the current state is maintained. Instance IDs must consist of 1 to 16 alphanumeric characters or underscores; existing names are rejected and will not be overwritten.
Example: CanvasTabsDemo
The demonstration showcases two tab bars (one with 3 tabs and another with 4 tabs), each accompanied by a content label below. Pressing the 'P' or 'O' keys allows selection of the next tab for each respective bar. The demo, not the library itself, is responsible for enabling mouse-move events (and restoring the prior setting upon exit) and preserving the selected tabs across symbol or timeframe changes. Note that selected tabs are not retained after a terminal restart.
Input Parameter: TestMode (default: false) activates built-in checks for duplicate names, invalid inputs, repeated resizing operations, repeated destruction calls, and resource cleanup verification.
Installation
- CanvasTabs.mqh: Place in MQL5\Include\CanvasTabs
- CanvasTabsDemo.mq5: Place in MQL5\Experts\CanvasTabsDemo
Tested on MetaTrader 5 build 6230 with a screen DPI of 120 in 2026.
You may also like: multi divergence ea - excellent alternative for expert users on MetaTrader 5.
Source Code
#property copyright "RobotFX"
#property version "1.01"
#property description "This code is educational. Feel free to use, modify and upgrade as you wish. Visit ROBOTFX.ORG for professional trading tools"
#include <CanvasTabs\CanvasTabs.mqh>
input bool TestMode=false;
CCanvasTabs TabsA,TabsB;
string TitlesA[]= {"Overview","Details","Notes"};
string TitlesB[]= {"Summary","A deliberately long tab title","History","Help"};
string LabelA="",LabelB="";
bool OwnLabelA=false,OwnLabelB=false;
.......
⚠ Limitations & Risk Warning
- This tool is provided for educational and testing purposes only.
- Past performance does not guarantee future results.
- Trading involves substantial risk of loss. Use on a demo account first.
- Results may vary depending on market conditions, broker, and settings.
- We recommend thorough backtesting and forward testing before using with real funds.