Examples: MQL4 Language for Newbies. Custom Indicators (Part 2)

 

New article MQL4 Language for Newbies. Custom Indicators (Part 2) has been published:

This is the fifth article from the series "MQL4 Languages for Newbies". Today we will learn to use graphical objects - a very powerful development tool that allows to widen substantially possibilities of using indicators. Besides, they can be used in scripts and Expert Advisors. We will learn to create objects, change their parameters, check errors. Of course, I cannot describe in details all objects - there are a lot of them. But you will get all necessary knowledge to be able to study them yourself. This article also contains a step-by-step guide-example of creating a complex signal indicator. At that, many parameters will be adjustable which will make it possible to change easily the appearance of the indicator.

About Graphical Objects

You often deal with them when working in MetaTrader 4 terminal. You can use graphical objects for various purposes. Traders place support and resistance levels, pivot points, Fibonacci levels etc. Let us view a simple example of using objects:

Four graphical objects are attached to this chart:

  • 2 horizontal lines
  • a text object
  • an object-symbol (an arrow)

Today we will learn to attach such objects using MQL4. Just imagine how many manual actions can be automated by using objects! For example, have you ever calculated pivot points, support and resistance levels and then drawn them manually? Well, there is not so much work, but if this process is automated in MQL4, the terminal will calculate and draw the corresponding levels itself. All you need is a double click on the script name, and everything will be done. Besides, using graphical objects one can write very useful signal indicators.

Author: Antoniuk Oleg

 
Thanks! Very useful tutorial, thanks a lot!
 
Hey.. the deinit function deletes all existing objects on the chart! So the code should be revised to enumerate and erase specifically the indicator's objects
 
amg:
Hey.. the deinit function deletes all existing objects on the chart! So the code
should be revised to enumerate and erase specifically the indicator's objects
Try this version of deinit():
int deinit()
{
   // deleting table of signals
   for(int x=0;x<9;x++)
      for(int y=0;y<3;y++)
         ObjectDelete("signal"+x+y);
  
  // deleting names of timeframes    
  for(x=0;x<9;x++)
      ObjectDelete("textPeriod"+x);   
  
  // deleting names of indicators 
  for(y=0;y<3;y++)
      ObjectDelete("textSignal"+y);   
 
   return(0);
}
 
please is there any way this lesson can be simplify, so i can understand it very well. Thank you


 

Antonuk,

What a great series you have created.  For the first time, I am beginning to comprehend the MQL4 language.  Your descriptions and layouts are very easy to understand.  I just want you to know how much I appreciate your articles.  I am hoping that you are planning to continue the series to include the development of EA's.  I hope it will be soon!  I offer my encouragement and appreciation for a job well done.

 

Mike Johnson, USA

mjohnson155@woh.rr.com

 

have you test in real account ?

what is the result ? profit ?

 
Brilliant tutorial. I actually enjoyed coding mql4 for once. Very easy to follow and makes mql4 easier to understand.
 
I'm having some trouble understanding the use of text vs. label objects in my EA. What's the difference between them? I can put labels in corners, but have trouble putting words on the chart at a time and amount. Why would you use one or the other? How can in insure that they appear when I hit the "Open chart" button after optimization? Are there amy differences between their use in EAs and their use in indicators?
 
  • window – the window number, in which the object should be drawn. If you need to draw an object on a chart, i.e. in the main window, use 0 as the window number.

how to use current window ? a indicator maybe in amin window or subwindow, I need to use the window the indicatoe inside.

 

you explain is very clear !
Thank you !

Reason: