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

 
Start learning to code and stop bumping your thread.
 

Just i need a little help then everything will be ok.( I need to know the lastest order for buy, the lastest order for sell and the previous order for whatever buy or sell )

many thanks for you.

int LastOpenTicketForBuy(){
    datetime lastTime  = 0;
    int      lastTicket = -1; // None open.
    int magi.number=0;
    //for(int pos=0; pos<OrdersTotal(); i++) {
      OrderSelect(pos, SELECT_BY_POS);
    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.
    &&  OrderOpenTime()     >  lastTime
    && OrderType()==OP_BUY
    ){
      lastTime   = OrderOpenTime();
      lastTicket = OrderTicket();
    }
    return(lastTicket);
}

int LastOpenTicketForSell(){
    datetime lastTime  = 0;
    int      lastTicket = -1; // None open.
    int magi.number=0;
    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.
    &&  OrderOpenTime()     >  lastTime
    && OrderType()==OP_SELL
    ){
      lastTime   = OrderOpenTime();
      lastTicket = OrderTicket();
    }
    return(lastTicket);
}

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

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

guys,

would you have a look and tell me what is the wrong.


i need create some functions for:
1- function to get and keep the last order open price for buy.
2- function to get and keep the last order open price for sell.
3- function to get and keep the last close order whatover buy or sell

int LastOpenTicketForBuy(){ datetime lastTime = 0 ; int lastTicket = - 1 ; // None open. 
int magi.number= 0 ;
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 )
{ lastTime = OrderOpenTime ();
lastTicket = OrderTicket (); }
return (lastTicket);}

int LastOpenTicketForSell()
{ datetime lastTime = 0 ; int lastTicket = - 1 ; // None open.

int magi.number= 0 ;
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_SELL )
{ lastTime = OrderOpenTime (); 

lastTicket = OrderTicket (); }
return (lastTicket);}

int lastcloseorder()
{ datetime lastTime = 0 ; int lastTicket = - 1 ; // None open. 
int magi.number= 0 ; 
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.
&& OrderCloseTime () > lastTime
&& OrderType ()==OP_BUY||OP_SELL )
{ lastTime = OrderCloseTime (); lastTicket = OrderTicket (); }
return (lastTicket);}




then i will put if ((LastOpenTicketForBuy()+LastOpenTi cketForSell())/2)<MarketInfo("EURUSD",MODE_BID)Clo se t he position

 
In your opinion . . what does return(lastTicket); do ?
 

Do you mean i should

1- put double LastOpenForBuy() instead int

2-put double orderforbuy then return( orderforbuy )

by this way i can got last order opened 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);}

 
Hand:

Do you mean i should

It's a question . . . I don't mean anything other than . . . what is your answer ?

If you want me to help, you need to answer my question . . . and "I do not know" is not an acceptable answer. Think about it a little.

 

In your opinion . . what does return(lastTicket); do ?

Returns ticket number for the currently selected order.

 
Hand:

Thanks WHRoeder,

For your real help. if i need to get the last order for buy and the last order for sell then compare them by doing :

if ( the last orderopenforbuy == OOTlastest )

{ do something }

else

{ } ....... is the below code will work.

does this really work???

first loop

for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if (

goes into second

 for(pos--; pos >= 0 ; pos--) if (

pos decremental down to zero. second loop ends --> jumps back to first, and first loop does not know where pos had left since the last time. chances are, pos = zero.

 

this code may possibly work... just need to change one 1 thing:

the second for statement

for(pos--; pos >= 0 ; pos--) if (

to a different iterator like

for(int a=pos--; a>=0 ; a--) if(// abort the use of pos again and introduce a new iterator, a

and likewise, replace pos to the new iterator (in this case, a) in all of second loop logic ONLY.

 
Hand:

In your opinion . . what does return(lastTicket); do ?

Returns ticket number for the currently selected order.

You said . . .

"i need create some functions for:
1- function to get and keep the last order open price for buy.
2- function to get and keep the last order open price for sell.

3- function to get and keep the last close order whatover buy or sell "

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