Download MetaTrader 5
To add comments, please log in or register
Deposit to your account via PayPal
DeanDeV
330
DeanDeV 2015.05.25 08: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.

Keith Watford
Moderator
8017
Keith Watford 2015.05.25 10:47  
static int sellticket=-1;

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

  }

 You will need to reset sellticket when it is closed

DeanDeV
330
DeanDeV 2015.05.25 13: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? 
whroeder1
13656
whroeder1 2015.05.25 15:27  
DeanDeV: May I inquire as to how I go about resetting it? 
  1. When in doubt, think!
  2. sellticket=-1;
/
To add comments, please log in or register