Download MetaTrader 5

Please help with OrderOpenPrice()

To add comments, please log in or register
Find out the most discussed Forum topics. Have a look at the Wall section!
494854
132
494854 2014.01.23 17:38 

Please, your help, I need to get the OrderOpenPrice() from the first order ( from the openbuy() funtion ) into the third order ( to the openbuystop function ) and the testing is stopping at the third order, it seems not taking the OrderOpenPrice from the firts order. I thank you any help.

void openbuy()
{
OrderSend(Symbol(), OP_BUY, 0.12, Ask, slippage, Ask-stoploss*Point-HedgeGrid*Point-0.00025, Ask+takeprofit*Point,"Buy Trade", magic1,0, Blue);
}
///---------------------------------------------------------------------------------------------------
void opensellstop()
{
   int    ticket,expiration;
   double point;
//----
   point=MarketInfo(Symbol(),MODE_POINT);
   expiration=NULL;
   double price = Bid-HedgeGrid*point;   //    CAMBIE  A 50  POR  HedgeGrid
//----
while(true)               //  
     {
      ticket=OrderSend(Symbol(),OP_SELLSTOP,0.35,price,0,price+stoploss*Point+HedgeGrid*Point+0.00025,price-takeprofit*Point,"SellStop",magic1,expiration,Green);
      if(ticket<=0) Print("Error = ",GetLastError());
      else { Print("ticket = ",ticket); break; }
      //---- 10 seconds wait
      Sleep(0);
     }
}

////  --------------------------------------------------------------------------------------------

void openbuystop()
{
   int    ticket,expiration;
   double point;

//----

point=MarketInfo(Symbol(),MODE_POINT);
int x = OrdersTotal()-1;
OrderSelect(x, SELECT_BY_POS, MODE_TRADES);
double price =  OrderOpenPrice();
   
//----

   while(true)               
     {
      ticket=OrderSend(Symbol(),OP_BUYSTOP,0.72,price,0,price-stoploss*Point-HedgeGrid*Point-0.00025,price+takeprofit*Point,"buystop",magic1,expiration,Green);
      if(ticket<=0) Print("Error = ",GetLastError());
      else { Print("ticket = ",ticket); break; }
      //---- 10 seconds wait
      Sleep(0);
     }
}
Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.01.23 17:42  
goncalo:

Please, your help, I need to get the OrderOpenPrice() from the first order ( from the openbuy() funtion ) into the third order ( to the openbuystop function ) and the testing is stopping at the third order, it seems not taking the OrderOpenPrice from the firts order. I thank you any help.

You need to make sure you are selecting the correct Order . . . how can you identify the correct order ?
494854
132
494854 2014.01.23 17:46  
RaptorUK:
You need to make sure you are selecting the correct Order . . . how can you identify the correct order ?

Hi Raptor, trying to select it with:

int x = OrdersTotal()-1;
OrderSelect(x, SELECT_BY_POS, MODE_TRADES);
494854
132
494854 2014.01.23 17:56  

but, when testing, the EA stops running when it is suposed to open the third trade with the buystop function.

Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.01.23 18:04  
goncalo:

Hi Raptor, trying to select it with:

But is that the correct Order ? how do you know it is ? how can you verify it is the correct Order in the code ?
Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.01.23 18:05  
goncalo:

but, when testing, the EA stops running when it is suposed to open the third trade with the buystop function.

Why ? what have you verified and tested ? have you printed the relevant variables to make sure everything is correct ?
494854
132
494854 2014.01.23 18:12  
RaptorUK:
But is that the correct Order ? how do you know it is ? how can you verify it is the correct Order in the code ?

by defining the x variable, I think I can get the order selection, or is there another way to ensure that the ORDEROPENPRICE that I need, be choosen ????? I really dont know how to get it.
Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.01.23 18:16  
goncalo:

Please do not reply by writing in the quote box . . .


Can you guarantee that the Order in the last position is the one you need ? if you can't then you need to make sure you have selected the correct one, test by Type, position size, symbol, Magic Number, OrderOpenTime() or whatever you can use to confirm it's the right one . . .
To add comments, please log in or register