Alert and Comment for External Indicators
Introduction
Practice shows that developers of indicators not always include the possibility of displaying alerts or comments in an indicator code which results in requests to add the possibility of showing signals in an indicator.
MQL4 Possibilities for Showing Information of Indicators
Possibilities of the MQL4 programming language do not include the extended usage of indicator buffers, for example extending them by adding comment or alert showing, which could be an advantage simplifying the creation of a program code. On the other hand, MQL4 allows reading the location of any objects and getting their full characteristics.
In this article I would like to show the method of getting data on a signal of an indicator attached to a chart and show its comment, alert or creating a global variable for further use for informational purposes, for example for passing it to an Expert Advisor.
All marks drawn on a chart use Wingdings and arrow codes. That is why it is not difficult to get information about a mark drawn on a chart. By the way, if an indicator author includes quite an informative description of the OBJ_ARROW object, a user can easily identify a signal. An example is the description of marks given by creators of classic Japanese candlesticks. In the standard performance of his indicator a user needs only to put the mouse cursor over the mark for getting a pop-up help with a corresponding text.
Standard showing of a signal
In MQL4 you can use some built-in options for more informative way of data presentation.
Among language commands the function
double ObjectGet (string name, int prop_id)
returns the value of a specified object property. To get an error data call the GetLastError() function.
See also ObjectSet().
Parameters:
name - object name.
prop_id - Identifier of object properties. Can be any value from the list of object properties.
Identifiers of object properties are used in functions ObjectGet() and ObjectSet(). Can be any of below values:
Constant | Value | Type | Description |
---|---|---|---|
OBJPROP_TIME1 | 0 | datetime | Receives/sets the first coordinate of time |
OBJPROP_PRICE1 | 1 | double | Receives/sets the first coordinate of price |
OBJPROP_TIME2 | 2 | datetime | Receives/sets the second coordinate of time |
OBJPROP_PRICE2 | 3 | double | Receives/sets the second coordinate of price |
OBJPROP_TIME3 | 4 | datetime | Receives/sets the third coordinate of time |
OBJPROP_PRICE3 | 5 | double | Receives/sets the third coordinate of price |
OBJPROP_COLOR | 6 | color | Receives/sets the color of an object |
OBJPROP_STYLE | 7 | int | Receives/sets the line style of an object |
OBJPROP_WIDTH | 8 | int | Receives/sets the line width of an object |
OBJPROP_BACK | 9 | bool | Receives/sets the background representation flag of an object |
OBJPROP_RAY | 10 | bool | Receives/sets the flag of ray properties for objects of OBJ_TREND type and the like |
OBJPROP_ELLIPSE | 11 | bool | Receives/sets the flag of displaying the full ellipse for OBJ_FIBOARC |
OBJPROP_SCALE | 12 | double | Receives/sets the value of an object scale |
OBJPROP_ANGLE | 13 | double | Receives/sets the angle value in degrees for OBJ_TRENDBYANGLE |
OBJPROP_ARROWCODE | 14 | int | Receives/sets the arrow code of OBJ_ARROW. Can be one of wingdings symbols or one of predefined arrow codes |
OBJPROP_TIMEFRAMES | 15 | int | Receives/sets object representation on various periods. Can be one of or combination of several object visibility constants |
OBJPROP_DEVIATION | 16 | double | Receives/sets deviation value for OBJ_STDDEVCHANNEL |
OBJPROP_FONTSIZE | 100 | int | Receives/sets font size for OBJ_TEXT and OBJ_LABEL |
OBJPROP_CORNER | 101 | int | Receives/sets number of binding angle for OBJ_LABEL. Gets values 0-3 |
OBJPROP_XDISTANCE | 102 | int | Receives/sets distance of X coordinate in pixels relative to the binding angle for OBJ_LABEL |
OBJPROP_YDISTANCE | 103 | int | Receives/sets distance of Y coordinate in pixels relative to the binding angle for OBJ_LABEL |
OBJPROP_FIBOLEVELS | 200 | int | Receives/sets number of levels of the Fibonacci object. Can be from 1 to 32 |
OBJPROP_LEVELCOLOR | 201 | color | Receives/sets line color of the object level |
OBJPROP_LEVELSTYLE | 202 | int | Receives/sets line style of the object level |
OBJPROP_LEVELWIDTH | 203 | int | Receives/sets the line width of the object level |
OBJPROP_FIRSTLEVEL+n | 210+n | int | Receives/sets objet level number, where n is index of installed/received level. Can be from 0 to 31 |
That is why let's use parameter OBJPROP_ARROWCODE in order to find a necessary object and we will receive the list of all objects. After that let's select necessary objects in the array and show the information on them in the required form.
Then let's create a code for receiving information about names of candlesticks for indicator “japan”. We get the following code:
int obj_total=ObjectsTotal(); // Define the total number of objects on a chart for(int i=0;i<obj_total;i++) // Loop of going through all objects with the purpose of finding necessary ones { if (ObjectGet(ObjectName(i),OBJPROP_ARROWCODE) // reading the code
First we should define how we will deal with Wingdings and correspondingly set up parameters in the program code. In this example we will handle the part of Wingdings table that starts with 100.
if (ObjectGet(ObjectName(i),OBJPROP_ARROWCODE)>100&& ObjectGet(ObjectName(i),OBJPROP_TIME1)>Time[ExtBars])
The ExtBars variable is used for defining the number of last bars for finding object drawn on a chart.
Now we will show Alerts and (or) Comments.
if (ExtAlert==true){ Alert(Symbol(),Period()," ", TimeYear(ObjectGet(ObjectName(i),OBJPROP_TIME1)),".", TimeDay(ObjectGet(ObjectName(i),OBJPROP_TIME1)),".", TimeMonth(ObjectGet(ObjectName(i),OBJPROP_TIME1)),"; ", TimeHour(ObjectGet(ObjectName(i),OBJPROP_TIME1)),":", TimeMinute(ObjectGet(ObjectName(i),OBJPROP_TIME1))," ", ObjectName(i));} if (ExtComment==true){ Comment("\n","\n","\n", Symbol(),Period()," ", TimeYear(ObjectGet(ObjectName(i),OBJPROP_TIME1)),".", TimeDay(ObjectGet(ObjectName(i),OBJPROP_TIME1)),".", TimeMonth(ObjectGet(ObjectName(i),OBJPROP_TIME1)),"; ", TimeHour(ObjectGet(ObjectName(i),OBJPROP_TIME1)),":", TimeMinute(ObjectGet(ObjectName(i),OBJPROP_TIME1))," ", ObjectName(i));}
In the comment line
("\n","\n","\n",
is used for showing information onto the third line of a display.
If necessary, you can include sending the information to global variables for using them in an Expert Advisor. Thus eliminating the breach of copyright of indicator authors we get the possibility to use information on alerts for our own purposes and do not have to ask authors to modify their codes.
Using the described approach we get the following result:
Operating result of the indicator showing external information
In the analogous way the code works with the indicator ExCandles2. This is the second indicator published in MQL4 base; it was tried together with the published code.
Conclusion
Here is the source code of the indicator for displaying information about appearing signals of indicators:
//+------------------------------------------------------------------+ //| AlertSignal.mq4 | //| Copyright © 2009, WWW.FIBOOK.RU | //| http://fibook.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009, FIBOOK.RU" #property link "http://fibook.ru" #property indicator_chart_window extern int ExtBars=10; // Number of last bars for calculation extern int ExtArrow=100; // Code number in the "wingdings" table for the count start extern bool ExtAlert=true; // Switch of Alerts displaying extern bool ExtComment=true; // Switch of Comments displaying //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { if (per == Time[0]) return; // Correct once per a period per = Time[0]; int cod=0; //---- int obj_total=ObjectsTotal(); for(int i=0;i<obj_total;i++) { if (ObjectGet(ObjectName(i),OBJPROP_ARROWCODE)>ExtArrow&& ObjectGet(ObjectName(i),OBJPROP_TIME1)>Time[ExtBars]) { if (ExtAlert==true){ Alert(Symbol(),Period()," ", TimeYear(ObjectGet(ObjectName(i),OBJPROP_TIME1)),".", TimeDay(ObjectGet(ObjectName(i),OBJPROP_TIME1)),".", TimeMonth(ObjectGet(ObjectName(i),OBJPROP_TIME1)),"; ", TimeHour(ObjectGet(ObjectName(i),OBJPROP_TIME1)),":", TimeMinute(ObjectGet(ObjectName(i),OBJPROP_TIME1))," ", ObjectName(i));} if (ExtComment==true){ Comment("\n","\n","\n", Symbol(),Period()," ", TimeYear(ObjectGet(ObjectName(i),OBJPROP_TIME1)),".", TimeDay(ObjectGet(ObjectName(i),OBJPROP_TIME1)),".", TimeMonth(ObjectGet(ObjectName(i),OBJPROP_TIME1)),"; ", TimeHour(ObjectGet(ObjectName(i),OBJPROP_TIME1)),":", TimeMinute(ObjectGet(ObjectName(i),OBJPROP_TIME1))," ", ObjectName(i));} } } //---- return(0); } //+------------------------------------------------------------------+
Translated from Russian by MetaQuotes Ltd.
Original article: https://www.mql5.com/ru/articles/1568
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Thank you for your excellent article on Alert and Comment for External Indicators.
I have made use of this code many times and with great reliability until recently.
I found that the code i was using did not use graphical objects for the arrow signals on charts, but instead used the DRAW ARROW command as part of a line index style attached to a buffer.
The arrow on my charts does not appear in the list of objects so i am at a loss as to how to make use of your alert code.
is there a way around this problem.
Apologies in advance if i have not explained myself clearly, I am not a coder but have managed to fumble through on other peoples knowledge so far.
Many thanks
Ginogee