# Get Price of Last Deal (Order Executed)

3924

Hello,

If I have multiples orders executed in the same trade (same direction) to do averaging price and I would like to get the price of the last order executed, not the final price (average).

How can I get this value?

I tryed to use the function bellow, but this function give me the price of the result of all orders.

PositionGetDouble(POSITION_PRICE_OPEN)

6547

```#define DAY (24 * 60 * 60)

void OnStart()
{
if (HistorySelect(0, TimeTradeServer() + DAY) && (HistoryDealsTotal() > 0))
Print("LastDealPrice = " + (string)HistoryDealGetDouble(HistoryDealGetTicket(HistoryDealsTotal() - 1), DEAL_PRICE));
}```
3924

fxsaber:

I did not understand the part about.

#define DAY (24 * 60 * 60) ?

Could I just use something like this:

```double OPLAST;
if (HistorySelect(0, TimeTradeServer()) && (HistoryDealsTotal() > 0))
OPLAST = HistoryDealGetDouble(HistoryDealGetTicket(HistoryDealsTotal() - 1), DEAL_PRICE));  ```
6547

Guilherme Mendonca:

I did not understand the part about.

#define DAY (24 * 60 * 60) ?

There can be a deal after TimeTradeServer.
3924

fxsaber:
There can be a deal after TimeTradeServer.

Thank's man!

Its working!!

Moderator
32410

fxsaber:
There can be a deal after TimeTradeServer.

Why using TimeTradeServer() at all ? Use TimeCurrent().

Your code could gives unexpected result is more than 1 symbol is traded.

3924

Alain Verleyen:

Why using TimeTradeServer() at all ? Use TimeCurrent().

Your code could gives unexpected result is more than 1 symbol is traded.

Yeah, I think you right

How should I have to do using TimeCurrent() ? Just need to substitute TimeTradeServer ?

Could be like:

```double OPLAST=0; //Price of the Last Order executed (
if (HistorySelect(0, TimeCurrent()) && (HistoryDealsTotal() > 0))
OPLAST = HistoryDealGetDouble(HistoryDealGetTicket(HistoryDealsTotal() - 1), DEAL_PRICE)); ```

????

Moderator
32410

Guilherme Mendonca:

Yeah, I think you right

How should I have to do using TimeCurrent() ? Just need to substitute TimeTradeServer ?

Could be like:

????

It depends where this code is executed. If in OnTick() yes you can just replace. In OnStart(), as fxsaber said you could also have a deal after TimeCurrent(), but then no point to use any TimeXXX() function, just use D'3000.12.31' for example.
6547

Alain Verleyen:

Why using TimeTradeServer() at all ? Use TimeCurrent().

Your code could gives unexpected result is more than 1 symbol is traded.

The code will always return the price of the last deal.
Moderator
32410

fxsaber:

The code will always return the price of the last deal.
Which is not what the OP is asking. He is asking the price of last deal on a related position (symbol).
6547

Alain Verleyen:
Which is not what the OP is asking. He is asking the price of last deal on a related position (symbol).

`TimeTradeServer() >= TimeCurrent(); // true`