how can i get the highest after orderopenprice was opened. - page 3

 

So why are you returning the ticket number ? Read the code you are copying and pasting, understand it, learn . . .

i used it to do the following

if(OrderSelect(LastOpenTicketForBuy(), SELECT_BY_POS)==true)
{ order for buy= OrderOpenPrice();}

then if ( (( order for buy+ order for sell)/2))<MarketInfo("EURUSD",MODE_BID) )

close the position

 
Hand:


if(OrderSelect(LastOpenTicketForBuy(), SELECT_BY_POS)==true)


a little change with your permission

if(OrderSelect(LastOpenTicketForBuy(), SELECT_BY_TICKET)==true)
 

Dear qjol

thanks a lot for your real help. but still i am not sure if it will work or not ( i think my functions a little diffecult). let us see

first function :

function to get and keep the last order open price for buy only

double LastOpenForBuy(){ datetime lastTime = 0 ; int lastTicket = - 1 ; // None open. 
int magi.number= 0 ; double orderforbuy;
for ( int pos = OrdersTotal ()- 1 ; pos >= 0 ; pos--)
if ( OrderSelect (pos, SELECT_BY_POS) // Only my orders w/
&& OrderMagicNumber () == magic.number // my magic number
&& OrderSymbol () == Symbol () // and my pair.
&& OrderType ()==OP_BUY )
{ orderforbuy = OrderOpenprice ();
lastTicket = OrderTicket (); }
return (orderforbuy);}

if(OrderSelect(LastOpenForBuy(), SELECT_BY_TICKET)==true)
{ order for buy= OrderOpenPrice();}

// then something like// // if ( (( order for buy+ order for sell)/2))<MarketInfo("EURUSD",MODE_BID) )

//close the position

     what i need is:
     1- function to get and keep the last order open price for buy only 
2- function to get and keep the last order open price for sell
3- function to get and keep the last order close price whatover  buy or sell
4- function to get and keep the previous close price before the last close order whatover  buy or sell.
 

OK, try this . . .

It will do 1 & 2 . . .

LastOpenPrice(OP_BUY) for open price of last buy.

LastOpenPrice(OP_SELL) for open price of last sell.

double LastOpenPrice(int OrderType)
   { 
 
   double OpenPrice;                         

   for ( int pos = OrdersTotal()- 1 ; pos >= 0 ; pos--)
      if ( OrderSelect (pos, SELECT_BY_POS) // Only my orders w/
      && OrderMagicNumber() == magic.number // my magic number       //  <-------  what Magic Number do you use when you place a trade ?  it must match  ! !
      && OrderSymbol() == Symbol()  // and my pair.                  //            magic.number  should be a Globally defined variable that has your Magic Numer  
      && OrderType() == OrderType )
         {
         OpenPrice = OrderOpenprice();
         break;
         }
   return (OpenPrice);                                             //  <-------  this returns the Order Open Price  NOT the ticket
}
 

And this . . . .

for 3 . . .

double LastClosePrice()
   { 
 
   double ClosePrice;                         

   for ( int pos = OrdersHistoryTotal()- 1 ; pos >= 0 ; pos--)
      if ( OrderSelect (pos, SELECT_BY_POS, MODE_HISTORY)            // Only my CLOSED  orders 
      && OrderMagicNumber() == magic.number // my magic number       //  <-------  what Magic Number do you use when you place a trade ?  it must match  ! !
      && OrderSymbol() == Symbol()  // and my pair.                  //            magic.number  should be a Globally defined variable that has your Magic Numer  
      && OrderType() < OP_BUYLIMIT )
         {
         ClosePrice = OrderCloseprice();
         break;
         }
   return (ClosePrice);                                             //  <-------  this returns the Order Open Price  NOT the ticket
}
 
Not sure I understand what you mean by No. 4.
 

raptor

i think u missing something if he has more than 1 order on the same pair (& the same magic) therefore i think it's better this way

double LastOpenPrice(int OrderType)
   { 
 
   double OpenPrice;                         
   datetime lastOpen; // First line added

   for ( int pos = OrdersTotal()- 1 ; pos >= 0 ; pos--)
      if ( OrderSelect (pos, SELECT_BY_POS) // Only my orders w/
      && OrderMagicNumber() == magic.number // my magic number       //  <-------  what Magic Number do you use when you place a trade ?  it must match  ! !
      && OrderSymbol() == Symbol()  // and my pair.                  //            magic.number  should be a Globally defined variable that has your Magic Numer  
      && OrderType() == OrderType
      && OrderOpenTime() > lastOpen) // Second line added
         {
         OpenPrice = OrderOpenprice();
         break;
         }
   return (OpenPrice);                                             //  <-------  this returns the Order Open Price  NOT the ticket
}

your opinion

 
If you count down the first order that matches the Magic Number and Symbol will be the last one placed for the EA and Symbol in question, no ?
 
Not sure
 
qjol:

raptor

i think u missing something if he has more than 1 order on the same pair (& the same magic) therefore i think it's better this way

your opinion


guys,

thanks a lot,

let me tell you why i want to use LastOpenPrice(OP_BUY) and LastOpenPrice(OP_SELL) because i want to use them in some conditions like

if ( LastOpenPrice(OP_BUY) -LastOpenPrice(OP_SELL)) > 0.0090 // for that reason i need to keep the last order was open for buy and the last order was open for sell, so i need separate last order one for buy and the other for sell.

-----

for double LastClosePrice() // can i used if ( OrderType() == OP_BUY || OP_SELL) instead *** OrderType() < OP_BUYLIMIT*** to get the last close whatover buy or sell.

----

for function number 4:

4- function to get and keep the previous close price before the last close order whatover buy or sell. // i want to get the closed order before the last closed order whatover buy or sell.

thanks

Reason: