Selecting an order and then using OrderSend() based on it

 

Hi,

I seem to be having a problem. I want to select an order and then when that order is in a certain amount of profit I want to send another order. Below is my code. When it reaches the certain amount in profit it places continuously as it oscillates around the profit point at which I want it to send the order. I just want it to send one order.

//Global variables

int ticketnumber1;

//Start()

if(Hour()==X && Minute()==Y)            //Specific time for pending/limit order placement 
  {
   if (Bars!=ThisBarTrade)       //One trade per bar
    {
     ThisBarTrade=Bars; 

    buyticket=OrderSend(Symbol(),OP_BUYSTOP,Lotsize,PendingPrice,3,Stoploss,TakeProfit,"Buy Stop Order",MagicNumber,0,clrBlue);
     ticketnumber1=buyticket;
      if(buyticket>0)Print("Order Send success, Buy Stop Order placed");
       if(buyticket<0) Print("Buy Stop Order Send failed, error # ",GetLastError());
     }
  }

if(OrderSelect(ticketnumber1,SELECT_BY_TICKET))
  {
   if(Ask-OrderOpenPrice()>Profitpoint*Point)
    sellticket=OrderSend(Symbol(),OP_SELLSTOP,Lotsize,PendingPrice,3,Stoploss,Takeprofit,"Sell stop order",MagicNumber,0,clrRed);
      if(sellticket<0) Print("Sell order failed," , GetLastError());
  }

 If I create a for() it places 999 orders at that point.

 
static int sellticket=-1;

if(sellticket<0 && OrderSelect(ticketnumber1,SELECT_BY_TICKET))
  {

  }

 You will need to reset sellticket when it is closed

 
GumRai:

 You will need to reset sellticket when it is closed

 

Thanks for the response. May I inquire as to how I go about resetting it? 
 
DeanDeV: May I inquire as to how I go about resetting it? 
  1. When in doubt, think!
  2. sellticket=-1;
Reason: