How do I close all orders at total profit in pips? - page 7

 
khasan kayumov:
Could someone please advise how to close all orders by the total profit in pips?

Read the posts, some I didn't understand. I guess I haven't encountered them.

I understood this question as follows: how to close open orders for different instruments when the profit is reached.

Perhaps, it is not quite smart, but it is the way I implemented it:

extern int    iPrftAc       = 35;   // Закрытие всех ордеров по текущему счету.
.......

if (AccountProfit() > iPrftAc)
   {
    Print("//--> Закрытие ордеров: Условие достижения ПРИБЫЛИ ПО ТЕКУЩЕМУ СЧЕТУ!;");
    vOrderClose(9,0,"");          
   }
........
void vOrderClose(int f_iTypOrdDel,  //Тип операции выбранного ордера на удаление
                 int f_iOrderTicket,//Номер тикета ордера
                 string f_sNamSig)  //Наименование сигнала
{
.......
 if (f_iTypOrdDel==9) // Удаление всех открытых и отложенных ордеров по всем финансовым инструментам.
     {
      int CloseOrdSymAll = 0;
      do {
          CloseOrdSymAll = 0;
          for (int i=0; i<=OrdersTotal(); i++)
            {
             if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)
                {
                 switch(OrderType())
                    {
                     case OP_BUY     :f_sCmdType = "OP_BUY";
                                      f_bResult = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),iSlippage,clrBlue);
                                      if (f_bResult == true) Print("//---> vOrderClose: ",f_iTypOrdDel,") Order(#",OrderTicket(),") Type(#",OrderType(),") ",f_sCmdType,"  successfully");
                                      else {
                                            Print("//--->vOrderClose: № ",f_iTypOrdDel,". Order(#",OrderTicket(),") Type(#",OrderType(),") ",f_sCmdType,", failed. Error:", GetLastError());
                                            Sleep(1000);
                                           }  
                                      CloseOrdSymAll++;
                                      break;
                                         
                     case OP_BUYLIMIT:f_sCmdType = "OP_BUYLIMIT";
                                      f_bResult = OrderDelete(OrderTicket(),CLR_NONE);
                                      if (f_bResult == true) Print("//---> vOrderClose: ",f_iTypOrdDel,") Order(#",OrderTicket(),") Type(#",OrderType(),") ",f_sCmdType," successfully");
                                      else {
                                            Print("//--->vOrderClose: № ",f_iTypOrdDel,". Order(#",OrderTicket(),") Type(#",OrderType(),") ",f_sCmdType,", failed. Error:", GetLastError());
                                            Sleep(1000);
                                           }  
                                      CloseOrdSymAll++;
                                      break;
                                         
                     case OP_BUYSTOP :f_sCmdType = "OP_BUYSTOP";
                                      f_bResult = OrderDelete(OrderTicket(),CLR_NONE);
                                      if (f_bResult == true) Print("//---> vOrderClose: ",f_iTypOrdDel,") Order(#",OrderTicket(),") Type(#",OrderType(),") ",f_sCmdType," successfully");
                                      else {
                                            Print("//--->vOrderClose: № ",f_iTypOrdDel,". Order(#",OrderTicket(),") Type(#",OrderType(),") ",f_sCmdType,", failed. Error:", GetLastError());
                                            Sleep(1000);
                                           }  
                                      CloseOrdSymAll++;
                                      break;
                                         
                     case OP_SELL    :f_sCmdType = "OP_SELL";
                                      f_bResult = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),iSlippage,clrRed);
                                      if (f_bResult == true) Print("//---> vOrderClose: ",f_iTypOrdDel,") Order(#",OrderTicket(),") Type(#",OrderType(),") ",f_sCmdType," successfully");
                                      else {
                                            Print("//--->vOrderClose: № ",f_iTypOrdDel,". Order(#",OrderTicket(),") Type(#",OrderType(),") ",f_sCmdType,", failed. Error:", GetLastError());
                                            Sleep(1000);
                                           }  
                                      CloseOrdSymAll++;
                                      break;
                                         
                     case OP_SELLLIMIT:f_sCmdType = "OP_SELLLIMIT";
                                       f_bResult = OrderDelete(OrderTicket(),CLR_NONE);
                                       if (f_bResult == true) Print("//---> vOrderClose: ",f_iTypOrdDel,") Order(#",OrderTicket(),") Type(#",OrderType(),") ",f_sCmdType," successfully");
                                       else {
                                             Print("//--->vOrderClose: № ",f_iTypOrdDel,". Order(#",OrderTicket(),") Type(#",OrderType(),") ",f_sCmdType,", failed. Error:", GetLastError());
                                             Sleep(1000);
                                            }  
                                       CloseOrdSymAll++;
                                       break;
                                         
                     case OP_SELLSTOP :f_sCmdType = "OP_SELLSTOP";
                                       f_bResult = OrderDelete(OrderTicket(),CLR_NONE);
                                       if (f_bResult == true) Print("//---> vOrderClose: ",f_iTypOrdDel,") Order(#",OrderTicket(),") Type(#",OrderType(),") ",f_sCmdType," successfully");
                                       else {
                                             Print("//--->vOrderClose: № ",f_iTypOrdDel,". Order(#",OrderTicket(),") Type(#",OrderType(),") ",f_sCmdType,", failed. Error:", GetLastError());
                                             Sleep(1000);
                                            }  
                                       CloseOrdSymAll++;
                                       break;
                    }
                }    
            }          
         }
     }
}
//+------------------------------------------------------------------+
//|Конец                                                             |
//+------------------------------------------------------------------+
 

What I don't understand is this.

Are you making money or making points?

Why bother searching for complex results when the desired (MAIN!) result is always in front of you: if the total profits (in money!) of all trades suit you, then close the whole damn thing!

 
Artemij:

What I don't understand is this.

Are you making money or making points?

Why bother to search for complex results, when the required (MAIN!) result is always in front of you: if the total profit (in money!) of all trades suits you, then close the whole damn thing!


If the profit is in money, then when you change the lot size, you must proportionally change the profit value. This is inconvenient.

 
Vadym Kulish:

Read the posts, some of them I didn't understand. I guess I haven't encountered them.

I understood this question as follows: how to close open orders for different instruments when the profit is reached.

Maybe, it is not very elegant, but this is how I implemented this question:

Why do we need such a big pause? Everything is working fast now.

I close without any pause at all.

 
Renat Akhtyamov:

Why the long pause? It's running fast now...

I don't pause at all.


It's a remnant of the previous code - I didn't understand the nature of the error and the meaning of theMarketInfo(OrderSymbol(),MODE_ASK), I left it there just in case. The Expert Advisor is incomplete.