# open just one order?? [Deleted]

helo.

in the function start() i want to open just one order but my problem is when the condition is ok my EA open a lot of order.

I will explain the condition:

if the last close order is buy=========>then place an order the type sell_stop in the open price of the last close order (in this case buy)

but just one order no much (this is problem). 17411

There are many ways of doing this, basically set a variable to true then when you want to place an order check if the variable is true, if it is place the order and set the variable to false . . . does that help ? [Deleted]
RaptorUK:
There are many ways of doing this, basically set a variable to true then when you want to place an order check if the variable is true, if it is place the order and set the variable to false . . . does that help ?

but if it s set as true and when the order is placed it take the value false.and how we know the function start() refresh in each tick so in the next it place another order.

if you can write a code to help me understand what you mean. 17411

Set the variable to true in init() not start() 25838

izmnaari:

in the function start() i want to open just one order but my problem is when the condition is ok my EA open a lot of order.

if the last close order is buy=========>then place an order the type sell_stop in the open price of the last close order (in this case buy)
```int TotalOrderCount(){
int count=0;
for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
&&  OrderMagicNumber()  == magic.number             // my magic number
&&  OrderSymbol()       == Symbol() ){              // and my pair.
count++;
}
return(count);
}
int start(){
if (TotalOrderCount() > 0) return; // Already have one open.
...```

2. Find the last closed order and get it type and price.
```bool SelectLastClosedOrder(){
datetime lastClose; int ticket = 0;
for(int pos=0; pos < OrdersHistoryTotal(); pos++) if (
OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY)   // Only orders w/
&&  OrderCloseTime()    > lastClose                 // not yet processed,
&&  OrderMagicNumber()  == magic.number             // my magic number
&&  OrderSymbol()       == Symbol()                 // and my pair.
&&  OrderType()         <= OP_SELL){// Avoid cr/bal forum.mql4.com/32363#325360
ticket = OrderTicket();
}
if (ticket == 0)    return(false)
OrderSelect(ticket, SELECT_BY_TICKET, MODE_HISTORY);
return(true);
}
int start(){
if (SelectLastClosedOrder()){
if (OrderType() == OP_BUY)  int newOP = OP_SELLSTOP;