You can't put an order opening immediately into a loop. You have to do a full loop on the orders first and find out exactly whether there is a Buy or not.
And only after that do you put a Buy, after that cycle.
You can't put an order opening immediately into a loop. You must first do a full loop on the orders and find out exactly whether there is a Buy or a No.
And only after that should you place a Buy if it is not there yet.
Right, I just took a piece from my programme posti without re-doing it. I'll do it now - five minutes...
But this code is not correct either! It will only open a buy order if there are no other orders for any other financial instrument, and if there are any other orders, it will not open a buy order.
The order is not executed immediately. Without a pause on the next tick, the order may not be opened yet, and the program will send another command to open it. In the MT5 tester, you can already enter the execution delay.
Have you tried making it a separate function to search for the presence/absence of items?
For example:
bool ExistPositions(int mn, string sy="", int op=-1) {
if (sy=="") sy=Symbol();
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS)) {
if (OrderMagicNumber()!=mn) continue;
if (OrderSymbol()!=sy) continue;
if (OrderType()>1) continue;
if (op<0 || OrderType()==op)
return(True);
}
}
return(False);
}
Magic - magic number of EA (set in settings, or generated by EA automatically). Then to check the absence of position Buy by current symbol should be written:
if (!ExistPositions(Magic, Symbol(), OP_BUY)) {
// ... Тут код для вызова функции открытия позиций ...
}
Note - not just a command to open a Buy order, but a full function with handling all order opening parameters and errors returned by the server.
However, for a tester, we can do without checking the entered parameters for valid values...
Have you tried making it a separate function to search for the presence/absence of items?
For example:
Then to check for absence of Buy position by current symbol should be written:
Note - not just a command to open a Buy order, but a full function with processing all parameters of the order opening and errors returned by the server.
However, the tester may do without checking the entered parameters for permissible values...
In the first post I gave the functions, kolyango wasn't happy with that. Also, I don't like working with magicians.
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.
on the first non-buy order you will flood the account with buy orders.
Thank you! Found another mistake!
Thank you! Found another error!
Mm-hmm.
but the previous one hasn't been fixed.
You can't put an order opening immediately into a loop. You have to do a full loop on the orders first and find out exactly whether there is a Buy or not.
And only after that do you put a Buy, after that cycle.
Mm-hmm.
but the previous one wasn't fixed.
You can't put an order opening immediately into a loop. You must first do a full loop on the orders and find out exactly whether there is a Buy or a No.
And only after that should you place a Buy if it is not there yet.
Right, I just took a piece from my programme posti without re-doing it. I'll do it now - five minutes...
Right, I just took a piece from my programme posti without redoing it. I'll do it now - five minutes...
Is that right now?
What's the point of this pause?
Why the pause?
The order is not executed immediately. Without a pause on the next tick, the order may not be opened yet, and the program will send another command to open it. In the MT5 tester, you can already enter the execution delay.
Is it correct now?
Have you tried making it a separate function to search for the presence/absence of items?
For example:
Magic - magic number of EA (set in settings, or generated by EA automatically). Then to check the absence of position Buy by current symbol should be written:
Note - not just a command to open a Buy order, but a full function with handling all order opening parameters and errors returned by the server.
However, for a tester, we can do without checking the entered parameters for valid values...
Have you tried making it a separate function to search for the presence/absence of items?
For example:
Then to check for absence of Buy position by current symbol should be written:
Note - not just a command to open a Buy order, but a full function with processing all parameters of the order opening and errors returned by the server.
However, the tester may do without checking the entered parameters for permissible values...
In the first post I gave the functions, kolyango wasn't happy with that. Also, I don't like working with magicians.