Discussion of article "Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator" - page 2
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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
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:
I hope that helps.
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