Problem with testing EA

 

Hi Everyone,

I have a problem with Strategy Tester - it always returns in log window: 2013.10.12 16:00:43 There were 1 passes done during optimization.

I did some manual testing during previous week and this EA send many pending orders and many of them were activated, so one passes during tests surprises me.

I set tick method, used almost every TF (apart from 1M) during my tests and the result was always the same.

I am not sure whether the problem is with my Checktime() function and variables calculated there (function checks allowed trading hours and return T or F).

The other think which might be tricky is the DAne_Handlowe1() function and variable cena - it is a close price of the specific bar from specific date=CzasStart - it workde perfect during tests on demo account but maybe it can not during using Strategy Tester in MT4??

Thanks for any help in advance!

Files:
 
jacksel:

Hi Everyone,

I have a problem with Strategy Tester - it always returns in log window: 2013.10.12 16:00:43 There were 1 passes done during optimization.

I did some manual testing during previous week and this EA send many pending orders and many of them were activated, so one passes during tests surprises me.

Why would you expect more than one pass during Optimization when you have no extern variables ? do you understand what an Optimization is ?
 
RaptorUK:
Why would you expect more than one pass during Optimization when you have no extern variables ? do you understand what an Optimization is ?


Hi RaptorUK,


Yes, I know what an Optimization is - on purpose I turned it off and the result none

I changed some variables to extern and there was no passes.

My EA is quite simple:

1. I define trading hours - from 17:10 to 18:45 local time - these are "CzasStart1" and "CzasStop1" variables respectively calculated in DaneCzasowe() function.

bool Checktime()
   {
      DaneCzasowe();
      if (TimeLocal()>=CzasStart1 && TimeLocal()<=CzasStop1 && DayOfWeek()!=0 && DayOfWeek()!=6)
         {
               CzasStart=CzasStart1;
               CzasStop=CzasStop1;
               return(true);
         }

      else return(false);                                  
   }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
bool DaneCzasowe()
   {
      Symb=Symbol();
      CzasStart1=StrToTime(TimeYear(TimeLocal())+"/"+TimeMonth(TimeLocal())+"/"+TimeDay(TimeLocal())+" "+"17:10:00");
      CzasStop1=StrToTime(TimeYear(TimeLocal())+"/"+TimeMonth(TimeLocal())+"/"+TimeDay(TimeLocal())+" "+"18:35:00");                
   }

2. I take the close price from 17:10 variable "cena" bar and I use it to define simple channel with upper bound and lower bound to set BUYLIMIT and SELLLIMIT levels in Dane_Handlowe1() function.

bool Dane_Handlowe1()
   {
            IndeksHandlu=6;
            cena=iClose(Symb,PERIOD_M5,iBarShift(Symb,PERIOD_M5,CzasStart));
            czas=iTime(Symb, PERIOD_M5,iBarShift(Symb,PERIOD_M5,CzasStart));
            GG=cena+GG1*Point;
            DG=cena+DG1*Point;            
            TPBUY=DG+TPBUY1*Point;
            SLBUY=DG+SLBUY1*Point;
            TPSELL=GG+TPSELL1*Point;
            SLSELL=GG+SLSELL1*Point;
            return(true);                                   
   }
 

3. If local time is in between trading hours, I check the current price if it is between BUYLIMIT=DG end SELLLIMIT=GG - in case it is, i calculate lotsize for risk=1%

bool Check_Margin_For_New() 
   {
      Symb=Symbol();   
      Lot_Size();
      AccountStopoutLev=AccountStopoutLevel();
      if(AccountMargin()==0)
         {
            AccountMarginForNewBUY=NormalizeDouble((AccountEquity()-AccountFreeMarginCheck(Symb,0,LotSizeBUY)),2);
            if (AccountFreeMarginCheck(Symb,0,LotSizeBUY) <= 0) SendError();
            AccountMarginForNewSELL=NormalizeDouble((AccountEquity()-AccountFreeMarginCheck(Symb,1,LotSizeSELL)),2);
            if (AccountFreeMarginCheck(Symb,1,LotSizeSELL)<=0) SendError();
            AccountRatioBUY=NormalizeDouble((AccountEquity()/AccountMarginForNewBUY)*100,2);
            AccountRatioSELL=NormalizeDouble((AccountEquity()/AccountMarginForNewSELL)*100,2);         
            if(AccountRatioBUY > AccountStopoutLev) return(true);
            if(AccountRatioSELL > AccountStopoutLev) return(true);            
            else return(false);             
         }
      else
         {
            AccountMarginForNewBUY=NormalizeDouble((AccountEquity()-AccountFreeMarginCheck(Symb,0,LotSizeBUY)),2);
            if (AccountFreeMarginCheck(Symb,0,LotSizeBUY)<=0) SendError();
            AccountMarginForNewSELL=NormalizeDouble((AccountEquity()-AccountFreeMarginCheck(Symb,1,LotSizeSELL)),2);
            if (AccountFreeMarginCheck(Symb,1,LotSizeSELL)<=0) SendError();
            AccountRatioBUY=NormalizeDouble((AccountEquity()/(AccountMargin()+AccountMarginForNewBUY)*100),2);
            AccountRatioSELL=NormalizeDouble((AccountEquity()/(AccountMargin()+AccountMarginForNewSELL)*100),2);           
            if(AccountRatioBUY > AccountStopoutLev) return(true);
            if(AccountRatioSELL > AccountStopoutLev) return(true);
            else return(false);              
         }                                
   }  
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
bool Lot_Size()
   {
      TickValue=(MarketInfo(Symb,MODE_TICKVALUE)/Point)*MarketInfo(Symb,MODE_TICKSIZE);
      TickSize=MarketInfo(Symb,MODE_TICKSIZE);
      PipsValue=TickValue*10;
      LotSizeBUY=NormalizeDouble((AccountEquity()/(-SLBUY1*PipsValue*100)),2);
      LotSizeSELL=NormalizeDouble((AccountEquity()/(SLSELL1*PipsValue*100)),2);                             
   }  

4. If everything is ok I check whether there are any pending or active orders on both long and short sides:


int Pending_Trade_Status()
   {
      Count_OP_BUY=0;
      Count_OP_BUYLIMIT=0;
      Count_OP_BUYSTOP=0;
      Count_OP_SELL=0;
      Count_OP_SELLLIMIT=0;
      Count_OP_SELLSTOP=0;      
      WszystkieZlecenia = OrdersTotal();
      if (WszystkieZlecenia==0) return(0);
      else
         {
            for(n=0;n<WszystkieZlecenia;n++)
               {
                  if(OrderSelect(n,SELECT_BY_POS)==true && OrderSymbol()==Symb)
                     {
                        if(OrderType()==OP_BUY) Count_OP_BUY=Count_OP_BUY+1;
                        if(OrderType()==OP_BUYLIMIT) Count_OP_BUYLIMIT=Count_OP_BUYLIMIT+1; 
                        if(OrderType()==OP_BUYSTOP) Count_OP_BUYSTOP=Count_OP_BUYSTOP+1;                        
                        if(OrderType()==OP_SELL) Count_OP_SELL=Count_OP_SELL+1;
                        if(OrderType()==OP_SELLLIMIT) Count_OP_SELLLIMIT=Count_OP_SELLLIMIT+1; 
                        if(OrderType()==OP_SELLSTOP) Count_OP_SELLSTOP=Count_OP_SELLSTOP+1;                    
                     }   
               }
            if (Count_OP_BUY==0 && Count_OP_BUYLIMIT==0 && Count_OP_BUYSTOP==0) return(2);
            if (Count_OP_SELL==0 && Count_OP_SELLLIMIT==0 && Count_OP_SELLSTOP==0) return(1);
            else return(3);      
         }                   
   }   
 

5. If there is no pending or active order on each side, I send an order on that side:

