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

 
( OrderType() < OP_BUYLIMIT ) is the same as ( OrderType() == OP_BUY || OrderType() == OP_SELL )
 
Hand:


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.

You can do that . . it will work . . try it.
 
Or maybe you mean the last BUY order that is now closed ?
 

it the explanation for function n.4 clear?

function number 4:

// i want to get the order closed before the last closed order whatover buy or sell.

4- function to get and keep the previous close price before the last close order whatover buy or sell. thanks

 

guys,

It really does not work

// Used to keep global variables

extern int MagicNumberLong = 6658641;                     //Identifies long positions
extern int MagicNumberShort = 4167090;                    //Identifies short positions
  
 






double LastOpenPrice(int ordertype)
   { 

   double OpenPrice;                         
   datetime lastOpen;
   for ( int pos = OrdersTotal()- 1 ; pos >= 0 ; pos--)
      if ( OrderSelect (pos, SELECT_BY_POS) // Only my orders w/
      && OrderMagicNumber() == MagicNumberLong || MagicNumberShort // 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 )
         {
         OpenPrice = OrderOpenPrice();
         break;
         }
   return (OpenPrice);                                             //  <-------  this returns the Order Open Price  NOT the ticket
}

if (  ((iOpen("EURUSD",PERIOD_H1,0)-0.0030)>=MarketInfo("EURUSD",MODE_BID))   ) 
  {   BUY("EURUSD",B_EURUSD_LS_0,B_EURUSD_TP_0,B_EURUSD_SL_0,B_EURUSD_TS_0,"if (  ( ((iOpen(EURUSD,PERIOD_H1,0)-0.00...") ;}
if (  ( (LastOpenPrice(OP_BUY)-0.0030)>MarketInfo("EURUSD",MODE_BID) )  ) 
   {  SELL("EURUSD",S_EURUSD_LS_1,S_EURUSD_TP_1,S_EURUSD_SL_1,S_EURUSD_TS_1,"if (  ( (LastOpenPrice(OP_BUY)-0.0030)>=MarketInfo("EURUSD",MODE_BID) )  )") ;}
if (  ( ((iOpen("EURUSD",PERIOD_H1,0)+0.0030)<=MarketInfo("EURUSD",MODE_BID)) )  ) 
  {   SELL("EURUSD",S_EURUSD_LS_0,S_EURUSD_TP_0,S_EURUSD_SL_0,S_EURUSD_TS_0,"if (  ((iOpen(EURUSD,PERIOD_H1,0)+0.00...") ;}
if (  ( (LastOpenPrice(OP_SELL)+0.0030)<MarketInfo("EURUSD",MODE_BID) )  ) 
   {  BUY("EURUSD",B_EURUSD_LS_1,B_EURUSD_TP_1,B_EURUSD_SL_1,B_EURUSD_TS_1,"if (  ( (LastOpenPrice(OP_SELL)+0.0030)<MarketInfo("EURUSD",MODE_BID) )") ;}

As you can see in the images

i started to testing the EA from 01/03/2011 to 11/04/2011

in the first hour for 01/03/2011

the position was opened but no one from above conditions availble . that let me really crazy

 
Hand:

it the explanation for function n.4 clear?

function number 4:

// i want to get the order closed before the last closed order whatover buy or sell.

4- function to get and keep the previous close price before the last close order whatover buy or sell. thanks

Close price ? close price of the bar before the bar where the last order closed ? or the Order close price of the Buy or Sell that closed before the last one that closed ?
 

the second option:

the Order close price of the Buy or Sell that closed before the last one that closed ?

 
Hand:

the second option:

the Order close price of the Buy or Sell that closed before the last one that closed ?

Try this . . .

To get the last close price of the last order that was a Buy or a Sell and matched the Symbol and magic.number do this LastClosePrice(1)

To get the one before that do this . . . LastClosePrice(2 )

double LastClosePrice(int Order)
   { 
 
   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 )
         {
         Order--;
         if (Order == 0)                                            //  determines if we have found the Order we are interested in
            {
            ClosePrice = OrderCloseprice();
            break;
            }
         }
   return (ClosePrice);                                             //  <-------  this returns the Order Open Price  NOT the ticket
}

NOTE: this code WILL NOT WORK with your magic numbers as shown in your code above . . .

extern int MagicNumberLong = 6658641;                     //Identifies long positions
extern int MagicNumberShort = 4167090; 


WHY ? ? ? ?
 

Guys.

Is there anybody can used teamviewer program then we will access togethor and checking what is the real issue.

 
Hand:

guys,

It really does not work

As you can see in the images

i started to testing the EA from 01/03/2011 to 11/04/2011

in the first hour for 01/03/2011

the position was opened but no one from above conditions availble . that let me really crazy

It is not crazy. It is "reasonable" for an order to be opened because:

double LastOpenPrice(int ordertype)
   { 

   double OpenPrice;                         
   datetime lastOpen;
   for ( int pos = OrdersTotal()- 1 ; pos >= 0 ; pos--)
      if ( OrderSelect (pos, SELECT_BY_POS) // Only my orders w/
      && OrderMagicNumber() == MagicNumberLong || MagicNumberShort // my magic number       
      && OrderSymbol() == Symbol()    // and my pair.             
      && OrderType() == ordertype 
      && OrderOpenTime() > lastOpen )
         {
         OpenPrice = OrderOpenPrice();
         break;
         }
   return (OpenPrice); //  <-------  this returns the Order Open Price OR ZERO.

If the above function returns ZERO, then any scenario such as the one below may occur

 if (  ( (LastOpenPrice(OP_SELL)+0.0030)<MarketInfo("EURUSD",MODE_BID) )  ) <--------------- 0+0.0030=0.0030<Bid: TRUE
   {  BUY("EURUSD",B_EURUSD_LS_1,B_EURUSD_TP_1,B_EURUSD_SL_1,B_EURUSD_TS_1,"if (

I suggest you place a "master" logic, over and above this. If function LastOpenPrice(...) returns zero....what is your game plan?

Reason: