Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 133
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
Hi All. Can you tell me how to change this code for(int i=OrdersTotal()-1;i>=0;i--){
Hi All. Please tell me how to change this code for(int i=OrdersTotal()-1;i>=0;i--){
{
if( /*Функция закрытия. Если вернула истину*/ )
i--;
}
Try it this way. Instead of comments, you should use the function to close the order. I have not checked its functionality. And here, I think that we will have to call the function that calculates the amount of orders each time, since the number of orders will decrease.
You may also try such a variant:
/*Функция закрытия ордера*/
it closes in an awkward way)
not correct, but for now (up to some build) it works: on successful closing of i--
Hi All. Can you tell me how to change this code for(int i=OrdersTotal()-1;i>=0;i--){
//| Закрыть все позиции начиная с первых |
//+------------------------------------------------------------------+
double CloseOrders()
{
for(int i=0; i<OrdersTotal(); )
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
break;
if (OrderMagicNumber() != mn)
break;
int type = OrderType();
bool result = false;
switch(type)
{
//Close opened long positions
case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), Slippage, CloseColor );
break;
//Close opened short positions
case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), Slippage, CloseColor );
break;
}
if(result == false)
{
Print("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
i++;
}
}
return (True);
}
// End
It closes in an awkward way)