Get Price of Last Deal (Order Executed)

 

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)


Please, could anyone help me??

 
#define DAY (24 * 60 * 60)

void OnStart()
{
  if (HistorySelect(0, TimeTradeServer() + DAY) && (HistoryDealsTotal() > 0))
    Print("LastDealPrice = " + (string)HistoryDealGetDouble(HistoryDealGetTicket(HistoryDealsTotal() - 1), DEAL_PRICE));
}
 
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));  
 
Guilherme Mendonca:


I did not understand the part about.

#define DAY (24 * 60 * 60) ?

There can be a deal after TimeTradeServer.
 
fxsaber:
There can be a deal after TimeTradeServer.


Thank's man!

Its working!!

 
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.

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


????

 
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.
 
Alain Verleyen:

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

Read the documentation, please.

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

The code will always return the price of the last deal.
 
fxsaber:

Read the documentation, please.

lol...documentation about what ?
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).
 
Alain Verleyen:
Which is not what the OP is asking. He is asking the price of last deal on a related position (symbol).

Forum on trading, automated trading systems and testing trading strategies

Get Price of Last Deal (Order Executed)

Guilherme Mendonca, 2017.05.19 14:51

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).

Alain Verleyen:
lol...documentation about what ?
TimeTradeServer() >= TimeCurrent(); // true
Reason: