I've a code that determines the deal profit of the last closed deal below.
How do I modify it to return the profit of the deal before the last one e.g deal 2 in history and the one before e.g deal 3?
My code for the profit of the latest code:
Here's one way (call "deal_profitY(1)" for last profit, "deal_profitY(2)" for 2nd last, and so on...):
double deal_profitY(int num) { : : if((HistoryDealGetInteger(ticket,DEAL_ENTRY)==DEAL_ENTRY_OUT)&&symbol==Symbol()) { if (--num==0) { deal_profit=HistoryDealGetDouble(ticket,DEAL_PROFIT); break; } } : }
Here's one way (call "deal_profitY(1)" for last profit, "deal_profitY(2)" for 2nd last, and so on...):
for(int i=HistoryDealsTotal()-1; i>=0; i--) {
Will this part of the code stay the same throughout the three calls?
Code doesn't work , i.e doesnt retrieve profit of the last 4th trade in the list, remember this trade profit has to change because trade history is constantly update.
double deal_profitT4(int num) { ulong ticket; datetime closeTime=0; bool found=false; double deal_profit=0; //ulong order_magic; string symbol; if(HistorySelect(0,TimeCurrent())) { for(int i=HistoryDealsTotal()-1; i>=0; i--) { ticket=HistoryDealGetTicket(i); symbol=HistoryDealGetString(ticket,DEAL_SYMBOL); if((HistoryDealGetInteger(ticket,DEAL_ENTRY)==DEAL_ENTRY_OUT)&&symbol==Symbol()) { if (num==4) { deal_profit=HistoryDealGetDouble(ticket,DEAL_PROFIT); break; } } } } return (deal_profit); } //==============================================
Code doesn't work , i.e doesnt retrieve profit of the last 4th trade in the list, remember this trade profit has to change because trade history is constantly update.
My Suggestion | Your Changes |
---|---|
if (--num==0) |
if (num==4) |
My Suggestion | Your Changes |
---|---|
Faulty code only returns the third deal on the list.
Faulty code only returns the third deal on the list.
any other suggestions?
Code doesn't work , i.e doesnt retrieve profit of the last 4th trade in the list, remember this trade profit has to change because trade history is constantly update.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I've a code that determines the deal profit of the last closed deal below.
How do I modify it to return the profit of the deal before the last one e.g deal 2 in history and the one before e.g deal 3?
My code for the profit of the latest code: