### Getting Started Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/README.md Resources for beginners to start using the MQL5 Controls Library, including tutorials and basic control guides. ```APIDOC ## Getting Started This section provides resources for beginners to quickly start developing with the MQL5 Controls Library. ### Getting Started Tutorial - **Description**: A step-by-step tutorial to create your first panel in MQL5 within 10 minutes. - **Endpoint**: `./docs/tutorials/getting-started.md` ### Basic Controls - **Description**: Learn about fundamental controls such as buttons and input fields. - **Example Control**: `CButton` - **Endpoint**: `./docs/simple-controls/CButton.md` ### Layout Management - **Description**: Understand how to position and size controls effectively within your panel. - **Endpoint**: `./docs/tutorials/layout-management.md` ``` -------------------------------- ### Advanced Developer Guides Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/README.md Advanced topics for experienced developers, including dynamic patterns, customization, and production examples. ```APIDOC ## Advanced Developer Guides This section covers advanced techniques and best practices for experienced MQL5 developers. ### Advanced Patterns - **Description**: Discover sophisticated techniques for dynamic control manipulation and runtime discovery. - **Endpoint**: `./docs/tutorials/advanced-patterns.md` ### Customization Guide - **Description**: Learn how to implement custom themes, branding, and advanced styling for your MQL5 applications. - **Endpoint**: `./docs/tutorials/customization.md` ### Production Examples - **Description**: Explore complete trading applications demonstrating production-ready implementations and best practices. - **Endpoint**: `./docs/examples/production-examples.md` ``` -------------------------------- ### MQL5 Event Handling Setup Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/examples/production-examples.md Defines how user interface events like clicks and changes are mapped to specific callback functions within the CAppDialog class. This allows for modular and organized event processing. ```MQL5 ON_EVENT(ON_CLICK, m_sell_button, OnSellButtonClick) ON_EVENT(ON_CLICK, m_close_all_button, OnCloseAllButtonClick) ON_EVENT(ON_CHANGE, m_lot_size, OnLotSizeChange) ON_EVENT(ON_CHANGE, m_stop_loss, OnStopLossChange) ON_EVENT(ON_CHANGE, m_take_profit, OnTakeProfitChange) ON_EVENT(ON_CHANGE, m_symbol_selector, OnSymbolChange) ON_EVENT(ON_CHANGE, m_expiry_date, OnExpiryDateChange) ON_EVENT(ON_CHANGE, m_order_type_group, OnOrderTypeChange) ON_EVENT(ON_CHANGE, m_trade_options_group, OnTradeOptionsChange) ON_EVENT(ON_CLICK, m_positions_list, OnPositionsListClick) EVENT_MAP_END(CAppDialog) ``` -------------------------------- ### MQL5: Implement Panel Class and Controls Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/tutorials/getting-started.md This MQL5 code implements the `Create` and `CreateControls` methods for a custom panel class. The `Create` method initializes the main dialog, while `CreateControls` programmatically adds various UI elements like a title label, a symbol input field, and BUY/SELL buttons. It handles layout and basic styling for these controls. ```mql5 //+------------------------------------------------------------------+ //| Create the panel and its controls | //+------------------------------------------------------------------+ bool CMyFirstPanel::Create(const long chart_id, const string name, const int subwin, const int x1, const int y1, const int x2, const int y2) { // Create the main dialog if(!CAppDialog::Create(chart_id, name, subwin, x1, y1, x2, y2)) return false; // Create all controls return CreateControls(); } //+------------------------------------------------------------------+ //| Create individual controls | //+------------------------------------------------------------------+ bool CMyFirstPanel::CreateControls(void) { int margin = 10; int row_height = 30; int y_pos = margin; // Title label if(!m_label_title.Create(m_chart_id, m_name+"Title", m_subwin, margin, y_pos, ClientAreaWidth()-margin, y_pos+20)) return false; m_label_title.Text("Trading Panel"); m_label_title.Font("Arial Bold"); m_label_title.FontSize(14); m_label_title.Color(clrBlue); Add(m_label_title); y_pos += row_height; // Symbol input if(!m_edit_symbol.Create(m_chart_id, m_name+"Symbol", m_subwin, margin, y_pos, ClientAreaWidth()-margin, y_pos+25)) return false; m_edit_symbol.Text(Symbol()); // Default to current chart symbol Add(m_edit_symbol); y_pos += row_height + 10; // Buy button int button_width = (ClientAreaWidth() - 3 * margin) / 2; if(!m_button_buy.Create(m_chart_id, m_name+"Buy", m_subwin, margin, y_pos, margin+button_width, y_pos+30)) return false; m_button_buy.Text("BUY"); m_button_buy.ColorBackground(clrGreen); m_button_buy.Color(clrWhite); Add(m_button_buy); // Sell button if(!m_button_sell.Create(m_chart_id, m_name+"Sell", m_subwin, margin*2+button_width, y_pos, ClientAreaWidth()-margin, y_pos+30)) return false; m_button_sell.Text("SELL"); m_button_sell.ColorBackground(clrRed); m_button_sell.Color(clrWhite); Add(m_button_sell); return true; } ``` -------------------------------- ### MQL5 Button Control Example Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/README.md Demonstrates the basic usage of a button control in MQL5, including its creation and event handling. This example is suitable for beginners learning about UI elements. ```MQL5 // Example for CButton control // ... (button creation and event handling code) ... ``` -------------------------------- ### Intermediate Developer Guides Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/README.md Guides for intermediate developers focusing on event handling, complex controls, and EA integration. ```APIDOC ## Intermediate Developer Guides Resources tailored for developers looking to deepen their understanding of the MQL5 Controls Library. ### Event Handling - **Description**: Master the `EVENT_MAP` system for efficient event management within your applications. - **Endpoint**: `./docs/tutorials/event-handling.md` ### Complex Controls - **Description**: Learn to implement and manage complex controls like data lists and selection components. - **Example Control**: `CListView` - **Endpoint**: `./docs/complex-controls/CListView.md` ### EA Integration - **Description**: Integrate MQL5 panels seamlessly into Expert Advisors (EAs) with complete lifecycle management. - **Endpoint**: `./docs/tutorials/ea-integration.md` ``` -------------------------------- ### Include Headers for MQL5 Panel Controls Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/tutorials/getting-started.md This snippet shows the standard headers required for creating a graphical panel in MQL5. It includes functionality for dialogs, buttons, labels, and editable text fields. These headers provide the base classes and methods for building interactive user interfaces within MetaTrader 5. ```mql5 #include // Main dialog functionality #include // Button controls #include // Text labels #include // Text input fields ``` -------------------------------- ### Create MQL5 Panel Structure and Controls Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/tutorials/getting-started.md This MQL5 code demonstrates the basic structure for creating a custom panel within MetaTrader 5 using the Controls Library. It includes the declaration of a panel class inheriting from CAppDialog, the creation of various controls (Label, Edit, Button), and the initialization and deinitialization logic for the Expert Advisor that hosts the panel. Dependencies include the MQL5 Controls Library headers. ```mql5 //+------------------------------------------------------------------+ //| MyFirstPanel.mq5 | //| Copyright 2025, Your Name | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, Your Name" #property link "" #property version "1.00" #include #include #include #include // Panel class declaration class CMyFirstPanel : public CAppDialog { private: CLabel m_label_title; CEdit m_edit_symbol; CButton m_button_buy; CButton m_button_sell; public: virtual bool Create(const long chart_id, const string name, const int subwin, const int x1, const int y1, const int x2, const int y2); virtual bool OnEvent(const int id, const long &lparam, const double &dparam, const string &sparam); protected: bool CreateControls(void); void OnButtonBuy(void); void OnButtonSell(void); }; // Global panel instance CMyFirstPanel MyPanel; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { // Create the panel if(!MyPanel.Create(0, "MyFirstPanel", 0, 50, 50, 300, 200)) { Print("Failed to create panel"); return INIT_FAILED; } MyPanel.Show(); return INIT_SUCCEEDED; } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { MyPanel.Destroy(); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { // Handle tick events if needed } //+------------------------------------------------------------------+ //| Chart event function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { MyPanel.OnEvent(id, lparam, dparam, sparam); } ``` -------------------------------- ### MQL5 CDialog Example Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/api/class-hierarchy.md This MQL5 code snippet shows the basic setup for a CDialog, which serves as a main application window or a modal dialog. It provides functionality for creating title bars, client areas, and control buttons. ```mql5 #include // ... inside OnInit() or another function ... // Create a CDialog instance CDialog myDialog; // Initialize and configure the dialog if(myDialog.Create(0, "MyDialogID", 100, 100, 300, 200)) { myDialog.Caption("My Application Dialog"); myDialog.CreateCaption(); myDialog.CreateClientArea(); myDialog.CreateButtonClose(); myDialog.Show(); } ``` -------------------------------- ### MQL5 Trading Panel Creation and Event Handling Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/tutorials/getting-started.md This MQL5 code defines a custom trading panel class 'CMyFirstPanel' which inherits from 'CAppDialog'. It includes functionality to create UI elements like labels, input fields, and buttons, and handles user interactions such as button clicks to simulate trading orders. Dependencies include MQL5's standard control libraries. ```mql5 //+------------------------------------------------------------------+ //| MyFirstPanel.mq5 | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, Your Name" #property version "1.00" #include #include #include #include class CMyFirstPanel : public CAppDialog { private: CLabel m_label_title; CEdit m_edit_symbol; CButton m_button_buy; CButton m_button_sell; public: virtual bool Create(const long chart_id, const string name, const int subwin, const int x1, const int y1, const int x2, const int y2); virtual bool OnEvent(const int id, const long &lparam, const double &dparam, const string &sparam); protected: bool CreateControls(void); void OnButtonBuy(void); void OnButtonSell(void); }; CMyFirstPanel MyPanel; int OnInit() { if(!MyPanel.Create(0, "MyFirstPanel", 0, 50, 50, 300, 200)) return INIT_FAILED; MyPanel.Show(); return INIT_SUCCEEDED; } void OnDeinit(const int reason) { MyPanel.Destroy(); } void OnTick() { } void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { MyPanel.OnEvent(id, lparam, dparam, sparam); } bool CMyFirstPanel::Create(const long chart_id, const string name, const int subwin, const int x1, const int y1, const int x2, const int y2) { if(!CAppDialog::Create(chart_id, name, subwin, x1, y1, x2, y2)) return false; return CreateControls(); } bool CMyFirstPanel::CreateControls(void) { int margin = 10; int row_height = 30; int y_pos = margin; // Title if(!m_label_title.Create(m_chart_id, m_name+"Title", m_subwin, margin, y_pos, ClientAreaWidth()-margin, y_pos+20)) return false; m_label_title.Text("Trading Panel"); m_label_title.Font("Arial Bold"); m_label_title.Color(clrBlue); Add(m_label_title); y_pos += row_height; // Symbol input if(!m_edit_symbol.Create(m_chart_id, m_name+"Symbol", m_subwin, margin, y_pos, ClientAreaWidth()-margin, y_pos+25)) return false; m_edit_symbol.Text(Symbol()); Add(m_edit_symbol); y_pos += row_height + 10; // Buttons int button_width = (ClientAreaWidth() - 3 * margin) / 2; if(!m_button_buy.Create(m_chart_id, m_name+"Buy", m_subwin, margin, y_pos, margin+button_width, y_pos+30)) return false; m_button_buy.Text("BUY"); m_button_buy.ColorBackground(clrGreen); Add(m_button_buy); if(!m_button_sell.Create(m_chart_id, m_name+"Sell", m_subwin, margin*2+button_width, y_pos, ClientAreaWidth()-margin, y_pos+30)) return false; m_button_sell.Text("SELL"); m_button_sell.ColorBackground(clrRed); Add(m_button_sell); return true; } bool CMyFirstPanel::OnEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { if(id == CHARTEVENT_OBJECT_CLICK) { if(sparam == m_button_buy.Name()) { OnButtonBuy(); return true; } if(sparam == m_button_sell.Name()) { OnButtonSell(); return true; } } return CAppDialog::OnEvent(id, lparam, dparam, sparam); } void CMyFirstPanel::OnButtonBuy(void) { string symbol = m_edit_symbol.Text(); Alert("Buy order for " + symbol); } void CMyFirstPanel::OnButtonSell(void) { string symbol = m_edit_symbol.Text(); Alert("Sell order for " + symbol); } ``` -------------------------------- ### MQL5 CDateTime: Basic Date/Time Operations Example Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/auxiliary/CDateTime.md Demonstrates basic usage of the CDateTime class, including setting current date/time, retrieving date/time components, obtaining month and day names, and performing simple time arithmetic. This example shows how to include the header file and utilize core methods. ```MQL5 #include void ExampleBasicDateTime() { CDateTime dt; // Set current date/time dt.DateTime(TimeCurrent()); Print("Current date/time information:"); Print(" Full date: ", dt.year, "/", dt.mon, "/", dt.day); Print(" Full time: ", dt.hour, ":", dt.min, ":", dt.sec); Print(" Month name: ", dt.MonthName()); Print(" Short month: ", dt.ShortMonthName()); Print(" Day name: ", dt.DayName()); Print(" Short day: ", dt.ShortDayName()); Print(" Days in month: ", dt.DaysInMonth()); Print(" Day of year: ", dt.day_of_year); // Time arithmetic examples dt.HourInc(2); Print("After adding 2 hours: ", TimeToString(dt.DateTime())); dt.DayDec(1); Print("After subtracting 1 day: ", TimeToString(dt.DateTime())); dt.MonInc(1); Print("After adding 1 month: ", TimeToString(dt.DateTime())); } ``` -------------------------------- ### Popular Use Cases Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/README.md Examples of common applications and trading tools that can be built using the MQL5 Controls Library. ```APIDOC ## Popular Use Cases The MQL5 Controls Library is versatile and can be used for a variety of trading-related applications. ### Trading Panels - **Description**: Create panels for buy/sell execution, position management, and risk control. ### Analysis Tools - **Description**: Develop tools for chart navigation, indicator settings configuration, and data visualization. ### Risk Management - **Description**: Implement sophisticated risk management features like position sizing and stop-loss controls. ### Account Management - **Description**: Build interfaces for monitoring account balance, equity, and trade history. ### Custom Indicators - **Description**: Design custom settings panels and alert configurations for indicators. ``` -------------------------------- ### MQL5 CWndObj - Basic Control Setup Pattern Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/foundation/CWndObj.md Illustrates a common pattern for creating and configuring a simple control, setting its text, colors, font, and Z-order. ```mql5 // Create and configure a simple control if(control.Create(chart_id, "MyControl", 0, 10, 10, 200, 50)) { control.Text("Click Me"); control.Color(clrWhite); control.ColorBackground(clrBlue); control.Font("Arial Bold"); control.FontSize(14); control.ZOrder(100); } ``` -------------------------------- ### Prepare Buy Order Request Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/examples/production-examples.md Prepares an MqlTradeRequest structure for executing a buy order. It validates trade inputs, sets the action to TRADE_ACTION_DEAL, and specifies the symbol for the order. ```MQL5 bool CTradingControlsDialog::ExecuteBuyOrder() { if(!ValidateTradeInputs()) return false; MqlTradeRequest request = {}; MqlTradeResult result = {}; // Prepare buy order request.action = TRADE_ACTION_DEAL; request.symbol = m_selected_symbol; ``` -------------------------------- ### MQL5 Custom Theming Example Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/README.md Demonstrates how to apply custom themes, including dark themes and branded interfaces, to MQL5 panels. This snippet focuses on styling controls for a unique look. ```MQL5 // Example for custom theming in MQL5 // ... (code for setting colors, fonts, and styles) ... ``` -------------------------------- ### MQL5 Expert Advisor Setup for Panel Events Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/tutorials/event-handling.md Demonstrates the essential Expert Advisor setup required to integrate an MQL5 panel and delegate chart events to it. It includes the necessary include directive for controls, a custom panel class inheriting from CAppDialog, and the crucial OnChartEvent function to route events. ```mql5 #include class CMyPanel : public CAppDialog { public: virtual bool OnEvent(const int id, const long &lparam, const double &dparam, const string &sparam); }; CMyPanel MyPanel; // Essential: Delegate chart events to your panel void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { MyPanel.OnEvent(id, lparam, dparam, sparam); } ``` -------------------------------- ### MQL5 Input Control Example Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/README.md Illustrates how to use input controls for user data entry in MQL5 panels. This snippet covers creating an input field and retrieving its value. ```MQL5 // Example for CEdit control (input) // ... (edit control creation and value retrieval code) ... ``` -------------------------------- ### MQL5 Lot Size Control Creation Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/examples/production-examples.md Creates and configures the input control for setting the lot size. It defines minimum and maximum allowed values, and sets the initial value. ```C++ //+------------------------------------------------------------------+ //| Create lot size control | //+------------------------------------------------------------------+ bool CTradingControlsDialog::CreateLotSizeControl() { int x1 = INDENT_LEFT; int y1 = INDENT_TOP + 85; // After status and symbol int x2 = x1 + 120; int y2 = y1 + EDIT_HEIGHT; if(!m_lot_size.Create(m_chart_id, m_name + "LotSize", m_subwin, x1, y1, x2, y2)) return false; m_lot_size.MinValue(0.01); m_lot_size.MaxValue(100.0); m_lot_size.Value(m_current_lot_size); return Add(m_lot_size); } ``` -------------------------------- ### MQL5 Factory Pattern Example Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/api/class-hierarchy.md Shows the Factory pattern for creating different types of UI controls (Button, Edit, Panel) through a static factory method. ```mql5 class CControlFactory { public: static CButton* CreateButton(const string type); static CEdit* CreateEdit(const string type); static CPanel* CreatePanel(const string type); }; ``` -------------------------------- ### CRect Basic Rectangle Operations Example (MQL5) Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/auxiliary/CRect.md Demonstrates the basic usage of the `CRect` class, including setting bounds, printing properties, testing point containment, moving, and shifting the rectangle. ```mql5 #include void ExampleBasicRectangle() { CRect rect; // Set initial bounds rect.SetBound(10, 20, 110, 80); Print("Rectangle created:"); Print(" Left: ", rect.Left, ", Top: ", rect.Top); Print(" Right: ", rect.Right, ", Bottom: ", rect.Bottom); Print(" Width: ", rect.Width(), ", Height: ", rect.Height()); Print(" Format: ", rect.Format()); // Test point containment bool contains_point1 = rect.Contains(50, 50); // Should be true bool contains_point2 = rect.Contains(150, 50); // Should be false Print("Point (50,50) is inside: ", contains_point1); Print("Point (150,50) is inside: ", contains_point2); // Move rectangle to new position rect.Move(100, 100); Print("After move to (100,100): ", rect.Format()); // Shift rectangle by offset rect.Shift(20, -10); Print("After shift by (20,-10): ", rect.Format()); } ``` -------------------------------- ### MQL5 EA Lifecycle Management Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/README.md Provides an example of managing the complete Expert Advisor (EA) lifecycle within an MQL5 panel. This covers initialization, trading logic, and deinitialization. ```MQL5 // Example for EA lifecycle management // ... (OnInit, OnTick, OnDeinit functions and related logic) ... ``` -------------------------------- ### MQL5 List View Control Example Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/README.md Shows how to implement a CListView control for displaying and selecting data in MQL5 applications. This is useful for presenting lists of items or trade history. ```MQL5 // Example for CListView control // ... (list view creation, data population, and selection handling code) ... ``` -------------------------------- ### Format Position Information Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/examples/production-examples.md Formats the details of a specific open position into a human-readable string. It extracts the symbol, type (BUY/SELL), volume, and profit/loss, then combines them into a standardized output string. ```MQL5 string CTradingControlsDialog::FormatPositionInfo(int position_index) { string symbol = PositionGetString(POSITION_SYMBOL); ENUM_POSITION_TYPE type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE); double volume = PositionGetDouble(POSITION_VOLUME); double profit = PositionGetDouble(POSITION_PROFIT); string type_str = (type == POSITION_TYPE_BUY) ? "BUY" : "SELL"; return StringFormat("%s %s %.2f P/L:%.2f", symbol, type_str, volume, profit); } ``` -------------------------------- ### Create a Basic Trading Panel in MQL5 Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/alternatives/EasyAndFastGUI.md This example demonstrates the creation of a simple trading panel using EasyAndFastGUI. It includes creating a main window, input fields for lot size, buy/sell buttons, and a status bar. Event handling for button clicks is also shown. This code requires the EasyAndFastGUI library to be included. ```mql5 #include class CProgram : public CWndCreate { private: CWindow m_window; CButton m_buy_button; CButton m_sell_button; CTextEdit m_lot_size; CStatusBar m_status_bar; public: bool CreateGUI(void); virtual void OnEvent(const int id, const long &lparam, const double &dparam, const string &sparam); }; bool CProgram::CreateGUI(void) { // Create main window if(!CreateWindow(m_window, "Trading Panel", 1, 1, 300, 200, true, true)) return false; // Create lot size input if(!CreateTextEdit(m_lot_size, "Lot size:", m_window, 0, false, 10, 30, 100, 80, 10, 2, 0.01, 2, 1.0)) return false; // Create buy button if(!CreateButton(m_buy_button, "BUY", m_window, 0, 10, 60, 80)) return false; // Create sell button if(!CreateButton(m_sell_button, "SELL", m_window, 0, 120, 60, 80)) return false; // Create status bar string status_items[] = {"Ready", "Connected"}; int item_widths[] = {0, 100}; if(!CreateStatusBar(m_status_bar, m_window, 1, 2, 18, status_items, item_widths)) return false; // Complete GUI creation CWndEvents::CompletedGUI(); return true; } void CProgram::OnEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { // Handle buy button click if(id == CHARTEVENT_CUSTOM + ON_CLICK_BUTTON) { if(lparam == m_buy_button.Id()) { double lots = m_lot_size.GetValue(); // Execute buy order Print("Buy order: ", lots, " lots"); } else if(lparam == m_sell_button.Id()) { double lots = m_lot_size.GetValue(); // Execute sell order Print("Sell order: ", lots, " lots"); } } } // Expert Advisor Integration CProgram program; int OnInit() { return program.CreateGUI() ? INIT_SUCCEEDED : INIT_FAILED; } void OnDeinit(const int reason) { program.OnDeinitEvent(reason); } void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam) { program.ChartEvent(id, lparam, dparam, sparam); } ``` -------------------------------- ### Alternative GUI Frameworks Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/README.md Information on alternative GUI frameworks, specifically EasyAndFastGUI, and a comparison with standard MQL5 controls. ```APIDOC ## Alternative GUI Frameworks This section discusses alternative GUI frameworks and provides comparisons. ### EasyAndFastGUI vs Standard Controls - **Description**: A comparison table highlighting the differences between the standard MQL5 Controls Library and the EasyAndFastGUI framework. - **Key Differences**: Rendering, number of controls, theming capabilities, performance, and learning curve. ### EasyAndFastGUI Complete Guide - **Description**: A detailed guide to the EasyAndFastGUI framework, a modern canvas-based GUI solution with advanced controls and theming. - **Endpoint**: `./docs/alternatives/EasyAndFastGUI.md` ### Framework Comparison Guide - **Description**: A comprehensive guide to help developers choose between different GUI frameworks based on their project needs. - **Endpoint**: `./docs/alternatives/framework-comparison.md` ``` -------------------------------- ### MQL5 Symbol Selector Control Creation Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/examples/production-examples.md Initializes the symbol selection control. This control allows users to choose the trading symbol. The provided snippet only shows the start of the creation function. ```C++ //+------------------------------------------------------------------+ //| Create symbol selector | //+------------------------------------------------------------------+ bool CTradingControlsDialog::CreateSymbolSelector() { int x1 = INDENT_LEFT; ``` -------------------------------- ### MQL5 Button Creation: Standard Controls vs. EasyAndFastGUI Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/alternatives/framework-comparison.md Compares the code patterns for creating a button in MQL5 using both the standard controls library and the EasyAndFastGUI framework. The standard controls use a Create method with specific parameters, while EasyAndFastGUI employs a helper function for initialization, offering a potentially more streamlined approach. ```mql5 // Standard Controls CButton button; button.Create(chart_id, "btn", 0, 10, 10, 100, 40); // EasyAndFastGUI CButton button; CreateButton(button, "Text", window, 0, 10, 10, 90); ``` -------------------------------- ### Button Creation: Standard vs EasyAndFastGUI Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/alternatives/EasyAndFastGUI.md Demonstrates the difference in creating a button using MQL5's Standard Controls and the EasyAndFastGUI library. EasyAndFastGUI offers a more streamlined function call for button creation. ```mql5 // Standard Controls CButton button; button.Create(chart_id, "button", subwin, x1, y1, x2, y2); button.Text("Click Me"); // EasyAndFastGUI CButton button; CreateButton(button, "Click Me", window, 0, x, y, width); ``` -------------------------------- ### MQL5 Theme Manager Class Definition and Functionality Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/tutorials/customization.md Defines the CThemeManager class in MQL5, responsible for managing UI themes. It includes an enum for theme types, static methods to set and get the current theme, and functions to retrieve theme-specific colors and font properties. The class also has protected methods for applying different theme types. ```mql5 class CThemeManager { private: static ENUM_THEME_TYPE s_current_theme; public: enum ENUM_THEME_TYPE { THEME_LIGHT, THEME_DARK, THEME_BLUE, THEME_CUSTOM }; static void SetTheme(const ENUM_THEME_TYPE theme); static ENUM_THEME_TYPE GetCurrentTheme() { return s_current_theme; } static color GetDialogBackground(); static color GetClientBackground(); static color GetCaptionBackground(); static color GetButtonBackground(); static color GetButtonPressed(); static color GetEditBackground(); static color GetTextColor(); static string GetFontName(); static int GetFontSize(); protected: static void ApplyLightTheme(); static void ApplyDarkTheme(); static void ApplyBlueTheme(); }; ENUM_THEME_TYPE CThemeManager::s_current_theme = THEME_LIGHT; void CThemeManager::SetTheme(const ENUM_THEME_TYPE theme) { s_current_theme = theme; switch(theme) { case THEME_LIGHT: ApplyLightTheme(); break; case THEME_DARK: ApplyDarkTheme(); break; case THEME_BLUE: ApplyBlueTheme(); break; } } color CThemeManager::GetDialogBackground() { switch(s_current_theme) { case THEME_LIGHT: return 0xF0F0F0; case THEME_DARK: return 0x2D2D30; case THEME_BLUE: return 0xE6F3FF; default: return 0xF0F0F0; } } color CThemeManager::GetTextColor() { switch(s_current_theme) { case THEME_LIGHT: return clrBlack; case THEME_DARK: return clrWhite; case THEME_BLUE: return 0x003366; default: return clrBlack; } } ``` -------------------------------- ### MQL5: Handle User Events for Trading Panel Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/tutorials/getting-started.md This MQL5 code defines the event handling logic for the trading panel. The `OnEvent` method intercepts chart events, specifically object clicks, to identify which button was pressed (Buy or Sell). It then calls corresponding handler functions (`OnButtonBuy`, `OnButtonSell`) which contain placeholder logic for trading operations and basic input validation. ```mql5 //+------------------------------------------------------------------+ //| Event handler | //+------------------------------------------------------------------+ bool CMyFirstPanel::OnEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { // Handle button clicks if(id == CHARTEVENT_OBJECT_CLICK) { if(sparam == m_button_buy.Name()) { OnButtonBuy(); return true; } if(sparam == m_button_sell.Name()) { OnButtonSell(); return true; } } // Call parent event handler return CAppDialog::OnEvent(id, lparam, dparam, sparam); } //+------------------------------------------------------------------+ //| Buy button click handler | //+------------------------------------------------------------------+ void CMyFirstPanel::OnButtonBuy(void) { string symbol = m_edit_symbol.Text(); Print("Buy button clicked for symbol: ", symbol); // Here you would implement actual trading logic // For this example, we'll just show an alert Alert("Buy order would be placed for " + symbol); // Example of basic validation if(StringLen(symbol) == 0) { Alert("Please enter a symbol"); return; } // Visual feedback m_button_buy.ColorBackground(clrDarkGreen); Sleep(100); // Brief visual feedback m_button_buy.ColorBackground(clrGreen); } //+------------------------------------------------------------------+ //| Sell button click handler | //+------------------------------------------------------------------+ void CMyFirstPanel::OnButtonSell(void) { string symbol = m_edit_symbol.Text(); Print("Sell button clicked for symbol: ", symbol); // Here you would implement actual trading logic Alert("Sell order would be placed for " + symbol); if(StringLen(symbol) == 0) { Alert("Please enter a symbol"); return; } // Visual feedback m_button_sell.ColorBackground(clrDarkRed); Sleep(100); m_button_sell.ColorBackground(clrRed); } ``` -------------------------------- ### MQL5 Complete Controls Demo Panel Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/examples/production-examples.md Implements a comprehensive trading panel using the MQL5 Controls Library. It demonstrates major control types and event handling for a functional user interface. Requires the TradingControlsDialog.mqh header file. ```mql5 //+------------------------------------------------------------------+ //| TradingControlsDemo.mq5| //| Production Trading Panel Demo | //+------------------------------------------------------------------+ #property copyright "Trading Panel Demo" #property version "1.00" #include "TradingControlsDialog.mqh" //--- Global panel instance CTradingControlsDialog ExtDialog; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { // Create application dialog if(!ExtDialog.Create(0, "TradingControls", 0, 20, 20, 400, 450)) { Print("Failed to create trading controls dialog"); return INIT_FAILED; } // Run application ExtDialog.Run(); return INIT_SUCCEEDED; } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { // Destroy dialog with proper cleanup ExtDialog.Destroy(reason); } //+------------------------------------------------------------------+ //| Chart event function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam) { // Route all events to the dialog ExtDialog.ChartEvent(id, lparam, dparam, sparam); } ``` -------------------------------- ### Display Data in a Table in MQL5 using EasyAndFastGUI Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/alternatives/EasyAndFastGUI.md This MQL5 example illustrates how to create and populate a data table using EasyAndFastGUI's CTable class. It shows how to initialize a table within a window, set the number of rows and columns, define header texts, adjust column widths, and add various data types including strings, doubles, and times to the table cells. ```mql5 CTable table; if(CreateTable(table, m_window, 10, 100)) { // Configure table table.TableSize(3, 10); // 3 columns, 10 rows table.HeadersText(headers); table.ColumnWidth(0, 80); table.ColumnWidth(1, 100); table.ColumnWidth(2, 120); // Add data for(int row = 0; row < 10; row++) { table.TextByRowCol(row, 0, "Item " + IntegerToString(row)); table.TextByRowCol(row, 1, DoubleToString(row * 10.5, 2)); table.TextByRowCol(row, 2, TimeToString(TimeCurrent() + row * 3600)); } } ``` -------------------------------- ### MQL5 CWndObj - Custom Label Creation Example Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/foundation/CWndObj.md Provides a practical example of creating a custom label control by inheriting from CWndObj. It demonstrates overriding creation and event handling methods. ```mql5 #include class CMyLabel : public CWndObj { public: virtual bool Create(const long chart_id, const string name, const int subwin, const int x1, const int y1, const int x2, const int y2); virtual bool OnSetText(void); virtual bool OnObjectClick(void); }; bool CMyLabel::Create(const long chart_id, const string name, const int subwin, const int x1, const int y1, const int x2, const int y2) { // Call parent creation if(!CWndObj::Create(chart_id, name, subwin, x1, y1, x2, y2)) return false; // Set initial properties Text("My Label"); Color(clrBlue); ColorBackground(clrLightGray); Font("Arial"); FontSize(12); return true; } bool CMyLabel::OnSetText(void) { // Custom behavior when text changes Print("Label text changed to: ", Text()); return CWndObj::OnSetText(); } bool CMyLabel::OnObjectClick(void) { // Handle click events Color(Color() == clrBlue ? clrRed : clrBlue); return true; } ``` -------------------------------- ### MQL5 Dynamic Resizing Example Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/tutorials/layout-management.md Shows an example of handling dynamic resizing in MQL5 by overriding the OnResize virtual function. This function is called when the dialog is resized, and it ensures that the layout is updated accordingly by calling an UpdateLayout function. ```mql5 virtual bool OnResize(void) { // Recalculate layout when dialog is resized UpdateLayout(); return CAppDialog::OnResize(); } ``` -------------------------------- ### CPanel Appearance: Text and Alignment Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/simple-controls/CPanel.md Controls the text displayed on the panel and its alignment. The Text() method gets or sets the panel's text, while Alignment() gets or sets the text alignment using uint values. ```mql5 string Text() const; virtual bool Text(const string text); uint Alignment() const; virtual bool Alignment(const uint alignment); ``` -------------------------------- ### Simple MQL5 Trading Panel Implementation (Standard Controls) Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/alternatives/framework-comparison.md Demonstrates a basic MQL5 trading panel using the standard controls library. This is suitable for quick prototyping and simple trading interfaces where familiar MetaTrader UI conventions are preferred. It utilizes the CAppDialog base class and standard control objects like CButton and CEdit. ```mql5 // Quick implementation with standard controls class CSimplePanel : public CAppDialog { CButton m_buy, m_sell; CEdit m_lots; }; ``` -------------------------------- ### Get or Set CComboBox Edit Text Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/complex-controls/CComboBox.md This method allows you to either get the current text displayed in the edit portion of the CComboBox or set a new text value. Setting text may trigger selection logic. ```mql5 string Text() const; virtual bool Text(const string text); ``` -------------------------------- ### Professional MQL5 Trading Terminal Implementation (EasyAndFastGUI) Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/alternatives/framework-comparison.md Illustrates the creation of an advanced trading terminal using the EasyAndFastGUI framework. This approach is recommended for complex data visualization, professional user interfaces, and when advanced controls like tables, graphs, and status bars are needed. It uses the CWndCreate base class and specialized EasyAndFastGUI controls. ```mql5 // Advanced interface with EasyAndFastGUI class CTradingTerminal : public CWndCreate { CTable m_positions; CGraph m_equity_chart; CStatusBar m_status; CMenuBar m_menu; }; ``` -------------------------------- ### MQL5 CCheckBox State and Value Management Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/api/function-reference.md Allows getting and setting the checked state (true/false) of a CCheckBox, as well as getting and setting an associated long value. This is useful for representing boolean options or linking checkboxes to data. ```mql5 bool Checked() const; // Get checked state virtual bool Checked(const bool flag); // Set checked state long Value() const; // Get associated value virtual bool Value(const long value); // Set associated value ``` -------------------------------- ### MQL5 CLabel Dynamic Updates and Event Handling Example Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/simple-controls/CLabel.md Illustrates dynamic updating of a CLabel's text and color based on status, overriding the OnSetText event to log changes and update timestamps. This example shows how to create a responsive status label. ```mql5 class CStatusLabel : public CLabel { private: datetime m_last_update; public: virtual bool OnSetText(void); void UpdateStatus(const string status); void UpdateTime(void); }; bool CStatusLabel::OnSetText(void) { // Log text changes Print("Status updated: ", Text()); m_last_update = TimeCurrent(); return CLabel::OnSetText(); } void CStatusLabel::UpdateStatus(const string status) { // Update with timestamp string full_text = status + " (" + TimeToString(TimeCurrent()) + ")"; Text(full_text); // Color based on status if(StringFind(status, "Error") >= 0) Color(clrRed); else if(StringFind(status, "Success") >= 0) Color(clrGreen); else Color(clrBlue); } void CStatusLabel::UpdateTime(void) { Text("Current Time: " + TimeToString(TimeCurrent())); } ``` -------------------------------- ### Implement File Navigation in MQL5 with EasyAndFastGUI Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/alternatives/EasyAndFastGUI.md This MQL5 code snippet demonstrates how to integrate a file navigator component into a trading panel using EasyAndFastGUI's CFileNavigator class. It shows how to create the navigator, set its mode to display all files, configure the content to include both MQL and common folders, and set an initial directory path. ```mql5 CFileNavigator navigator; if(CreateFileNavigator(navigator, m_window, 10, 150)) { navigator.NavigatorMode(FN_ALL); // Show all files navigator.NavigatorContent(FN_BOTH); // MQL and common folders navigator.CurrentFullPath("\Files\"); // Set initial path } ``` -------------------------------- ### MQL5 EVENT_MAP Macro System - Usage Examples Source: https://github.com/stephanecoder/mql5-panel-doc/blob/main/docs/api/constants.md Demonstrates practical usage of the EVENT_MAP macros for handling various event scenarios in MQL5 applications. Includes examples for basic control events, pointer-based events, named events, external events, and indexed events. ```mql5 // Basic event map EVENT_MAP_BEGIN(CMyPanel) ON_EVENT(ON_CLICK, m_button1, OnButton1Click) ON_EVENT(ON_CLICK, m_button2, OnButton2Click) ON_EVENT(ON_CHANGE, m_edit, OnEditChange) EVENT_MAP_END(CAppDialog) // Advanced event map with multiple event types EVENT_MAP_BEGIN(CAdvancedPanel) // Standard control events ON_EVENT(ON_CLICK, m_buy_button, OnBuyClick) ON_EVENT(ON_CHANGE, m_lot_size, OnLotSizeChange) // Pointer-based events (for dynamically created controls) ON_EVENT_PTR(ON_CLICK, m_dynamic_button, OnDynamicButtonClick) // Named events (string-based identification) ON_NAMED_EVENT(ON_CLICK, m_named_control, OnNamedControlClick) // External events (custom application events) ON_EXTERNAL_EVENT(1001, OnCustomEvent) // No-ID events (global events) ON_NO_ID_EVENT(ON_APP_CLOSE, OnApplicationClose) EVENT_MAP_END(CAppDialog) // Indexed event handling for control arrays EVENT_MAP_BEGIN(CButtonArrayPanel) ON_INDEXED_EVENT(ON_CLICK, m_button_array, OnButtonArrayClick) EVENT_MAP_END(CAppDialog) // Handler method signatures bool OnButtonArrayClick(int button_index) { Print("Button ", button_index, " clicked"); return true; } void OnCustomEvent(long lparam, double dparam, string sparam) { Print("Custom event received: ", lparam, ", ", dparam, ", ", sparam); } bool OnApplicationClose() { Print("Application closing"); return true; // Allow close } ```