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

Back to topics list To post a new topic, please log in or register
avatar
120
DeanDeV 2015.05.25 10:42
 

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.

avatar
Moderator
3418
GumRai 2015.05.25 12:47 #
 

static int sellticket=-1;

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

  }

 You will need to reset sellticket when it is closed

 

avatar
120
DeanDeV 2015.05.25 15:56 #
 
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? 
avatar
13006
WHRoeder 2015.05.25 17:27 #
 
DeanDeV: May I inquire as to how I go about resetting it? 
  1. When in doubt, think!
  2. sellticket=-1;

Back to topics list  

To add comments, please log in or register