Object Creation and Modification Functions
Info
The Object Creation and Modification Functions is a Library for MetaTrader 5 that the attached *. mqh file contains functions for creating objects and modifying object properties, aiding in rapid test code development that creates objects on charts and adjusts existing object properties.
Usage
This tool is typically used for enhancing chart analysis and decision making.
Platform
This Library works exclusively on MetaTrader 5 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL5/Libraries folder via File ? Open Data Folder in MetaTrader 5.
How to Install and Use Object Creation and Modification Functions
1. Storage: Place library files in the MQL/Libraries directory to ensure they are accessible to your projects.
2. Implementation: Include the library in your code using the #import directive, ensuring you match the exact function names and parameters.
3. Compilation: Ensure the library is present in the directory before you compile your main EA or script, as the compiler links them during this phase.
4. Management: Keep libraries organized in sub-folders if you manage many custom functions to maintain a clean project structure.
Frequently Asked Questions
Q: What is a library file used for? A: Libraries store reusable code modules, allowing you to centralize common logic used by multiple EAs or indicators.
Q: Is a library executable? A: No, libraries are non-executable files containing functions; they must be imported into an EA, indicator, or script to function.
Q: Can I update a library while the platform is running? A: You should compile your EA or script after updating a library to ensure the latest code changes are integrated.
What this tool does
The attached *.
Typical Use Case
This Library excels in automated trading and technical analysis on MetaTrader 5.
Compatible Platform & Setup
This Library works on MetaTrader 5. Place the file in the MQL5/Libraries folder and restart the terminal.
Description & Settings
Related: Extended Objects - another powerful library for MetaTrader 5 traders.
The attached *.mqh file contains functions for creating objects and modifying object properties, aiding in rapid test code development that creates objects on charts and adjusts existing object properties.Also recommended: Object Emulator for MetaTrader 4 and 5 - similar library with strong performance on MetaTrader 5.
The accompanying script demonstrates this by creating a text label, rotating it by 90 degrees, and altering its text and color during the rotation.
I. Functions for Creating Objects
These functions are based on standard functions outlined in the MetaTrader documentation, with the following key differences:
- Added lines for setting tooltips and managing object visibility across different timeframes.
- Removed lines for creating functions without setting coordinates, prices, or anchor points, except for vlinecreate(...) and eventcreate(...).
- Built on functions for setting/changing object properties, with additional conditions to ensure successful property updates.
List of functions for creating objects:
II. Functions for Setting Object Properties
Using ObjectSetText(), ObjectSetInteger(), and ObjectSetDouble() without specifying a modifier:
Using ObjectSetText(), ObjectSetInteger(), and ObjectSetDouble() with a specified modifier:
Additional functions:
III. Usage
You can either include the entire file or selectively copy specific functions into your source code. If opting for the latter, it's advisable to first include the entire file, implement the necessary function calls, and then remove the include directive (#include...). This way, the compiler will indicate which functions you need to retain in your source code.
To use as an include file:
Save the attached file, objectcreateandset.mqh, to the 'include' folder via the 'Navigator' window in MetaEditor. Right-click the 'include' folder and select 'Open Folder'.
To incorporate the library into your code, copy the #include... line from the file's beginning and paste it into your source code. The attached script exemplifies this inclusion.
Compiling your code will enable tooltips for included functions, displaying their full names and parameters as you type.
Updates:
2026.09.14: Enhanced the obdelete() function to output the object's name to the Experts tab in case of deletion errors, simplifying error identification.
You may also like: object list - excellent alternative for library users on MetaTrader 5.
Source Code
#property copyright "robotfx"
#property link "https://robotfx.org"
#property version "1.00"
#include <objectcreateandset.mqh>
void onstart()
{
string nameobj="testlabel";
string text[10]=
{
"a a","b b","c c","d d","e e",
.......
⚠ 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.