Earn up to
for inviting friends
to get StartUp Bonus
from InstaForex
No investments required!
from InstaForex
on every deposit
Reply to thread
Results 1 to 1 of 1

Thread: MQL4 programming language lessons up to professionalism, Part 4

  1. #1 You can automatically minimize the read posts in your account in the 'Forum Settings'
    Will work for pips
    I am:
    Somia2020 is on a distinguished road Somia2020's Avatar
    Join Date
    Oct 2020
    Accumulated bonus
    68 USD (What is this?)
    Thanked 242 Times in 51 Posts
    Subsribed 0

    Post MQL4 programming language lessons up to professionalism, Part 4

    Name: 1.png Views: 16 Size: 147.7 KB

    We will now talk about the actual steps for creating an indicator and then actually running it on the chart.

    By doing so, you will have put your man on the first steps of becoming a programmer, God willing.

    Necessary steps for making a real pointer:

    1- Clarify the idea and purpose of this new indicator:

    The idea of ​​the indicator is to draw two vertical lines for each candle.
    The first red line represents the candle's length in pips, meaning the difference between the high and low for each candle.

    The second line in green represents the candle body's length and points, meaning the difference between the close and the open.

    This indicator's objective is to know the increase in the lengths and bodies of the candles on the chart.

    2- Our indicator will be drawn on a separate window because it is practically impossible to draw it on the same chart due to the difference in the proportions between the index values ​​and the price values.

    3- This indicator does not currently have any external characteristics.

    4- The colors and the way to show the lines were selected on the separate window.

    5- Text of reserved rights.
    6- The text of the link to a website or email.

    7- The name of the indicator.

    With the previous steps, we have identified all the necessary information to start programming this new indicator.

    Now let us start with the straightforward steps for writing your indicator script:

    1- Run the MetaTrader trading program.

    2- Press F4 or click the yellow icon in the top center of the trading platform.

    3- Meta Editor will appear. Press Ctrl + N to create a new program.

    4- A window will appear in which we specify the type of program we want to create, which is an indicator, so we choose Custom Indicator. Then we press the Next button.

    5- Another window will appear in which we will type the name of the indicator Candle Length in the Name field.

    6- We also write the copyright information in the Author field.

    7- We write the website name or email in the Link field.

    8- The name is necessary to be written. The reserved rights and the link are optional, but the work should be professional that we write them.

    9- We press the Next button to show another new window.

    10- What matters to us about it is to choose that the new indicator will appear in a separate window, so we put a check mark on the option Indicator in a separate window.

    11- We press Finish, and then the indicator window will appear with a bit of code, and we have to complete it with the idea we want our cursor to do.

    The initial explanation of the code that appeared to us:

    - Anything that appears in silver is commented that are not implemented, but rather help us coordinate the code and add an explanation within the script itself.

    The first two lines we see in blue are the two orders in which we put the copyright text and the link text, and they are as follows:

    PHP Code:

    #property copyright "Copyright  ####"
    #property link "email"
    After that comes another essential line through which we specify that the cursor will appear in a separate window. It is as follows:

    PHP Code:

    #property indicator_separate_window
    We can easily change this property by replacing the last line with the following line:

    PHP Code:

    #property indicator_chart_window
    After that, we find the following code (after deleting comments from it):

    PHP Code:

    #property copyright "Copyright  ####"
    #property link      "email"
    #property indicator_chart_window
    int init()
    int deinit()
    int start()
       int    counted_bars=IndicatorCounted();
    The preceding code is three functions of MQL4 language.

    The init function is where we put all the programming commands we want to execute at once when the program (cursor) is started.

    The start function is where we put all the programming orders that we want to execute with each price change.

    The deinit function is where we put all the programming commands that we want to execute at once when removing the cursor from the chart.

    More explanation of a function and how to write it in general:

    In the first lesson, a function is a block of code executed by typing the function name.

    This function returns to us with a value that we choose with the return command, and it is usually present at the end of the function.

    Each function has a name that must match the terms of naming in MQL4 language, namely:

    The job title must begin with a letter, not a number.
    No more than forty characters.
    - It should not contain prohibited characters such as + - \ / *% ^ #% @! etc.
    Not be one of the reserved names for the MQL4 language itself such as print, int and other reserved words that we cannot name our functions with.

    We must also specify for the job the type of value it will return to, whether it is numerical, text, or other known types of data.

    The textual formula for writing a function is as follows:

    First, we write the type of return value such as int or double where int means that the return value is an integer such as 859 and double means that the return value is a floating-point number such as 1.2358.

    After that, we write the job name according to the naming terms that we explained above.

    After that, we write parentheses, closing the first second in the form ().
    After that, we open parentheses {} and write the code we want inside them.

    The final job formula is as follows:

    PHP Code:

    int FunctionName()
    We can also write them all on one line as follows:

    PHP Code:

    int FunctionName() { return(0); }
    Moreover, the job distribution on more than one line is for ease of reading only by the programmer or who will see the code in general.

    Though trading on financial markets involves high risk, it can still generate extra income in case you apply the right approach. By choosing a reliable broker such as InstaForex you get access to the international financial markets and open your way towards financial independence. You can sign up here.

  2. The Following User Says Thank You to Somia2020 For This Useful Post:

    ghada1996 (25-01-2021)

Reply to thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts