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

 
BeerGod:

Is there any way to implement it correctly so that it closes starting from zero? If possible a line of code please.
Go through the entire list (of orders) in the desired direction and put the Ticket values into an array, then delete the orders by brute forcing this array.
 
BeerGod:

Is there any way to implement it correctly so that it closes starting from zero? If possible a line of code please.


Just a quick fix:

//+------------------------------------------------------------------+
//|                 Закрыть все ордера                               |
//+------------------------------------------------------------------+


double ClossAllOrders ()

{
  for(int i=0; i<OrdersTotal(); )
  {
    if ( !OrderSelect(i, SELECT_BY_POS) )
      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, Lime );
                          break;
      
      //Close opened short positions
      case OP_SELL      : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), Slippage, Lime );
                          break;

      //Close pending orders
      case OP_BUYLIMIT  :
      case OP_BUYSTOP   :
      case OP_SELLLIMIT :
      case OP_SELLSTOP  : result = OrderDelete( OrderTicket() );
    }
    
    if(result == false)
    {
      Print("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
      i++;
      Sleep(500);
    }  
  }
}

// End
 
Trader7777:

Yes, I should have written more precisely. It's just that I've already laid out in full twice what this function is supposed to do, but no one has answered. Once again, what this function should do. Suppose I have a grid of orders. Whether they are opened with the same step or not, it does not matter. One order was opened earlier and another one later, i.e. every position has passed a different amount of points with a different lot. The grid will be closed according to certain conditions and I need to calculate the LOT needed to cover the loss incurred from that grid for TP points. In order not to write two mirror functions I introduced an otype parameter in the function.

But still there is an error somewhere. Please help me fix it.



I would take a different route. First, I would calculate the loss from closing the grid. And then it is as simple as that. Loss = Profit from the next order. Express the profit from the order through the lot and TP and find the lot from the equation.
 
Contender:


A quick hand job:


Thank you very much, everything is working correctly, thanks to all who responded!


 
khorosh:
I would take a different route. First, I would calculate the loss from closing the grid. And then it is as simple as that. Loss = Profit from the next order. Express the profit from the order through the lot and TP and find the lot from the equation.


Is the loss at the end of the grid in money or pips?
 
Trader7777:

is the loss from closing the grid in money or pips?
In the currency of the deposit.
 
What about the fact that each pair has a different point price?
 
Trader7777:
What about the fact that each pair has a different point price?
Why would you want to do that?
 
Trader7777:
What about the fact that each pair has a different point price?

Here you can see how it is implemented


https://www.mql5.com/ru/code/7275

https://www.mql5.com/ru/forum/113937/page2

https://docs.mql4.com/ru/constants/marketinfo

 
ErrorDescription
What is this operator or function or variable, in short, what is it?
How do I enter it so that the compiler doesn't throw an error?
'ErrorDescription' - variable not defined  
?

I found a replacement in the navigator:
#include <stdlib.mqh>
.
Reason: