No deal profit available
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.
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.
- www.mql5.com
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