Please correct this EA

 

Dear all

I am a newbie to write EAs. so i am trying to write an EA which can open 2 pending orders. when i order is triggered, the pending order must be deleted.

i searched for an ideas and this is what i got.

The pending orders which are created, are deleted immediately without being triggered.

any help please and Thanks in advanced.

extern double MAGIC = 1234;

extern double lots = 1;

extern double sl = 9;

extern double tp = 50;



int ticket;

int last_bar = 0;


int start(){

if (last_bar == Bars) return(0);

last_bar = Bars;

if (OrdersTotal() == 0){

ticket=OrderSend(Symbol(),OP_BUYSTOP,lots, Ask+5*Point,3,0,0,"test",MAGIC,0,Green);

ticket=OrderSend(Symbol(),OP_SELLSTOP,lots, Bid-5*Point,3,0,0,"test",MAGIC,0,Red);


bool found = false;

for(int k=OrdersHistoryTotal()-1;k>=0;k--)

{

if((OrderSelect(k,SELECT_BY_POS,MODE_HISTORY))&&(OrderMagicNumber()==MAGIC))

{

found = true;

break;

}

}

if(found)

{

for(k=OrdersTotal()-1;k>=0;k--)

{

if((OrderSelect(k,SELECT_BY_POS,MODE_TRADES))&&(OrderMagicNumber()==MAGIC))

{

OrderDelete(OrderTicket());

}

}

}

}

}

 

As a variant

extern double MAGIC = 1234;

extern double lots = 1;

extern double sl = 9; 

extern double tp = 50; 




int ticketb,tickets;

int last_bar = 0;


int start(){

if (last_bar == Bars) return(0);

last_bar = Bars;

if (OrdersTotal() == 0){

ticketb=OrderSend(Symbol(),OP_BUYSTOP,lots, Ask+5*Point,3,0,0,"test",MAGIC,0,Green);
RefreshRates();

tickets=OrderSend(Symbol(),OP_SELLSTOP,lots, Bid-5*Point,3,0,0,"test",MAGIC,0,Red);
return(0);

}
if(OrdersTotal()==2)
{
if(OrderSelect(ticketb,SELECT_BY TICKET)&&OrderType==0)OrderDelete(tickets);
if(OrderSelect(tickets,SELECT_BY TICKET)&&OrderType==1)OrderDelete(ticketb);
}
}

 

Hi Roger

Thanks for your help but it is giving me errors when compiling the "SELECT_BY" & "TICKET" are variables are not defined . can you please correct it?

Thanks again and soooooooooooooooo much

 
adaheem:

Hi Roger

Thanks for your help but it is giving me errors when compiling the "SELECT_BY" & "TICKET" are variables are not defined . can you please correct it?

Thanks again and soooooooooooooooo much


if(OrderSelect(ticketb,SELECT_BY_TICKET)&&OrderType==0)OrderDelete(tickets);
if(OrderSelect(tickets,SELECT_BY_TICKET)&&OrderType==1)OrderDelete(ticketb);
 

Hi

its still giving a different error now.

extern double MAGIC = 1234;

extern double lots = 1;

extern double sl = 9;

extern double tp = 50;



int ticketb,tickets;

int last_bar = 0;


int start(){


if (last_bar == Bars) return(0);


last_bar = Bars;


if (OrdersTotal() == 0){


ticketb=OrderSend(Symbol(),OP_BUYSTOP,lots, Ask+5*Point,3,0,0,"test",MAGIC,0,Green);

RefreshRates();


tickets=OrderSend(Symbol(),OP_SELLSTOP,lots, Bid-5*Point,3,0,0,"test",MAGIC,0,Red);

return(0);


{

if(OrdersTotal()==2)


if(OrderSelect(ticketb,SELECT_BY_TICKET)&&OrderType==0) OrderDelete(tickets);

if(OrderSelect(tickets,SELECT_BY_TICKET)&&OrderType==1) OrderDelete(ticketb);

}

Files:
sss.mq4  1 kb
 

Check brackets !!!

 
Roger:

Check brackets !!!


dear all friends

i couldn't have it to work yet whenever i try to fix it by the brackets, i get more errors .

please help.

Thanks in advanced

 
adaheem:

i couldn't have it to work yet whenever i try to fix it by the brackets, i get more errors .

You are missing 2 closing brackets ('}') at the end of the program. OrderType() is a function, so it must have the '()' at the end. This should make it compile, although there are many other problems with this code...



 
gordon:

You are missing 2 closing brackets ('}') at the end of the program. OrderType() is a function, so it must have the '()' at the end. This should make it compile, although there are many other problems with this code...




Hi again

i made the brackets and it went good, but now its asking for an '\end of program: unbalanced left parenthesis '

{

if(OrdersTotal()==2)


if (OrderSelect(ticketb,SELECT_BY_TICKET)&&OrderType()==0 OrderDelete(tickets);

if (OrderSelect(tickets,SELECT_BY_TICKET)&&OrderType()==1 OrderDelete(ticketb);

}

}

}

what is missing?

10x again

 
adaheem:


i made the brackets and it went good, but now its asking for an '\end of program: unbalanced left parenthesis '

When in doubt, THINK
if (OrderSelect(ticketb,SELECT_BY_TICKET)&&OrderType()==0 OrderDelete(tickets);
   1           2                        2                ? 
 
WHRoeder:
When in doubt, THINK


Hi now its compiling without errors but its not deleting the 2nd pending order after the first has been triggered.

Help please

Thanks

Reason: