Strategy Tester and Deal Magic

 

Hi all !!

next code is just a sample to check deal history.

Backtesting an Ea including this code should Print "magic ok", but journal shows both "magic ok" and "magic". Hmm... so whats wrong ? 

void DealMagicTest() 
  {
   uint total=0;
   long ticket;
   long magic;

   HistorySelect(0,TimeCurrent());
   total=HistoryDealsTotal();

   for(uint i=0;i<total; i++)
     {
      ticket=HistoryDealGetTicket(i);

      magic=HistoryDealGetInteger(ticket,DEAL_MAGIC);
      
      if(magic==MagicNumber)
        {
         Print("magic ok");
        }
      if(magic!=MagicNumber)
        {
         Print("magic");
        }
     }
  }
 
Algm:

Hi all !!

next code is just a sample to check deal history.

Backtesting an Ea including this code should Print "magic ok", but journal shows both "magic ok" and "magic". Hmm... so whats wrong ? 

In tester journal log, first deal entry is "deal #2". So with this for() loop, you will scan deal #0 and deal #1 that may not reference EA generated order.

for(uint i=0;i<total; i++)

Try this to see if this is correct.

if(magic==MagicNumber)
   {
      Print("magic ok"," Ticket # ",ticket);
   }
if(magic!=MagicNumber)
   {
      Print("magic"," Ticket # ",ticket);
   }
 
wackena:

In tester journal log, first deal entry is "deal #2". So with this for() loop, you will scan deal #0 and deal #1 that may not reference EA generated order.

Try this to see if this is correct.


Im checking #1 and #2 deals, and is correct. 

I didn´t realize that deal #1 is the first deposit into account. Now i understand how it works.

Thanks :)
Reason: