[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 39

 
artem86:

Can you please help me? How to close 5 pending orders with the same magic.

Thank you in advance!


if (OrdersTotal()>0)
{  for (int i=OrdersTotal()-1; i>=0; i--)
   {  if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
      {  if(OrderMagicNumber()==magic_number)
         {  if (OrderClose(OrderTicket(),LOT,price,3)==true)
            {  Print("Error = ",GetLastError()); return(0);
}  }  }  }  }
If all these orders were opened to sell then price=Ask, if to buy then price=Bid.
 
paladin80:
If the order was opened to sell then price=Ask, if to buy then price=Bid.


Wrong, you should

if (OrdersTotal()>0)
{  for (int i=OrdersTotal()-1; i>=0; i--)
   {  if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
      {  if(OrderMagicNumber()==magic_number)
         {  if (OrderDelete(OrderTicket())==true)
              {  
              Print("Error = ",GetLastError()); return(0);
              } 
         } 
      }  
   }  
}
 
r772ra:


Wrong, you have to

Shit, I didn't notice that I should have closed the pending orders, I was thinking about closing positions.
 

Guys - tell me, in the tester, and then when trading on the trading account, including manually, it turns out that it is possible NOT to NORMALIZE the volume of the open position, while it will be opened by the required volume. For example, if I open an order with 0.1210 lots, the terminal will open with 0.12, i.e. the "extra" fractional part is discarded by default.

Please advise whether this is another "upgrade" of the terminal or it was originally possible.

I have used this method of volume normalization before but I have missed this point in one of my ops and orders keep opening and the Expert Advisors tab gives me before opening the position the preliminary volume to be opened, particularly, 0.121 lots - I am testing this on a demo account.

Function of lot's normalization:

//+------------------------------------------------------------------+
//| Нормализация лота                                                |
//+------------------------------------------------------------------+

double NormalizeLots(double lot)
{
   double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
   double lots = NormalizeDouble(lot / lotStep, 0) * lotStep;   
   lots = MathMax(lots, MarketInfo(Symbol(), MODE_MINLOT));
   lots = MathMin(lots, MarketInfo(Symbol(), MODE_MAXLOT));   
   return (lots);
}

Calling it from EA start:

// ---------НОРМАЛИЗУЕМ НОВЫЕ РАСЧЕТНЫЕ ЛОТЫ И ОТКРЫВАЕМ ОЧЕРЕДНУЮ ПОЗИЦИЮ...            
                    Lots_New = NormalizeLots(Lots_New);
                    if (lastType == OP_SELL) WmOrderSend(Symbol(), OP_BUY, Lots_New, Ask, 0, 0, "итерация" , MagicNumber);
                    if (lastType == OP_BUY)  WmOrderSend(Symbol(), OP_SELL,Lots_New, Bid, 0, 0, "итерация" , MagicNumber);

Who is aware of it - comment, plz...

P.S. Checked again - apparently there is a situation that when you try to open a volume of 0.1466 - opens 0.14, ie, rejects everything to the right of the 2nd sign after the decimal point.

If you do the normalisation, it looks like it will open 0.15 lot - i.e. with rounding.

I'll have to check it out...

P.P.S. All the same: Who knows - comment, please...

 

Fucking ignore.

 
HELP...PLEASE...I am running the Expert Advisor on a demo and a real account, it says: will be started with the next tick...The tick comes but it will not start although the option "allow the EA to trade" is checked, the EA is enabled, no errors in the log, the Internet works and other EAs also work.This adviser works fine in the tester.If it helps: EA stopped running after I added the filter function from this article into it
 
sellena:
If it helps:The EA stopped turning on after I added the filter function from this article to it

If it helps, talk to one of the workers here.
 
sergeev:

If it helps, talk to one of the workers here.
Alex, take a look at my question if you have time... Thank you.
 
Roman.:
Alex, take a look at my question if you have time... Thank you.

I can tell you one thing - I already contacted the service (on another occasion) and they told me: "rely on defaults is harmful, use your own filters and treatments if you want to be sure". So it's up to you...
 
Roman.:
Alex, have a look at my question if you have time... Thanks.

The FAQ says it right. You can't rely on "defaults". Because I remember that 131 error (wrong lot) often came up, if you don't do a normalization before sending an order.
Maybe now the MMOs have done their own default lot checking on the servers when sending an order for execution.

So you should always do your own price and lot normalization before sending.

This is for you the rules of good coding and the pledge of less hassle with potential problems in the future.