[Solved] Trying to select the last closed order

 
Original code (it returns the first closed order from History):
for(int i=OrdersHistoryTotal(); i>=0; i--){if(OrderSelect(i-1 ,SELECT_BY_POS,MODE_HISTORY && OrderSymbol()==Symbol()){double LastTradeClose=OrderClosePrice();}}
The right one:
for(int  i=0; i<OrdersHistoryTotal(); i++){if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY && OrderSymbol()==Symbol()){double LastTradeClose=OrderClosePrice();}}
 
ElGaviero: the following loop returns me the first one from History! What am I doing wrong?
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum 2019.05.06
              Messages Editor

  2. if(OrderSymbol()==Symbol() && OrderSelect(i, SELECT_BY_POS,MODE_HISTORY

    You can not use any Trade Functions until you first select an order.

  3. The loop returns each entry matching symbol — resulting in the first after loop exits. Why does that surprise you?

    1. Do not assume history has only closed orders.
                OrderType() == 6, 7 in the history pool? - MQL4 programming forum 2017.11.30

    2. Do not assume history is ordered by date, it's not.
                Could EA Really Live By Order_History Alone? (ubzen) - MQL4 programming forum 2012.04.21
                Taking the last profit and storing it in a variable | MQL4 - MQL4 programming forum #3 2020.06.08

    3. Total Profit is OrderProfit() + OrderSwap() + OrderCommission(). Some brokers don't use the Commission/Swap fields. Instead, they add balance entries. (Maybe related to Government required accounting/tax laws.)
                "balance" orders in account history - Day Trading Techniques - MQL4 programming forum 2017.11.01

      Broker History
      FXCM
      Commission - <TICKET>
      Rollover - <TICKET>

      >R/O - 1,000 EUR/USD @0.52

      #<ticket>  N/A
      OANDA
      Balance update
      Financing (Swap: One entry for all open orders.)

 
[Solved]
 
ElGaviero: Anyway, here is the code looking at OrderCloseTime(), is that right?
  1. No! You were told to use the code button. You didn't edit your original post as requested. You didn't use it on your last post.
  2. If you successfully select an order you continue on to the next one. Your loop now does nothing.
 
ElGaviero:
[Solved]

It is totally ridiculous to edit your posts in this manner.

You have deleted the original code and so now nobody knows what mistakes you made and the reply which helped you to correct your code make no sense at all.

Now nobody else can get any benefit from this topic.

 
Keith Watford:

It is totally ridiculous to edit your posts in this manner.

You have deleted the original code and so now nobody knows what mistakes you made and the reply which helped you to correct your code make no sense at all.

Now nobody else can get any benefit from this topic.


You are totally right, I rewrote the original code.. Anyway, solved by myself. 
I’m sorry if I messed up a bit!
Reason: