Get Last Deal Profit

 

Hello,

Im trying to get my last deal profit, that means that if I lose I get a negative number and if I win I get positive number.

I wrote the simple code:

HistorySelectByPosition(last position ticket);
Print(HistoryDealGetDouble(HistoryDealGetTicket(0),DEAL_PROFIT));

but all I get is 0.0, always.

When I use:

Print(HistoryDealGetDouble(HistoryDealGetTicket(0),DEAL_PROFIT),doubleVariable);

It does return true, but doubleVariable equals 0.0.


what am I doing wrong?

Thanks.

 
yuv98:

Hello,

Im trying to get my last deal profit, that means that if I lose I get a negative number and if I win I get positive number.

I wrote the simple code:

but all I get is 0.0, always.

When I use:

It does return true, but doubleVariable equals 0.0.

what am I doing wrong?

Thanks.





Look at this

https://www.mql5.com/en/docs/trading/historyselect

Only thing I would change is counting down the deals (in case you are making changes).
 
strategy_tester:
Look at this

https://www.mql5.com/en/docs/trading/historyselect

Only thing I would change is counting down the deals (in case you are making changes).

I changed the "HistorySelect" to:

   HistorySelect(0,TimeCurrent()); 

Insted of

HistorySelectByPosition(last position ticket);

and it did work. when I check a deal that closed a position it showed me the profit.

Thank you!