Join our fan page
- Views:
- 12464
- Rating:
- Published:
- 2015.07.31 11:34
- Updated:
- 2016.11.22 07:32
-
Need a robot or indicator based on this code? Order it on Freelance Go to Freelance
The attached *.mqh file contains functions for creating objects and changing object properties. It is particularly useful for me when I need to quickly write some test code which creates objects on a chart and/or changes the properties of existing objects.
The other file is a script with a usage example (creates a text label, gradually rotates it by 90 degrees changing the text and its color along the way).
I. Functions for creating objects:
The functions are based on standard functions described in MQL5 Reference. Major differences from the corresponding standard functions:
- added lines for setting tooltips and setting the visibility of objects on different timeframes;
- removed lines for creating functions without setting coordinates, prices, anchor points (except for VLineCreate(...) and EventCreate(...));
- based on functions for setting (changing) object properties implemented in this library, additional conditions have been added to check the success of setting the properties.
List of functions for creating objects:
Name |
Brief description |
Object type |
---|---|---|
VLineCreate |
Create a vertical line |
|
HLineCreate |
Create a horizontal line |
|
TrendCreate |
Creates a trend line by given coordinates |
|
ArrowedLineCreate |
Create an arrowed line by given coordinates |
|
ChannelCreate |
Create an equidistant channel by given coordinates |
|
RectangleCreate |
Create a rectangle by given coordinates |
|
TriangleCreate |
Create a triangle by given coordinates |
|
EllipseCreate |
Create an ellipse by given coordinates |
|
ArrowCreate |
Create OBJ_ARROW |
OBJ_ARROW |
TextCreate | Create a Text object |
OBJ_TEXT |
LabelCreate |
Create a text label |
|
ButtonCreate |
Create a button |
|
BitmapCreate |
Create a bitmap in the chart window |
|
BitmapLabelCreate |
Create a Bitmap Label object |
|
EditCreate |
Create an Edit object |
|
EventCreate |
Create an Event object on the chart |
|
RectLabelCreate |
Create a rectangle label |
II. Functions for setting object properties:
Using ObjectSetDouble(...), ObjectSetInteger(...) and ObjectSetString(...) without specifying a modifier:
Using ObjectSetDouble(...), ObjectSetInteger(...) and ObjectSetString(...) with specifying a modifier:
Name |
Enumeration | Property | Brief description | Property type | |
---|---|---|---|---|---|
1. | ObSetDoubleMod | ENUM_OBJECT_PROPERTY_DOUBLE | OBJPROP_PRICE | Price coordinate - double, modifier=anchor point number | double |
OBJPROP_LEVELVALUE | Level value - double, modifier=level number |
double | |||
2. |
ObSetIntegerLevelColorMod | ENUM_OBJECT_PROPERTY_INTEGER | OBJPROP_LEVELCOLOR | Level line color - color, modifier=level number |
color |
3. |
ObSetIntegerLevelStyleMod |
ENUM_OBJECT_PROPERTY_INTEGER | OBJPROP_LEVELSTYLE |
Level line style ENUM_LINE_STYLE, modifier=level number |
ENUM_LINE_STYLE |
4. |
ObSetIntegerLevelWidthMod |
ENUM_OBJECT_PROPERTY_INTEGER | OBJPROP_LEVELWIDTH |
Level line width - int, modifier=level number |
int |
5. | ObSetIntegerTimeMod | ENUM_OBJECT_PROPERTY_INTEGER | OBJPROP_TIME |
Time coordinate - datetime, modifier=anchor point number |
datetime |
6. | ObSetStringMod | ENUM_OBJECT_PROPERTY_STRING | OBJPROP_LEVELTEXT | Level description - string, modifier=level number | string |
OBJPROP_BMPFILE |
BMP file name for the Bitmap Level object - string. See also Resources in the Reference. Modifier: 0-ON state, 1-OFF state | string |
Additional functions:
bool ObDelete (long chart_ID,string name) |
Delete a single object with specified name |
III. Usage:
You can use it as an include file or you can just copy certain functions from it to your source code.
If you choose the second way, I think it's better to first use it as an include file. Once you implement all necessary function calls you can remove the include directive (#include...).
Then, the compiler will point out which functions you need to copy from the include file.
Use as an include file:
- Save the attached file ObjectCreateAndSet.mqh to "Include" folder. To do so, you can use the Navigator window in MetaEditor. In the Navigator window, right-click the "Include" folder and choose "Open Folder".
- To use the library in your code, copy the #include... line from the beginning of the file and paste it to your source code:
#include <ObjectCreateAndSet.mqh>
The attached script provides an example of including the library. - After that, compile your code. It will allow to see the tooltips for included functions when you start entering their names:
Fig.1. Full name of a function in a tooltip after entering its first few letters
Fig.2. Parameters of a function in a tooltip
By the way, you can you use the functions list button on the MetaEditor toolbar to quickly view the list of functions used in the current file:
Fig.3. Button for showing the list of functions used in a file
When you press the button, a drop-down list appears. To go to a particular function, click its name in the list.
Fig.4. Pressing the button opens the list of functions in a file (useful to quickly move to a certain function)
Updates:
- 2015.09.14: In the ObDelete() function, added output of object's name to the Experts tab if there is an error when deleting the object. It facilitates finding errors in the code.
Translated from Russian by MetaQuotes Ltd.
Original code: https://www.mql5.com/ru/code/13374

The ColorLinearRegSlope_V2 indicator with the timeframe selection option available in the input parameters.

The ColorLeManTrend indicator with the timeframe selection option available in the input parameters.

The ColorMomentum_AMA indicator with the timeframe selection option available in the input parameters.

The ColorMaRsi-Trigger indicator with the timeframe selection option available in the input parameters.