How to select a specific order and get the order's OrderOpenPrice()??

 

Hi everybody,

my question is...how can i get the OrderOpenPrice() of a specific order?? If i send, for example, a buy order by...

if(High[1]>=Resist){

res = OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",MAGICMA,0,Green);

if(res>=1){

OrderModify(res,OrderOpenPrice(),bsl,0,0,CLR_NONE);

if(OrderSelect(res,SELECT_BY_TICKET,MODE_TRADES))

Print("Buy order opened: " + OrderOpenPrice());

else

Print("Error opening Buy Order: " + GetLastError());

}

return;}

I have tried to search between the opened order by "for cycle", but it don't work...

for(int i=OrdersTotal(); i>=0; i--){

if(OrderSelect(res,SELECT_BY_TICKET,MODE_TRADES)==true)

if(Ask-OrderOpenPrice()>TriggerLevel1){

int buiticket1=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,0,"",MAGICMA+1,0,Green);

if(buiticket1>=1)

{

OrderModify(buiticket1,OrderOpenPrice(),bsl,0,0,CLR_NONE);

if(OrderSelect(buiticket1,SELECT_BY_TICKET,MODE_TRADES))

Print("Buy order opened: " + OrderOpenPrice());

else

Print("Error opening Buy Order: " + GetLastError());

}

return; }

}

The goal is, (like turtle TS) for example, to add new position if (ex. BUY side) Ask-OrderOpenPrice()>N*ATR

Thanks in advance...

 

You have the right idea.. just select the order by the ticket number using OrderSelect() and then call the OrderOpenPrice() to get the price of the order you most recently selected.

Just save the ticket number (res) in some kind of int variable like int ticketnumber in the global area above.. as soon as your order is placed successfully say something like ticketnumber=res; to assign a value to it.

Then there is no need for a for loop. Just select the trade. OrderSelect(TicketNumber,SELECT_BY_TICKET) ..there is no need to specify MODE_TRADES... then immediately after turning the Ea's attention to this particular trade then get it's price.

Of course at the same time that you captured the ticketnumber=res; you could have also captured it's opening price with something like.... double price; in the global area then .....price=OrderOpenPrice();

Hope this gives you some ideas... PipPip... Jimdandy

 

  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Jimdandy suggests saving the ticketnumber is a global. If you close the chart, the terminal, power fails, OS crashes, you've lost it. How are you going to recover? Use a orderSelect loop no recovery required and you also find out IF the order is still open.
  3. What is the point of looping through the count of open orders and repeatedly selecting the same order by ticket.?
     for(int i=OrdersTotal(); i>=0; i--){
       if(OrderSelect(res,SELECT_BY_TICKET,MODE_TRADES)==true)