Opinion,suggestions _EA function

 

Hi. I have a function that keeps my platform unresponsive and 100% CPU usage each time it executes, 

I hope someone could help... 

Please note, I have a loop of continuous buying and selling and means that there are always

positions left open at negative or positive result... 

 

//-------------------------------------------------------------------+
// Close at profit Function                                          |
//-------------------------------------------------------------------+
   void CloseatProfit( string Symb ) 
      {
         total = OrdersTotal();
         int ticket = 0;
         while ( OrdersTotal() > 10 )
            {
               for( int cnt = total()-1; cnt >= 10; cnt-- )
                  {
                     if ( OrderSelect( cnt, SELECT_BY_POS, MODE_TRADES ))
                        {
                           if (  OrderProfit() > 1 )
                                 {
                                    ticket = OrderTicket();
                                 }
                        }
                  }
               
               if( ticket != 0 && OrderSelect(ticket,SELECT_BY_TICKET))
                        {
                           if (  OrderType() == OP_BUY && OrderSymbol() == Symb )
                           if ( OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(),MODE_BID), 10, clrNONE ) ) Print("Close order success");
                           else Print( "Close order failed");
                     
                           if (  OrderType() == OP_SELL && OrderSymbol() == Symb ) 
                           if ( OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(),MODE_ASK), 10, clrNONE ) ) Print("Close order success");
                           else Print( "Close order failed");
                        }                  
               if (ticket == 0 ) break; // I also tried this > if ( OrdersTotal() < 10 ) break; 
            }
      }
 

Try it


//-------------------------------------------------------------------+
// Close at profit Function                                          |
//-------------------------------------------------------------------+
   void CloseatProfit( string Symb )
      {
         total = OrdersTotal();
         int ticket = 0;
         if(OrdersTotal() <= 10) return;
                for( int cnt = total-1; cnt >= 9; cnt-- )
                  {
                     if ( OrderSelect( cnt, SELECT_BY_POS, MODE_TRADES ))
                        {
                           if ( OrderSymbol() == Symb && OrderProfit() > 1 )
                                 {
                                 if ( OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), 10, clrNONE ) ) Print("Close order success");
                                 else Print( "Close order failed");
                                 }
                        }
                  }
               
      }
 
tuoitrecuoi:

Try it


//-------------------------------------------------------------------+
// Close at profit Function                                          |
//-------------------------------------------------------------------+
   void CloseatProfit( string Symb )
      {
         total = OrdersTotal();
         int ticket = 0;
         while ( OrdersTotal() > 10 )
            {
               for( int cnt = total-1; cnt >= 9; cnt-- )
                  {
                     if ( OrderSelect( cnt, SELECT_BY_POS, MODE_TRADES ))
                        {
                           if ( OrderSymbol() == Symb && OrderProfit() > 1 )
                                 {
                                 if ( OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), 10, clrNONE ) ) Print("Close order success");
                                 else Print( "Close order failed");
                                 }
                        }
                  }
               
            }
      }


Wow! Thank you.

May I ask, no -break-  - IsStopped()- ?

If I have 10 or 100 open positions, the function will only close,per ticket,per symbol of only OrderProfit() > 1?