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 your precious time.


Greetings, Lorenzo
 
lorenzo9530: but I would like to add
You haven't stated a problem.  You have only four choices:
  1. Search for it,
  2. learn to code it. If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours.
  3. Beg at Coding help - MQL4 and MetaTrader 4 - MQL4 programming forum or Need help with coding - General - MQL5 programming forum or Free MQL4 To MQL5 Converter - General - MQL5 programming forum or Requests & Ideas (MQL5 only!),
  4. or pay (Freelance) someone to code it.
We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using CODE button) and state the nature of your problem.
          No free help
          urgent help.
Reason: