Select open order with the lowest OderOpenPrice

 

Guys, so far, i want to say thank you for all your help in the past. I already published in "Code Base" my first EA but currently working on two other with much better performance..


Ive been working very hard on this for the past two months and think i need a brake now, lol..


I would also need a small help.

I have multiple OP_BUY positions and need to select on the one with the lowest OrderOpenPrice().


Would be anyone so kind and help me with the code for it? I know how to go trough all open positions but not sure how to select the one with the lowest open price.


Thank you in advance.

 

Hi jirimac

I haven't done this before but when you are scanning through the orders you could save the order and open price using OrderOpenPrice()

then compare it with the next one and just hold the lowest value trade if you get my drift.


 
jirimac:

Guys, so far, i want to say thank you for all your help in the past. I already published in "Code Base" my first EA but currently working on two other with much better performance..


Ive been working very hard on this for the past two months and think i need a brake now, lol..


I would also need a small help.

I have multiple OP_BUY positions and need to select on the one with the lowest OrderOpenPrice().


Would be anyone so kind and help me with the code for it? I know how to go trough all open positions but not sure how to select the one with the lowest open price.


Thank you in advance.

double LowestOpenPrice = 99.9999;

int LowestOrderTicket;

int iOrders = OrdersTotal()-1;

for (i = iOrders; i>=0; i--)

{

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if (OrderOpenPrice() < LowestOpenPrice)

{

LowestOpenPrice = OrderOpenPrice();

LowestOrderTicket = OrderTicket();

}

}

Print("Order with lowest open price is order number ",LowestOrderTicket," with an open price of ",LowestOpenPrice);


CB


 
Awesome!! You guys rock!! Works like a charm :)