Download MetaTrader 5

Hi... i'm trying to edit/recreate and EA.. but looks like alot of error.. still learning.. help needed

To add comments, please log in or register
Examine the Top MetaTrader 5 signals. Choose the best one and subscribe to it!
Mohammad Rizal Bin Rahmat
284
Mohammad Rizal Bin Rahmat 2016.06.24 06:07 
extern double Price_Target=0.0;     //The Price at which you want to CLOSE & DELETE all Orders.
extern string Profit_Target= "ENTER ABOVE THE PRICE YOU TARGET";
extern bool SELL = false;                                    
extern bool BUY = false; 
                                          
double vbid= MarketInfo(Symbol(),MODE_BID);
double vask= MarketInfo(Symbol(),MODE_ASK);
                                             
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((BUY==true)(iClose(Symbol(),0,0)<=Price_Target && Ask <= Price_Target) || 
   if(SELL==true)(iClose(Symbol(),0,0)>=Price_Target && Bid >= Price_Target))
   {
    for(i=OrdersTotal()-1;i>=0;i--)
       {
       OrderSelect(i, SELECT_BY_POS);
       int type   = OrderType();
               
       bool result = false;
              
       switch(type)
          {

          case OP_BUYLIMIT  : result = OrderDelete( OrderTicket() );
          case OP_BUYSTOP   : result = OrderDelete( OrderTicket() );
          case OP_SELLLIMIT : result = OrderDelete( OrderTicket() );
          case OP_SELLSTOP  : result = OrderDelete( OrderTicket() );
          case OP_BUY       : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );      
          case OP_SELL      : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
                                  
          }
          
       if(result == false)
          {
            Sleep(0);
          }  
       }
      Print ("Account Price Reached. All Pending Order Have Been Deleted");
      return(0);
   }  

   
   Comment("Balance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(),
           "\nMy Account Profit Target: ",Price_Target);
   
  return(0);
}
Need your guidance... been searching for the code of Candle Close Price. but all i could find is iClose. Unknown if it's correct. 
Here's what i'm trying to do, 
If BUY is true, when anytime a Candle close Ask Price is above or equal to "Price Target", it will close and delete all orders
If SELL is true, when anytime a Candle Close Bid Price is below or equal to "Price Target", it will close and delete all orders.

Once a Candle Bar Close Price reach after the EA have been attach. Not the previous Candle Bar Close Price.
Ernst Van Der Merwe
4727
Ernst Van Der Merwe 2016.06.24 09:32  

Something like this.

extern double Price_Target=0.0;     //The Price at which you want to CLOSE & DELETE all Orders.
extern string Profit_Target= "ENTER ABOVE THE PRICE YOU TARGET";
extern bool SELL = false;                                    
extern bool BUY = false; 
extern int Slippage=5;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---- 
   Slippage*=10;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   Comment("");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   double vBid= MarketInfo(Symbol(),MODE_BID);
   double vAsk= MarketInfo(Symbol(),MODE_ASK);
                                             
   if((BUY && vAsk >= Price_Target) || 
     (SELL && vBid <= Price_Target))
      {
       for(int i=OrdersTotal()-1;i>=0;i--)
         {
          if(!OrderSelect(i, SELECT_BY_POS))
            continue;
          int type   = OrderType();
                  
          bool result = false;
                 
          switch(type)
             {
   
             case OP_BUYLIMIT  : result = OrderDelete( OrderTicket() ); continue;
             case OP_BUYSTOP   : result = OrderDelete( OrderTicket() ); continue;
             case OP_SELLLIMIT : result = OrderDelete( OrderTicket() ); continue;
             case OP_SELLSTOP  : result = OrderDelete( OrderTicket() ); continue;
             case OP_BUY       : result = OrderClose( OrderTicket(), OrderLots(), vBid, Slippage, clrRed ); continue;      
             case OP_SELL      : result = OrderClose( OrderTicket(), OrderLots(), vAsk, Slippage, clrRed );
                                     
             }
             
          if(result == false)
             {
               Sleep(500);
             }  
          }
         Print ("Account Price Reached. All Pending Order Have Been Deleted");
         return(0);
      }  

   
   Comment("Balance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(),
           "\nMy Account Profit Target: ",Price_Target);
   
  return(0);
 }
Ernst Van Der Merwe
4727
Ernst Van Der Merwe 2016.06.24 15:28  

If you want candle close either use previous bar close or current open.

   double vBid= MarketInfo(Symbol(),MODE_BID);
   double vAsk= MarketInfo(Symbol(),MODE_ASK);
   double spread = vAsk-vBid;
                                             
   if((BUY && iClose(Symbol(),0,1)+spread >= Price_Target) || 
     (SELL && iClose(Symbol(),0,1) <= Price_Target))
      {
To add comments, please log in or register