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:
int GetMagic()
{
int magic = 0;
int unique = 0;
if(OrdersTotal()){
do{
magic++;
for(int i = OrdersTotal() - 1; i >= 0 ; i --){
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
if(magic != OrderMagicNumber())
unique ++;
}
}
Print (" MAGIC ", magic, " | UNIQUE ", unique)
}while(unique < OrdersTotal());
} elsereturn (magic + 1);
return (magic);
}
-----------------------------------
'endless cycle.mq4' endless cycle.mq4 11
'}' - semicolon expected endless cycle.mq4 497
'else' - 'while' expected endless cycle.mq4 505
'else' - illegal 'else' without matching 'if' endless cycle.mq4 505
'OnTick' - function declarations are allowed on global, namespace or class scope only endless cycle.mq4 606
'OnTick' - function already defined and has body endless cycle.mq4 606
see previous declaration of function 'OnTick' endless cycle.mq4 606
'}' - unexpected end of program endless cycle.mq4 6316 errors, 0 warnings 71
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:
int GetMagic()
{
int magic = 0;
int unique = 0;
if(OrdersTotal()){
do{
magic++;
for(int i = OrdersTotal() - 1; i >= 0 ; i --){
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
if(magic != OrderMagicNumber())
unique ++;
}
}
Print (" MAGIC ", magic, " | UNIQUE ", unique); // <---
}while(unique < OrdersTotal());
} elsereturn (magic + 1);
return (magic);
}
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.
Thank you. That's not what I meant. Anything could be forgiven for mql if it were on an open licence. Otherwise, I'm picking on you. Well, it seems to me, for example, that we could have put a flag in NormalizeDouble function and used place trimming or arithmetic rounding. Or, for example, we could expand the functions of position handling, for example, return the number of open positions only for sell or buy. Also, a more detailed help could be written. But this is only the opinion of an amateur. Also, please forgive me if the previous statement seemed harsh.
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 :-)
Maxim Kuznetsov 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. You may get a paper at the same time:-)
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
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
Print(GetMagic());
}
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+int GetMagic()
{
//Если должен быть открыт стопордер и если есть уже открытые или отложенные//ордера, то возможно некоторые с маджиком, это надо проверить и сгенерировать//для нашего ордера уникальный маджикint arr[];
int n=-1;
int OT=OrdersTotal();
for(int i=0; i<OT; i++) {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) {
if(OrderType() == OP_SELL || OrderType() == OP_BUY) {
if(ArraySearchInt(arr, OrderMagicNumber())==-1) {
n++;
ArrayResize(arr,n+1);
arr[n]=OrderMagicNumber();
}
}
}
}
ArraySort(arr);
OT=ArraySize(arr);
for(int i=0; i<OT; i++)
if(arr[i]!=i) return i;
return OT;
}
//-- удаляет копии с массиваint ArraySearchInt(int& m[], int e)
{
for(int i=0; i<ArraySize(m); i++) {
if(m[i]==e) return(i);
}
return(-1);
}
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.
It's a last resort, in case this option doesn't work out. In the meantime, this is what the print came up with.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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