int Trade()
   {
      if(Checktime()==true && Check_GG_DG()==true && Check_Margin_For_New()==true)
         {
            if(Pending_Trade_Status()==2)
               {
                  TicketBUY=OrderSend(Symb,OP_BUYLIMIT,LotSizeBUY,DG,2,SLBUY,TPBUY,NULL,TimeLocal(),CzasStop,CLR_NONE);//BUYLIMIT
                  Alert("\nTrade()_1_SYMB=",Symb,"\nTrade()_1_TicketBUY=",TicketBUY,"\nTrade()_1_Cena=",DG,"\nTrade()_1_SLBUY=",SLBUY,"\nTrade()_1_TPBUY=",TPBUY);
                  return(TicketBUY);
               }
            if(Pending_Trade_Status()==1)
               {
                  TicketSELL=OrderSend(Symb,OP_SELLLIMIT,LotSizeSELL,GG,2,SLSELL,TPSELL,NULL,TimeLocal(),CzasStop,CLR_NONE);//SELLLIMIT
                  Alert("\nTrade()_1_SYMB=",Symb,"\nTrade()_1_TicketSELL=",TicketBUY,"\nTrade()_1_Cena=",GG,"\nTrade()_1_SLBUY=",SLSELL,"\nTrade()_1_TPBUY=",TPSELL);
                  return(TicketSELL);   
               }
            if(Pending_Trade_Status()==0)
               {
                  TicketBUY=OrderSend(Symb,OP_BUYLIMIT,LotSizeBUY,DG,2,SLBUY,TPBUY,NULL,TimeLocal(),CzasStop,CLR_NONE);//BUYLIMIT
                  SendError();
                  TicketSELL=OrderSend(Symb,OP_SELLLIMIT,LotSizeSELL,GG,2,SLSELL,TPSELL,NULL,TimeLocal(),CzasStop,CLR_NONE);//SELLLIMIT
                  SendError();
                  Alert("\nTrade()_1_SYMB=",Symb,"\nTrade()_1_TicketBUY=",TicketBUY,"\nTrade()_1_Cena=",DG,"\nTrade()_1_SLBUY=",SLBUY,"\nTrade()_1_TPBUY=",TPBUY);
                  Alert("\nTrade()_1_SYMB=",Symb,"\nTrade()_1_TicketSELL=",TicketSELL,"\nTrade()_1_Cena=",GG,"\nTrade()_1_SLBUY=",SLSELL,"\nTrade()_1_TPBUY=",TPSELL);    
                  return(11);  
               }
            else return(3);                                                                     
         }   
   } 
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
int SendError()
  {
      int CheckError;
      CheckError=GetLastError();
      MessageBox("Error nr="+CheckError);
  }  

I still cant get why it worked during last week when i traded and why it shows 0 results or 1 passes while testing in Strategy Tester (with optimization either on or off).

 

from 17:10 to 18:45 local time

make it TimeCurrent brokertime

 
deVries:

from 17:10 to 18:45 local time

make it TimeCurrent brokertime

Hi,

I changed TimeLocal to TimeCurrent, but still no results - can anyone more experienced/literate and so over can run my EA on his platform for example on last week data with optimization off just to check if there are any trades tested?

Once again changed code including deVries and RaptorUK remarks.

Files:
 
jacksel:

Hi,

I changed TimeLocal to TimeCurrent, but still no results - can anyone more experienced/literate and so over can run my EA on his platform for example on last week data with optimization off just to check if there are any trades tested?

Once again changed code including deVries and RaptorUK remarks.



2013.10.12 23:19:53 2013.10.02 04:38 testerstrategii_1 EURCHF,M5: checktime false
2013.10.12 23:19:53 2013.10.02 04:38 testerstrategii_1 EURCHF,M5: checktime false
2013.10.12 23:19:52 2013.09.30 17:20 testerstrategii_1 EURCHF,M5: unknown subwindow number 1 for ObjectCreate function
2013.10.12 23:19:52 2013.09.30 17:20 testerstrategii_1 EURCHF,M5: unknown subwindow number 1 for ObjectCreate function
2013.10.12 23:19:52 2013.09.30 17:20 testerstrategii_1 EURCHF,M5: checktime true
2013.10.12 23:19:52 2013.09.30 17:20 testerstrategii_1 EURCHF,M5: unknown subwindow number 1 for ObjectCreate function
2013.10.12 23:19:52 2013.09.30 17:20 testerstrategii_1 EURCHF,M5: unknown subwindow number 1 for ObjectCreate function
2013.10.12 23:19:52 2013.09.30 17:20 testerstrategii_1 EURCHF,M5: checktime true
2013.10.12 23:19:52 2013.09.30 17:20 testerstrategii_1 EURCHF,M5: unknown subwindow number 1 for ObjectCreate function
2013.10.12 23:19:52 2013.09.30 17:20 testerstrategii_1 EURCHF,M5: unknown subwindow number 1 for ObjectCreate function
2013.10.12 23:19:51 2013.09.26 14:33 testerstrategii_1 EURCHF,M5: checktime false
2013.10.12 23:19:51 2013.09.26 14:33 testerstrategii_1 EURCHF,M5: checktime false

int start()
  {           
      if (Checktime()==True) 
          {
          Print("checktime true");
          Dane_Handlowe1();
          }  
      else
         {
            Print("checktime false");            
            return;       
         }   
      if (Dane_Handlowe1()==True) 
         {   
            Check_GG_DG();
            if(ObjectsTotal()==0) 
               {   
                  ObjectCreate("DG", OBJ_HLINE,DG,DG,DG);
                  ObjectCreate("GG", OBJ_HLINE,GG,GG,GG);                  
               }          
         }   
      else return;      
      if (Check_GG_DG()==True) Check_Margin_For_New();

Place printfunctions inside your code to find out what's going on.....


Reason: