CLOSE ORDER AT CANDLE CLOSE PRICE. Still learning... need help

 
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);
   }  
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.
 
Seems good 
Your code will give you what you target

---

Do u want to detect new candle? Or the previous candle close price??
If you want the preious candle close price then you should write tge number one instead of 0 for the shift
 
Mohammad Soubra:
Seems good 
Your code will give you what you target

---

Do u want to detect new candle? Or the previous candle close price??
If you want the preious candle close price then you should write tge number one instead of 0 for the shift
Once i attach the EA, any candle after that close at the stated price. I try to compile but too many error
 
Mohammad Rizal Bin Rahmat:
Once i attach the EA, any candle after that close at the stated price. I try to compile but too many error

may you please show your full code

to determine what to fix

or a screen-shot of the errors 

 
Mohammad Soubra:

may you please show your full code

to determine what to fix

or a screen-shot of the errors 

extern double Price_Target=0.0;     //The Candle Close Price at which will 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 ("All Orders Have Been Closed & Deleted");
      return(0);
   }  

   
   Comment("Balance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(),
           "\nMy Account Profit Target: ",Price_Target);
   
  return(0);
}
 

K got it. But now another problem. i tested it working just as i wanted but it deleted and close all pair. i just wanted it to close & delete at current pair which the EA is placed.

 

extern double Price_Target=0.0;     //The Price at which you want to delete & close 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 && iClose(NULL,PERIOD_M1,1)<=Price_Target && Ask <= Price_Target) || (SELL && iClose(NULL,PERIOD_M1,1)>=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 ("Price Reach!! All Orders Have Been Closed & Deleted");
      return(0);
   }  

   
   Comment("Balance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(),
           "\nMy Account Profit Target: ",Price_Target);
   
  return(0);
}
 
Mohammad Rizal Bin Rahmat:

K got it. But now another problem. i tested it working just as i wanted but it deleted and close all pair. i just wanted it to close & delete at current pair which the EA is placed.

 

extern double Price_Target=0.0;     //The Price at which you want to delete & close 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 && iClose(NULL,PERIOD_M1,1)<=Price_Target && Ask <= Price_Target) || (SELL && iClose(NULL,PERIOD_M1,1)>=Price_Target && Bid >= Price_Target))

   {
    for(i=OrdersTotal()-1;i>=0;i--)
       {
       bool xy = OrderSelect(i, SELECT_BY_POS);
       int type   = OrderType();
               
       bool result = false;
              
       switch(type)
          {

          case OP_BUYLIMIT  : result = OrderDelete( OrderTicket() );break;
          case OP_BUYSTOP   : result = OrderDelete( OrderTicket() );break;
          case OP_SELLLIMIT : result = OrderDelete( OrderTicket() );break;
          case OP_SELLSTOP  : result = OrderDelete( OrderTicket() );break;
          case OP_BUY       : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );break;
          case OP_SELL      : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
                                  
          }
          
       if(result == false)
          {
            Sleep(0);
          }  
       }
      Print ("Price Reach!! All Orders Have Been Closed & Deleted");
      return(0);
   }  

   
   Comment("Balance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(),
           "\nMy Account Profit Target: ",Price_Target);
   
  return(0);
}

 

 

Sorry for being late

 

try the above with updates

 

let me know if you need more help 

Reason: