Add True/false option and Orders Total to EA

 

Hello everybody, actually I am using this EA to close at a profit level and deleting all Pending Orders placed left on Terminal.

It works perfectly but I would like to add this functions:


1) Delete Pending Orders    True/False options,to activate or de-activate


and a 


2)"Value of Total Orders" filter to  Close at profit:


Condition: if total orders open are >=  “value”   -----------------------> close (and delete)
 
                 if total orders open are   <  “value”   -----------------------> don't do anything
 
 
for Total Orders I mean:  if only  OP_SELL  or  only OP_BUY or (OP_SELL + OP_BUY) are >= of “Value”  still proceed to close ( and delete if activated) otherwise if < of “Value”  don't do anything.
 

ex. : 1 lot OP_BUY + 0.8 lot OP_SELL + 2.5 lot OP_BUY = 3 orders    --------> enable to close (and delete)




This is the code actually I am using.


                                      

extern double My_Money_Profit_Target=100;     //The amount of money profit at which you want to close ALL open trades.
extern string Profit_Target= "Enter above To Close all OPEN trades when amount of profit is Reached in Account and not per OPEN trade! ";
                                         
int Slippage=5;
int i;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+


int start()
{
if (AccountProfit()>= My_Money_Profit_Target)
   {
    for(i=OrdersTotal()-1;i>=0;i--)
       {
       OrderSelect(i, SELECT_BY_POS);
       int type   = OrderType();
              
       bool result = false;
             
       switch(type)
          {
          //Close opened long positions
          case OP_BUY  : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),Slippage,Blue);
                         break;
              
          //Close opened short positions
          case OP_SELL : result = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),Slippage,Red);
      
        break;
                     
            //Close pending orders
      case OP_BUYLIMIT  :
      case OP_BUYSTOP   :
      case OP_SELLLIMIT :
      case OP_SELLSTOP  : result = OrderDelete( OrderTicket() );

              
          }
         
       if(result == false)
          {
            Sleep(0);
          } 
       }
      Print ("Account Profit Reached. All Open Trades Have Been Closed");
      return(0);
   } 
  
   Comment("Balance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(),
           "\nMy Account Profit Target: ",My_Money_Profit_Target);
  
  return(0);
}


Many many thanks for you precious time.


Greetings, Lorenzo

Reason: