How do i ge the OrderOpenprice ()

 

Hi

How do i get the OrderOpenprice (), when backtesting.


I have tried with this

double open = OrderOpenPrice();


And it gives me right price sometimes but not always?

 
pontuso:

Hi

How do i get the OrderOpenprice (), when backtesting.

I have tried with this

And it gives me right price sometimes but not always?

Did you read the OrderOpenPrice() documentation ? where it says . . . "Order must be first selected by the OrderSelect() function." ?
 

No i did not, will check that out and try again.

 

Hi again

This is working correct in backtester and giving me the right results.! =)

Just wanna check with you that this is the proper way of writing it

OrderSelect(0,SELECT_BY_POS,MODE_TRADES);

double open = OrderOpenPrice(); 

 
  1. What are Function return values ? How do I use them ? - MQL4 forum (what if there is no open order?)
  2. Do a orderSelect loop (what if order position zero is from another chart?)
  3. Filter by magic number (what if order is from another EA or manual trading)
  4. Do it right



 

I think i got it now.

{   
for(int op=0; op<OrdersTotal();op++)                                                 // Loop through orders
if(OrderSelect(op,SELECT_BY_POS,MODE_TRADES)==true && OrderMagicNumber()==Magic)     // Select the correct order from my magic number

double openprice = OrderOpenPrice();                                                 // Gives me the OrderOpenPrice value on this EA:s last open order
}
Reason: