Please correct this EA - page 2

 
Check that the ticket number of the market order matches either ticketb or tickets as some Brokers server issue a new ticket number when the pending order is changed into a market order.
 
adaheem:


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

Help please

Thanks

any help please !!!!
 
Does the ticket number of the market order match either ticketb or tickets? (as some Brokers server issue a new ticket number when the pending order is changed into a market order).
 
sxTed:
Does the ticket number of the market order match either ticketb or tickets? (as some Brokers server issue a new ticket number when the pending order is changed into a market order).

Hi again

The ticket number keeps the same when its triggered.

 

please try this when markets re-open, surround different data types with brackets when testing, i like your little program

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);
  }
}
 
I can not write a short program. can someone help me with this?

Thanks

 

Adaheem, i would erase all code lines where "last_bar" is mentioned, as it will delay the deletion of the pending order (which has not been triggered); also after the release of major reports or important news there is sometimes after the first pending order has been triggered a rapid retracement of the market price. Do not forget to complete coding "sl" and "tp".

extern double MAGIC = 1234;
extern double lots = 1;
extern double sl = 9;
extern double tp = 50;

int ticketb,tickets;

void start() {
  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);
  }
  if (OrdersTotal() == 2) {
    if (OrderSelect(ticketb,SELECT_BY_TICKET) && (OrderType()==0)) OrderDelete(tickets);
    if (OrderSelect(tickets,SELECT_BY_TICKET) && (OrderType()==1)) OrderDelete(ticketb);
  }
}
 
adaheem:


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

Help please

Thanks

any help please?
 

The corrected code dated 2010.10.03 01:00 works: it places a Buy stop pending order above the market and a Sell stop pending order below the market, then the price goes down (for real example) and when the price reaches the Sell stop pending order it becomes a Sell market order and the Buy stop order is deleted.

I reminded you "Do not forget to complete coding sl and tp" as your expert will not close the market order, you need to remove the expert and close the market order manually. You need to add code that only allows for one market order or only placing the pending orders once.

Reason: