Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 429

 
splxgf:

so if there is a close, it is better to loop backwards.

No, it should close from the old to the new order
 
Trader7777:

no, it should close from the old to the new order

If you change the order, it will be from the old to the new. In the meantime, from the new to the old, and even through one sometimes it may happen.
 
evillive:

If you change the order, it will be from the old to the new. In the meantime, from the new to the old one, and sometimes it may happen through one.

If you do for (int i = OrdersTotal()-1; i>0; i--) it will close from new to old!
 
evillive:

If you change the order, it will be from the old to the new. But in the meantime, from the new to the old, and sometimes one after the other, it can happen.

I don't understand, if you are too lazy to suggest errors, why impose on me a function that, according to my TS, I don't need?
 

Good evening ...

this https://www.mql5.com/ru/code/9767 indicator in the Expert Advisor will be correct?

if(iCustom( NULL,0, "wave(MACD_FZR)",1,0)<Low[1] )

{

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point, "macd sample",16384,0,Green);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());

}

else Print("Error opening BUY order : ",GetLastError());

return(0);

}

// check for short position (SELL)

if(iCustom( NULL, 0, "wave(MACD_FZR)",1,1)>High[1] )

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point, "macd sample",16384,0,Red);

 
Trader7777:

I don't understand, if you're too lazy to suggest errors, why should you impose on me a function that I don't need according to my TS?

Well, then look at your function, for example the first order is taken and as it fits the condition it is deleted... Its place is taken by the second order.

During the next loop, the third order is checked, and the second one will be skipped.

That is why we pointed out that the enumeration is wrong...

If your own order is really important, we can decrement the loop variable when deleting it.

 
Trader7777:

I don't understand, if you're too lazy to suggest errors, why impose on me a function that, according to my TS, I don't need?

I told you to do it while. Like (update 3):

void CloseHalfOrders(int otype) {
   int count = 0;
   double CTexisting = CountTrades(otype), nCloseOrdersCnt = NormalizeDouble(CTexisting/2,1), price;
   int i = 0;
   while (i < OrdersTotal()) {
      if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES)) {
         if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && OrderType() == otype) {
            if (otype == OP_BUY) price = Bid;
            else if (otype == OP_SELL) price = Ask;
            else return;//работаем только с OP_BUY/OP_SELL
            if (count < nCloseOrdersCnt) {
               OrderClose(OrderTicket(),OrderLots(),price,0,Lime);
               count++;
               Sleep(1000);
               i = 0;
               continue;
            } else i = OrdersTotal();
         }
      }
      i++;
   }
}
 

Or

           OrderClose(OrderTicket(),OrderLots(),Bid,0,Lime);
           i--;
 
                    if (count<n)

Why are k and n compared with the total number of orders closed?

 

Trader7777:

evillive:

If you change the order, it will be from the old to the new. But in the meantime, from the new to the old, and even through one sometimes it may happen.


if you do for (int i = OrdersTotal()-1; i>0; i--) it will close from new to old!

Trader7777:

I don't get it, if you're too lazy to tell me what's wrong, why are you imposing a function on me that I don't need according to my TS?

If an order with number OrdersTotal() -1 is the newest one to you and order with number 0 is the oldest, I have nothing more to say. When a person's eyes are closed, they only open of their own free will, no one can force them.

for (int i =0; i<OrdersTotal();i++) //i++ кто будет писать, Пушкин? Зачем сочинять химеру FOR + WHILE???

By the way, what function did I inadvertently "impose" on you there?

Reason: