How to get last close price

 
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();
    }
 

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();
    }

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);
 
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();
    }
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it
  2. 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).
  3. 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
  4. 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
Reason: