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

 

Folks, help is needed. The function has to close half of the orders necessarily starting with the oldest one. In the first case, the orders are closed one by one for some reason, and in the second, they start closing in the wrong order.

void CloseHalfOrders (int otype)// ф-ция закрытия половины ордеров сетки
{
  int count = 0; double CTbuy = CountTrades(OP_BUY); double CTsell = CountTrades(OP_SELL); 
  for (int i = 0; i<=OrdersTotal;i++)
  {
    if (OrderSelect(i, SELECT_BY_POS,MODE_TRADES))
    {
       if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && OrderType() == otype)
       {
         if (otype == OP_BUY)
         { 
           if (count<CTbuy/2 && CTbuy>3 )
           
             OrderClose(OrderTicket(),OrderLots(),Bid,0,Black);
             count++;
             Sleep(1000);
           
         }
       
       
         else if (otype == OP_SELL)
         {
           if (count<CTsell/2 && CTsell>3)
           
           OrderClose(OrderTicket(),OrderLots(),Ask,0,Black);
           count++;
           Sleep(1000);
           
         }
       }
     }
   }
   
 }
 for (int i = OrdersTotal()-1; i>=0; i--)
 
vadynik:

So I need an integer...
MathRound
 
evillive:
MathRound


so this is rounding, the number does not become int, it remains double
 
vadynik:

so this is rounding, the number does not become int, but remains double

So? Is there a fundamental difference between 1 and 1.0 for calculations? Of course the format is double, but the value is integer.


An especially perverted variant then: DoubleToStr and then StringToInteger

 
vadynik:

Please tell me how to remove the warning in the new compiler

possible loss of data due to type conversion

int    SizeB      =MathAbs(Open[1]-Close[1])/Point;

Так помогает 

int    SizeB      =(int) ( MathAbs(Open[1]-Close[1])/Point );

 
Zhunko:



Thank you, so no pre-warning, it's already eating my eye)
 

Hi, I've searched Kim's, but I can't find anything that lets me know: Which order (pending) opened the position from? From a limit order or a stop order?

I tried to compare prices of the last order opened

if(MathAbs(GetOrderOpenPrice()-LastPrice) <= slip)

with a position opened on it but the whole logic is broken. Maybe there is something more suitable? Thanks!

 
Trader7777:

Folks, help is needed. The function should close half of the orders necessarily starting with the oldest one. In the first case, the orders are closed one by one for some reason, and in the second, they start closing in the wrong order.


There was a question like this, how to close orders starting with the oldest one, a couple of pages later there is an answer and the correct code.


https://www.mql5.com/ru/forum/145455/page406

 
borilunad:

Hi, I searched Kim's, but I can't find anything that lets me know: Which order (pending) opened the position from? From a limit order or a stop order?

I tried to compare prices of the last order opened

with a position opened on it but the whole logic is broken. Maybe there is something more suitable? Thanks!

Boris. Try writing in the commentary of the orders - limit to limit, stop to stop. Then from these comments of open positions you will know what the legs have grown from. Only partial closing of these comments will erase them. Maybe something else can kill the comments. Only deleted positions are saved in the history. The ones that worked aren't there. You have to go through... you figure out what you have to go through...
 
artmedia70:
Boris. Try writing in the commentary of the orders - limit to limit, stop to stop. Then from these comments of open positions you will know what the legs have grown from. Only partial closing of these comments will erase them. Maybe something else can kill the comments. Only deleted positions are saved in the history. The ones that worked aren't there. You have to go through... You can't figure out what you have to go through...
Thank you, Artem! So I "twisted", and something is wrong. And comments and magicians do not want to attract the attention of DC. I need it only for the next move, as in chess! Everything is closed in its entirety by the conditions. I'm trying and panting, maybe I'll finish it! Happy New Year, Artem!