Errors, bugs, questions - page 2412

 
Andrey Barinov:

Then debug it. Print transaction tickets and see in the tester what is actually selected there. Add a filter for deal type, though.

The lot is displayed correctly, so the ticket is selected correctly.

 
Andrey Dik:

the lot is correct, so the ticket is correct.

No. Both trades, In and Out, have the same lot. But the profit is not.

Here's my code. It works.

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
ulong LastOutDealTicket(const string symbol,const uint magic)
  {
//===============
   long lasttime=0;
//===============

//===============
   ulong ticket=0;
//===============

//===============
#ifdef __MQL5__
//===============
   ::HistorySelect(0,TimeCurrent()+60);
//===============
   const int deals=::HistoryDealsTotal();
//===============
   for(int i=deals-1;i>=0;i--)
     {
      //===============
      const ulong tempticket=::HistoryDealGetTicket(i);
      //===============

      //===============
      if(::HistoryDealGetInteger(tempticket,DEAL_ENTRY)!=DEAL_ENTRY_OUT || ::HistoryDealGetString(tempticket,DEAL_SYMBOL)!=symbol ||
         ::HistoryDealGetInteger(tempticket,DEAL_MAGIC)!=magic)continue;
      //===============

      //===============
      if(::MQLInfoInteger(MQL_TESTER))return(tempticket);
      //===============

      //===============
      if(::HistoryDealGetInteger(tempticket,DEAL_TIME)<=lasttime)continue;
      //===============

      //===============
      ticket=tempticket;
      lasttime=::HistoryDealGetInteger(tempticket,DEAL_TIME);
      //===============
     }
//===============
#endif 
//===============

//===============
#ifdef __MQL4__
//===============
   const int ordershistory=OrdersHistoryTotal();
//===============
   for(int i=ordershistory-1;i>=0;i--)
     {
      //===============
      if(!::OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) || ::OrderSymbol()!=symbol || ::OrderMagicNumber()!=magic || 
         (::OrderType()!=OP_SELL && ::OrderType()!=OP_BUY))continue;
      //===============

      //===============
      if(::MQLInfoInteger(MQL_TESTER))return(::OrderTicket());
      //===============

      //===============
      if(::OrderCloseTime()<=lasttime)continue;
      //===============

      //===============
      ticket=::OrderTicket();
      lasttime=::OrderCloseTime();
      //===============
     }
//===============
#endif 
//===============

//===============
   return(ticket);
//===============
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double LastClosedProfit(const string symbol,const uint magic)
  {
//===============
   const ulong lastoutticket=::LastOutDealTicket(symbol,magic);
//===============

//===============
   if(lastoutticket<=0)return(0);
//===============

//===============
   double result=0;
//===============

//===============
#ifdef __MQL5__
//===============
   result=::HistoryDealGetDouble(lastoutticket,DEAL_PROFIT);
//===============
#endif 
//===============

//===============
#ifdef __MQL4__
//===============
   if(::OrderSelect((int)lastoutticket,SELECT_BY_TICKET,MODE_HISTORY))result=::OrderProfit();
//===============
#endif 
//===============

//===============
   return(result);
//===============
  }
 
Andrey Barinov:

No. Both trades, In and Out, have the same lot. The profit is not.

Here's my code. It works.

tried it, your code gives 0.0 too)))

The account is hedged, if anything.
 
Andrey Dik:

tried it, your code gives 0.0 too)))

The account is hedged, if anything.

Just checked everything on 2009 build. My code gives out what it should. If it gives 0, it means you have 0 there.

 
Andrey Barinov:

Just checked everything on the 2009 build. My code gives out what it is supposed to give out. If it gives 0, it means that you have 0 there.

How come, in the history there are closed trades with a non-zero result, and it gives 0

 
Andrey Barinov:
Andrey Dik:

There is a possibility that the problem could be on the DC side.

 
Alexey Kozitsyn:

There is a possibility that the problem may be on the DC side.

Tried it on Metaquotes and Robo, in the tester.

 
Found my mistake... My mistake was that I didn't pass a majik to the position close function, but to the open function, and as a result the deal could not be selected by the majik...
 

If you use CSymbolInfo in multicurrency, which is called by Name method at the moment of initialization:

if(!SymbolInfoDouble(m_name,SYMBOL_TRADE_TICK_VALUE,m_tick_value))
   return(false);
if(!SymbolInfoDouble(m_name,SYMBOL_TRADE_TICK_VALUE_PROFIT,m_tick_value_profit))
   return(false);
if(!SymbolInfoDouble(m_name,SYMBOL_TRADE_TICK_VALUE_LOSS,m_tick_value_loss))
   return(false);

During testing USDCAD symbol errors will occur:

no prices for symbol
 
Andrey Pogoreltsev:

If you use CSymbolInfo in multicurrency, which is called by Name method at the moment of initialization:

There will be errors for USDCAD symbol during testing:

Does anyone even understand what we're talking about?