Download MetaTrader 5

I know there is errors here... i need help... it won't trigger

To add comments, please log in or register
Millions of traders download codes from MQL5 library. Share your app with them!
Mohammad Rizal Bin Rahmat
284
Mohammad Rizal Bin Rahmat 2016.06.13 03:12 

Hi, i'm trying to recreate a EA to delete pending order when it hit the price i input. But kept having error. tried to google up, but not able to. Or maybe the code i do is wrong? anyone could help please? thanks

 

extern double Price_Target=0.0;     //The Price at which you want to delete all Pending Orders.
extern string Profit_Target= "ENTER ABOVE THE PRICE YOU TARGET";
                                          
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 (vask()= Price_Target)
  if else (vbid()= Price_Target)
   {
    for(i=OrdersTotal()-1;i>=0;i--)
       {
       OrderSelect(i, SELECT_BY_POS);
       int type   = OrderType();
               
       bool result = false;
              
       switch(type)
          {

            //Close pending orders
          case OP_BUYLIMIT  : result = OrderDelete( OrderTicket() );
          case OP_BUYSTOP   : result = OrderDelete( OrderTicket() );
          case OP_SELLLIMIT : result = OrderDelete( OrderTicket() );
          case OP_SELLSTOP  : result = OrderDelete( OrderTicket() );
                                  
          }
          {
if (Bid()= Price_Target)
   {
    for(i=OrdersTotal()-1;i>=0;i--)
       {
       OrderSelect(i, SELECT_BY_POS);
       int type   = OrderType();
               
       bool result = false;
              
       switch(type)
          {

            //Close pending orders
          case OP_BUYLIMIT  : result = OrderDelete( OrderTicket() );
          case OP_BUYSTOP   : result = OrderDelete( OrderTicket() );
          case OP_SELLLIMIT : result = OrderDelete( OrderTicket() );
          case OP_SELLSTOP  : result = OrderDelete( OrderTicket() );
                                  
          }
          
       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);
}
Kaleem Haider
73706
Kaleem Haider 2016.06.13 05:05  
Mohammad Rizal Bin Rahmat:

Hi, i'm trying to recreate a EA to delete pending order when it hit the price i input. But kept having error. tried to google up, but not able to. Or maybe the code i do is wrong? anyone could help please? thanks

 

Check you if statements, it should be "==" not "=".  Declare vask and vbid within start statement and remove ().  
Lazar Buga
6158
Lazar Buga 2016.06.13 11:59  
Your error was   '{' - unbalanced parentheses.
That mean if you have opened  parentheses  '{', then it must be always closed '}'
And maybe some other little mistakes.
Try this:
int start()
  {
   if(Ask==Price_Target || Bid==Price_Target)
      {
        for(int i=OrdersTotal()-1;i>=0;i--)
           {
             if(!OrderSelect(i, SELECT_BY_POS)) continue;         
             //---    
             bool result = false;     
             if(OrderType()>1 && OrderSymbol()==Symbol()) result = OrderDelete( OrderTicket() ); 
             //---
             if(!result) Sleep(0);
           }
        Print ("Account Price Reached. All Pending Order Have Been Deleted");   
      } 
   
   Comment("Balance: ",AccountBalance(),", Account Equity: ",AccountEquity(),", Account Profit: ",AccountProfit(),
           "\nMy Account Profit Target: ",Price_Target);   
 
   return(0);
  }
Lazar Buga
6158
Lazar Buga 2016.06.13 12:31  
But in this case it also probably will not ever trigger. Because Ask can jump over Price_Target and never will equal to it.
So you must to check in such way:

if((iOpen(NULL,PERIOD_M1,0)<=Price_Target && Ask >= Price_Target)
|| (iOpen(NULL,PERIOD_M1,0)>=Price_Target && Bid <= Price_Target)) 
   {
      .... delete pending
   } 
Mohammad Rizal Bin Rahmat
284
Mohammad Rizal Bin Rahmat 2016.06.13 22:32  
Lazar Buga:
But in this case it also probably will not ever trigger. Because Ask can jump over Price_Target and never will equal to it.
So you must to check in such way:

Hi Lazar,

Thank you for guiding. Ok i understand about the need to have "<" or ">". Will try it out...

Is this part still ok or it is wrong too?
double vbid= MarketInfo("Symbol",MODE_BID);
double vask= MarketInfo("Symbol",MODE_ASK);
Lazar Buga
6158
Lazar Buga 2016.06.14 16:16  
Mohammad Rizal Bin Rahmat:

Is this part still ok or it is wrong too?
You can always check anything you need.

Just make data visible for you.

For example you can use Print();

int OnInit()
  {
//---
   Print("Correct = "+ MarketInfo(Symbol(),MODE_BID));
   Print("Wrong = "  + MarketInfo("Symbol",MODE_BID));
//---
   return(INIT_SUCCEEDED);
  }    
Then go to the 'Experts' and check it.
You will see:
http://prntscr.com/bg9qtl
To add comments, please log in or register