Discussion of article "Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator"

 

New article Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator is published:

MetaQuotes Programming Language 5 (MQL5), included in MetaTrader 5 Client Terminal, has many new possibilities and higher performance, compared to MQL4. This article will help you to get acquainted with this new programming language. The simple examples of how to write an Expert Advisor and Custom Indicator are presented in this article. We will also consider some details of MQL5 language, that are necessary to understand these examples.

Author: Denis

 

After downloading the file "indicator_TP_en.mql5", rename it to "indicator_TP.mql5", please.

 

 

This ExpertAdvisor does not work on MT5 build 712, at least not for me.

There is an error message "Cant't copy indicator buffer".

Also the indicator does not compile without warnings,

"possible loss of data due to type conversion" on line 53,

"possible use on uninitialized varaiable 'day_n'"  on line 54

"possible use on uninitialized varaiable 'h_day'"  on line 62

"psosible use on uninitialized varaiable 'l_day'"  on line 63


Can you correct these problems, please?

This is otherwise a good example for us who have background in other software but MT5.

 
If I want to place 5 sell stop and 5 buy stop pending orders and gap between them 10 pips. How do I so that?
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
 

This is a excellent article, for beginners and people who comes from mql4, with in prime a good trading strategy example.

There are some minor lacks in code (error checking not always implemented), but the EA works very well if used on minute timeframe as recommended by the author. Warnings when compiling the indicator are only warnings, and are not blocking you to use it and the EA.

Thank you.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Chart Constants / Chart Timeframes
  • www.mql5.com
Standard Constants, Enumerations and Structures / Chart Constants / Chart Timeframes - Documentation on MQL5
 

this is not an easy way of explaining mql5 to the people. (like beginners ever had chance to understand it!) its like with programming books 90% of people dont have idea how to start. They open this book for example about c programming and first "Easy example" is long for 1 whole page written in tiny fonts. In my whole life i read only one good programming book that could teach programming to anyone. The reason for that is that they are being written by probably excellent programmers, but unfortunately very bad teachers. Programming can be really easy and i will prove it to you making a simple tutorial for MQL4 programming language when i have a little more time than now. For everyone - even total beginners. The biggest mistake is to teach people details of language most of their work should be ctrl+C and ctrl+v and use google for the commands and most important - keeping everything VERY SIMPLE. I know 10+ programming languages (I programm since i was 7) and i am still am scared by the way this "Easy example" on 11kb (!!!) is explained. I would like to know is there is any real programming beginner that learned MQL5 from this example ;D. I doubt it and if there is you can count these people on fingers of one hand.

Fast Dive into MQL5
  • 2012.08.02
  • MetaQuotes Software Corp.
  • www.mql5.com
You have decided to study MQL5 trading strategies' programming language, but you know nothing about it? We have tried to examine MQL5 and MetaTrader 5 terminal from the newcomers' point of view and have written this short introductory article. In this article, you can find a brief idea of the possibilities of the language, as well as some tips on working with MetaEditor 5 and the terminal.
 
angreeee:

this is not an easy way of explaining mql5 to the people. (like beginners ever had chance to understand it!) its like with programming books 90% of people dont have idea how to start. They open this book for example about c programming and first "Easy example" is long for 1 whole page written in tiny fonts. In my whole life i read only one good programming book that could teach programming to anyone. The reason for that is that they are being written by probably excellent programmers, but unfortunately very bad teachers. Programming can be really easy and i will prove it to you making a simple tutorial for MQL4 programming language when i have a little more time than now. For everyone - even total beginners. The biggest mistake is to teach people details of language most of their work should be ctrl+C and ctrl+v and use google for the commands and most important - keeping everything VERY SIMPLE. I know 10+ programming languages (I programm since i was 7) and i am still am scared by the way this "Easy example" on 11kb (!!!) is explained. I would like to know is there is any real programming beginner that learned MQL5 from this example ;D. I doubt it and if there is you can count these people on fingers of one hand.

You are right about programmers not being good teachers in general.

But I don't agree when you said mql5 is so difficult to learn, mainly for a programmer who have experimented with 10+ languages. 

 
Indeed this is great article for beginners of mql5 programming, like me. angevoyageur speak right about it.
 
I have copy paste the Expert Advisor and try to test it with Strategytester. But it doesn't make any trades. I am new to MQL5 and programming so maybe I just made a stupid mistake. It compiled without any errors. I'd really like the strategy! Anyone ideas why it doesn't run on strategytester..?
 

Im new at mql5 programming


Was trying to learn through this example, but im a bit lost with the loop at the end of the indicator build. Where exactly did he assign a value to day_n variable?


Because the loop will check for day_n<day_t. How can the program know day_n value?


for(i=prev_calculated;i<rates_total;i++)
     {
      day_t=time[i]/PeriodSeconds(ATRtimeframe);
      if(day_n<day_t)
        {
         day_n=day_t;
         h_day=high[i];
         l_day=low[i];
        }
        else
        {
         if(high[i]>h_day) h_day=high[i];
         if(low[i]<l_day) l_day=low[i];
        }
      bu[i]=l_day+atr[1];
      bd[i]=h_day-atr[1];
     }


And how is it calculated at all? Lets assume rate_total = 10 and there is still no calculated bar yet. So prev_calculated = 0


day_t=time[0] (TODAY! since its counted backwards)/PeriodSeconds... since it starts counting from 1970, lets assume it starts count from 10 days ago. so it should give 10, right?

So day_t=10. Now it checks if dayt > dayn. I dont know dayn, but i know dayt=10. Im gonna assume dayn is zero, since there is no value.

Then dayn becomes 10 too. Ok.

Second roll of the loop. prev_calculated + 1= 1.

DayT=time[1] (yesterday)/period... remember, it starts counting from 10 days ago... but now only until yesterday. it should give a value of 9, right?

but now dayN < dayT is false. Then it starts to perform the else expressions. Ok. I understand. 


It then will calculate all the bu[] and bd[]. Ok. The loop will end when prev < total rate is false.

But when a new bar arrives, and it becomes true again, i will start from zero again? Or it will start from 10 and go straight to the else part?


Thanks!!!!

 
Grzegorz Korycki:

this is not an easy way of explaining mql5 to the people. (like beginners ever had chance to understand it!) its like with programming books 90% of people dont have idea how to start. They open this book for example about c programming and first "Easy example" is long for 1 whole page written in tiny fonts. In my whole life i read only one good programming book that could teach programming to anyone. The reason for that is that they are being written by probably excellent programmers, but unfortunately very bad teachers. Programming can be really easy and i will prove it to you making a simple tutorial for MQL4 programming language when i have a little more time than now. For everyone - even total beginners. The biggest mistake is to teach people details of language most of their work should be ctrl+C and ctrl+v and use google for the commands and most important - keeping everything VERY SIMPLE. I know 10+ programming languages (I programm since i was 7) and i am still am scared by the way this "Easy example" on 11kb (!!!) is explained. I would like to know is there is any real programming beginner that learned MQL5 from this example ;D. I doubt it and if there is you can count these people on fingers of one hand.

How true. I'm new to coding and I can tell you that you are perfectly correct. I need to understand how the coding is structured. The layout of the program. I have been searching the web for tutorial to make a newbie understand. It is impossible. Is there any idea you can direct me to such to such tutorial. The videos I download from youtube is all the same. Thanks
Reason: