Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1689
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
If you don't like "-1", you can do this.
No, you can't - the program will crash if you access your array that way.
At best, if you access your internal arrays, you will miss the data you need, or simply not reach it in the loop.
Basically it's simple, your unique sums up all the mismatched orders between different magicians...
For example there are 3 orders
The first iteration of magic=1 unique=0, at the end of the iteration unique will be=2.
The second iteration magik=2unique=2, at the end of the iterationunique will be=3
Since 3>=number of all orders, the while loop will break... And magic =3 was never checked... So magic =2 again and so on with all...
The first order is given magic =1 by default. Then the loop goes into action:
Start of iteration magic = 1 unique = 0, at the end (when there is already one order with magic = 1) magic = 1 is still 1 and unique = 0
Second iteration magic = 2 unique = 0, at the end magic = 2 and unique = 1 (no match) and the retorn is given to the 2nd order magic = 2.
The third should be the same...
I wanted to print the whole process, but something went wrong:
The first order is given magic = 1 by default. Then a loop is started:
Start of iteration magic = 1 unique = 0, at the end (when there is already one order with magic = 1 ) magic is still 1 and unique = 0
Second iteration magic = 2 unique = 0, at the end, magic = 2 and unique = 1 (no match) and the retorn is assigned to the 2nd order magic = 2.
The third should be the same...
I wanted to print the whole process, but something went wrong:
Aim formore- ALL programming languages.
It's simple - in programming languages, counting starts at zero. The first cell of an array will have an index of 0. Therefore, you have to do a reverse loop BEFORE zero INCLUDING it. I.e. >=0
OrdersTotal() outputs, for example, 10. And you start a loop from 10, while the array's last index is 9 (remember, we're starting from zero?). And what will happen when you access a non-existing array cell? That's right - the program will crash on a critical error, because you have gone into an unallocated area of memory, beyond the array's limits.
These are solid crutches for sure. Read, learn and everything will come to you.
There are tons of free and good courses on C/C++.
Mql is close to them and you can freely learn. Fortunately, deep knowledge is not required. But at least the syntax of the language and the basic basics of algorithms.
Otherwise we get nonsense in the topic, instead of consultations on the platform and algorithms, primary schools level dialogues - where to put ; what is a loop and why indexes are 0.
For example, there is a site intuit.ru - there are courses on C and algorithms, take your time, a couple of weeks at most. At the same time you can get a paper :-)
Otherwise we get nonsense in the topic, instead of consultations on the platform and algorithms, primary schools level dialogues - where to put ; what is a loop and why indexes are 0.
For example, there is a site intuit.ru - there are courses on C and algorithms, take your time, a couple of weeks at most. You may get a paper at the same time:-)
Like this?
OrdersTotal() gives for example 10. And you start the loop from 10. But the last index of the array is 9 (remember, we're counting from zero?). And what will happen when you access a non-existing array cell? That's right - the program will crash on a critical error, because you have gone into an unallocated area of memory, beyond the array's limits.
I stand corrected... There won't be a critical error, just the OrderSelect boolean will return false... and that's all... But of course, it's better to avoid... For if you use incorrect code features, it's difficult to predict possible errors...
The first order is given magic = 1 by default. Then a loop is started:
Start iteration magic = 1 unique = 0, at the end (when there is already one order with magic = 1 ) magic = 1 and unique = 0
Second iteration magic = 2 unique = 0, at the end magic = 2 and unique = 1 (no match) and the retorn is assigned to the 2nd order magic = 2.
The third should be the same...
I just see that the filling of unique goes very fast and reaches the limit, and magic barely grows... Generally, it was wrong to use the same variable for both loop control and for the logic inside the loop where this variable inflates...
Print to find a solution in this context, but I would suggest just reformulating the problem... For example find the maximum magik in orders by the loop and return it with +1, that would be the right simple solution.
You can do it this way, the code is called as needed, so its weight is not a problem
For the test I used Buy/Sell
Forum on trading, automated trading systems & strategy testing
Any questions from newbies on MQL4 and MQL5, tips and discussion on algorithms and codes
Vitaly Muzichenko, 2021.10.19 23:08
I will correct it a little. There will be no critical error, just the boolean OrderSelect will return false ... and that's all... But of course it's better to avoid... For if the code features are not used correctly, it's hard to predict the possible pitfalls...
I just see unique filling up at a very fast pace and reaching its limit, while magic barely grows... Generally it was wrong to use the same variable for both loop control and for the logic inside the loop, where this variable inflates...
Print to find a solution in this context, but I would suggest just reformulating the problem... For example find the maximum magik in orders by the loop and return it with +1, that would be the right simple solution.
You can do it this way, the code is called as needed, so its weight is not a problem
For the test I used Buy/Sell