chinaski:
Learn the code from here SendNotification with P&L
Hello,
when open a position and close i can see the profit of this transaction in the deal history along with profit.
Not so from within mql:
This returns always zero. However, in the history you can see the profit for same deal #.
Anyone knows how to get proft from Transaction event ?
asd
Phi,
You are right.
HistoryDealSelect
is what solves it.
(Why at all, if HistoryDealGetDouble expects a deal # ?)
CDealInfo does not work reliable:
void OnTradeTransaction(const MqlTradeTransaction& t, const MqlTradeRequest& request, const MqlTradeResult& result) { //--- if(t.deal > 0) { CDealInfo di; di.Ticket(t.deal); Print("s1=",di.Symbol()); HistoryDealSelect(t.deal); Print("s2=",HistoryDealGetString(t.deal,DEAL_SYMBOL)); } }
s1 is emtpy. s2 not.
the same mt4, i have script close at profit. you can see here. from mt4, you can wirte for mt5, i think same
Files:
CloseAtProfit.mq4
15 kb
Hello,
it seems that at least DEAL_PRICE and DEAL_PROFIT does always return 0 in backtest (MqlTradeTransaction has zeros as well).
void OnTradeTransaction(const MqlTradeTransaction& trans, const MqlTradeRequest& request, const MqlTradeResult& result) { if(trans.symbol == Symbol() && trans.deal > 0) { if(HistoryDealSelect(trans.deal) == true) { int dealtype=HistoryDealGetInteger(trans.deal,DEAL_TYPE); //if(trans.deal_type == (int) DEAL_ENTRY_OUT) { double price=HistoryDealGetDouble(trans.deal,DEAL_PRICE); double profit=HistoryDealGetDouble(trans.deal,DEAL_PROFIT); Print(StringFormat("deal price=%.5f profit=%.2f",price,profit)); /// zero zero } } else Print("SELECT FAILED"); } }
Anyone knows what i do wrong or a workaround.
This applies only for backtesting.

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Deal Properties
- www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Deal Properties - Documentation on MQL5

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello,
when open a position and close i can see the profit of this transaction in the deal history along with profit.
Not so from within mql:
This returns always zero. However, in the history you can see the profit for same deal #.
Anyone knows how to get proft from Transaction event ?
asd