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

 
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
 

Ibrahim Melssen:
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..?

Same here men I cant seem to find out why

 
Guin:

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?



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!!!!

You need to divide into two parts: 

    1 At the first time indicator applied to the chart:  prev_calculated =0 , i = 0, i++  until  i = rates_total,  it gets out of loop    (time[0] is from the past not present.) 

    2 New bar is started:  prev_calculated will be less than rates_total so condition is true,  the loop will run only on that new bar

 

Hi @Guin,

I don't think your question has been answered correctly yet. If you've used the code in the example, you probably end up with an invisible indicator that doesn't make any sense and you can't see on the chart. That's because the code never goes through this block:

if(day_n < day_t){
        day_n = day_t;
        h_day = high[i];
        l_day = low[i]
}

The reason is that day_n is not manually set to any default value, and the comparison day_n < day_t will always result in false. According to the debugger, the value of day_n when not explicitly set is "2076449103".

Just change the definition of day_n to something like:

int day_n = 0, day_t;


I hope that helps.


Guin:

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?

 

Great article,

Thanks for sharing