Download MetaTrader 5

No deal profit available

To add comments, please log in or register
Do you have Linux? Find out how to install MetaTrader on it!
chinaski
890
chinaski 2013.02.06 13:50 

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: 

 

 

 

void OnTradeTransaction(const MqlTradeTransaction& trans,
                        const MqlTradeRequest& request,
                        const MqlTradeResult& result)
{

    if(trans.deal > 0)
                Print(DoubleToString(HistoryDealGetDouble(trans.deal,DEAL_PROFIT),6));    
}

 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 nuts
2184
phi nuts 2013.02.06 14:48  
chinaski:

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 

Learn the code from here SendNotification with P&L
chinaski
890
chinaski 2013.02.06 14:58  

Hello Phi,

HistoryDealSelect

does not work as well (as well as using CDealInfo).

So a transaction happened, a deal number available; how to get profit please ?

Thank you 

 

 

chinaski
890
chinaski 2013.02.06 15:09  

Phi,

You are right. 

HistoryDealSelect

is what solves it. 

(Why at all, if HistoryDealGetDouble expects a deal # ?)

chinaski
890
chinaski 2013.02.06 16:53  

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.

khai hoan nguyen
242
khai hoan nguyen 2013.02.07 09:35  
the same mt4, i have script close at profit. you can see here. from mt4, you can wirte for mt5, i think same
Files:
chinaski
890
chinaski 2013.03.27 05:18  

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
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
To add comments, please log in or register