You also need to look at
OrderCloseTime()
To find out which one was closed last and from there on you can get to the ClosePrice.
Tony Chavez:
Anyone have any insight on getting the close price of the last order?
I tried:
if(OrderSelect(OrdersHistoryTotal(),SELECT_BY_POS,MODE_HISTORY)==true)
{
double LastOrderClosePrice = OrderClosePrice();
}
Anyone have any insight on getting the close price of the last order?
I tried:
if(OrderSelect(OrdersHistoryTotal(),SELECT_BY_POS,MODE_HISTORY)==true)
{
double LastOrderClosePrice = OrderClosePrice();
}
Try:
datetime last_close = 0;
double close_price = 0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;
if(OrderSymbol() != _Symbol) continue;
// if(OrderMagicNumber() != magic_no) continue;
datetime close_time = OrderCloseTime();
if(close_time > last_close)
{
last_close = close_time;
close_price = OrderClosePrice();
}
}
printf("Last order was closed at %s for %f",TimeToStr(last_close),close_price);
double close_price = 0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;
if(OrderSymbol() != _Symbol) continue;
// if(OrderMagicNumber() != magic_no) continue;
datetime close_time = OrderCloseTime();
if(close_time > last_close)
{
last_close = close_time;
close_price = OrderClosePrice();
}
}
printf("Last order was closed at %s for %f",TimeToStr(last_close),close_price);
if(OrderSelect(OrdersHistoryTotal(),SELECT_BY_POS,MODE_HISTORY)==true)
{
double LastOrderClosePrice = OrderClosePrice();
}
{
double LastOrderClosePrice = OrderClosePrice();
}
-
Play videoPlease edit your post.
For large amounts of code, attach it - You would never write if( (2+2 == 4) == true) would
you? if(2+2 == 4) is sufficient. So Don't write if(bool == true),
just use if(bool) or if(!bool).
- In history there are OrdersHistoryTotal() entries. They are numbered zero to OrdersHistoryTotal() - 1. Therefor your select will never be true. You would know that has you bothered to check your return codes
What are Function
return values ? How do I use them ? - MQL4 forum and Common Errors
in MQL4 Programs and How to Avoid Them - MQL4 Articles
- You assume history is ordered by date, it's not. #2 Showed you how to find the latest one for the current symbol. See also Could EA Really Live By Order_History Alone? (ubzen) - MQL4 forum
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I tried:
if(OrderSelect(OrdersHistoryTotal(),SELECT_BY_POS,MODE_HISTORY)==true)
{
double LastOrderClosePrice = OrderClosePrice();
}