Download MetaTrader 5

It won't work... newbie still learning.. anyone can help if i coded it wrongly? Thank You

To add comments, please log in or register
Mohammad Rizal Bin Rahmat
284
Mohammad Rizal Bin Rahmat 2016.06.13 02:34 

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  on the exact word that i should use" (???=My_Price_Target), 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);

Irwan Adnan
925
Irwan Adnan 2016.06.13 04:55  
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  on the exact word that i should use" (???=My_Price_Target), but not able to. Or maybe the code i do is wrong? anyone could help please? thanks


What is the errors?
Osama Shaban
1464
Osama Shaban 2016.06.13 06:02  

Brother Mohammad ...

The code is full of errors ... Some are in the functions syntax and some in the logic itself ...

For example ...

--- if (Bid()= Price_Target) should be if (Bid >= Price_Target) or if (Bid <= Price_Target) 

it depends on where is the price should be (above or bellow) Price_Target ... using < or > is a must to prevent price tick jump or gaps.

 

--- Why using ( ) for both Ask and Bid ? 

 

--- Why not use  vbid= MarketInfo(Symbol(),MODE_BID) instead of vbid= MarketInfo("Symbol",MODE_BID)

the same for vask 

 

--- add "}" to the end of code.

--- I didn't reviewed the whole logic of the code.

 

If you tell the needed logic in details, I can help you with full code.

 

Regards ... 

Mohammad Rizal Bin Rahmat
284
Mohammad Rizal Bin Rahmat 2016.06.13 22:29  
Osama Shaban:

Brother Mohammad ...

The code is full of errors ... Some are in the functions syntax and some in the logic itself ...

For example ...

--- if (Bid()= Price_Target) should be if (Bid >= Price_Target) or if (Bid <= Price_Target) 

it depends on where is the price should be (above or bellow) Price_Target ... using < or > is a must to prevent price tick jump or gaps.

 

--- Why using ( ) for both Ask and Bid ? 

 

--- Why not use  vbid= MarketInfo(Symbol(),MODE_BID) instead of vbid= MarketInfo("Symbol",MODE_BID)

the same for vask 

 

--- add "}" to the end of code.

--- I didn't reviewed the whole logic of the code.

 

If you tell the needed logic in details, I can help you with full code.

 

Regards ... 

Hi Brother Osama,

Thank you for your time to teach me. Actually i'm trying to code a EA when it hit a X price which i set on my own, it will delete all the pending orders.
To add comments, please log in or register