Download MetaTrader 5

Function to continually close positions per ticket per conditions

To add comments, please log in or register
Vantages
148
Vantages  

Hello.

With my multi currency EA, 15 symbols and 100s of open positions all the time,

which is better to use to continually closes position/s per ticket per 1-2 conditions:

1. Should I use >   " while " ;

2. Or just simply use the code below ( But, it is not properly working

    when positions are more than 50 deals ?

Thanks.


//-------------------------------------------------------------------+

// Close at profit Function                                                  |
//-------------------------------------------------------------------+
   void CloseatProfit( string Symb )
      {
         total = OrdersTotal();
         int ticket = 0;
         if(OrdersTotal() < 1) return;
                for( int cnt = total-1; cnt >= 0; 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");
                                 }
                        }
                  }
               
      }
To add comments, please log in or register