How can I cancel a trade when another is open and keep the open trade for a given duration? : <p>I have written the code below that opens a buy and sell trade (a certain number of pips above and below the ask and bid price) at a specific time.</p>

<ol>
<li><p>How can I close/cancel one immediately when the other is opened?</p></li>
<li><p>How can I close the opened trade if it's say X pips in profit or after a minute (depending on which condition is reached first)?</p></li>
</ol>

<p>I'm a not too sure I've done the right thing in the code below and would really appreciate some help.</p>

<pre><code>double spread = Ask-Bid;
extern datetime time;
extern int pipGap = 7;
extern int lotSize = 0.01;
extern int closeTimeInSeconds = 60;


int start() {
  if (TimeCurrent() &gt;= StrToTime(time)){

    OrderSend(Symbol(),OP_BUYSTOP,lotSize, Ask + Point*pipGap, 0,0,0);
    OrderSend(Symbol(),OP_SELLSTOP,lotSize, Bid - Point*pipGap, 0,0,0);


    }


for(int pos = OrdersTotal()-1; pos &gt;= 0 ; pos--) if (
    OrderSelect(pos, SELECT_BY_POS)           
){              
    int duration = TimeCurrent() - OrderOpenTime();
    if (duration &gt;= closeTimeInSeconds)
         OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(),
                     3*Point);
}

   return(0);
}
</code></pre>
