Download MetaTrader 5

Error with strategy tester. Bug !

To add comments, please log in or register
Having questions? Ask them on the Forum - traders will help you!
Patrick Bouche
195
Patrick Bouche 2010.09.30 18:10 

Hello there,

I found an error with the strategy tester, which occurs only when testing. There are no error when operating live (demo).

It seems that the values of global variables are reset to 0 when exiting functions.

Below is the EA: The variables: Current_res & Current_sup have their values assigned when calling the function  Filter_swings(); , with the next line I checked their values Alert(Current_res," ",Current_sup);

There are no error when the EA is attached to a chart, those variables return the correct values, but not with Strategy tester, here is a part of the log:

GN 0 Core 1 07:49:45 2010.07.01 00:00:12   Error
KO 0 Core 1 07:49:45 2010.07.01 00:00:12   0 0
EJ 0 Core 1 07:49:45 2010.07.01 01:00:00   Error
IS 0 Core 1 07:49:45 2010.07.01 01:00:00   0 0
PF 0 Core 1 07:49:45 2010.07.01 02:00:00   Error
DG 0 Core 1 07:49:45 2010.07.01 02:00:00   0 0

Thanks to look into it. Pat

Here is my EA:

//+------------------------------------------------------------------+
//|                                                             Tester.mq5 |
//|                                Copyright 2010, -----------------. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2010, ---------------------."
#property link      "http://www.mql5.com"
#property version   "1.00"
#include <PrintComment.mqh>
#include <SendOrder.mqh>
#include <ModifyPosition.mqh>
#include <ModifyOrder.mqh>
#include <CloseOrder.mqh>
#include <DeleteOrder.mqh>

input      int   Delta=10;

int ZigZaghandle;
double ZizZagbuffer[],ZizZagbufferhighs[],ZizZagbufferlows[];
double lows[5][2];
double highs[5][2];
double Current_res, Current_sup, stp, tgt;
int    Pos_res, Pos_sup, delta;
bool              newbar;
datetime          time0[1];
static datetime   oldtime;
string            text;
MqlTick           CurrentPrice;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   ZigZaghandle=iCustom(_Symbol,0,"Examples\\ZigZag",12,5,3);
   if(ZigZaghandle==INVALID_HANDLE) Alert("Cannot call indicator");
   ArraySetAsSeries(ZizZagbuffer,true);ArraySetAsSeries(ZizZagbufferhighs,true);ArraySetAsSeries(ZizZagbufferlows,true);
  
//---
   delta=Delta;
   if(_Digits==3 || _Digits==5)  {delta=Delta*10;}
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   IndicatorRelease(ZigZaghandle);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- detect new bar 
   newbar=false;
   int copied=CopyTime(_Symbol,PERIOD_H1,0,1,time0);
   if(copied<0){StringConcatenate(text,"Error copying time0, #",GetLastError());PrintComment(text);ResetLastError();}
   if(oldtime!=time0[0])
   {
      oldtime=time0[0];
      newbar=true;  
   }
   if(newbar==true)
   {
      Filter_swings();
      Alert(Current_res," ",Current_sup);
      if(PositionSelect(_Symbol)==0)
      {
         SymbolInfoTick(_Symbol,CurrentPrice);
         if(CurrentPrice.ask > Current_res+delta*_Point && CurrentPrice.ask < Current_res+500*_Point)
         {
            stp=Current_sup;
            tgt=Current_res+(Current_res-Current_sup);
            SEND(_Symbol,"BUY",11111,0.2,CurrentPrice.ask,stp,tgt,"");
         }
         if(CurrentPrice.bid < Current_sup-delta*_Point && CurrentPrice.bid > Current_sup-500*_Point)
         {
            stp=Current_res;
            tgt=Current_sup-(Current_res-Current_sup);
            SEND(_Symbol,"SELL",22222,0.2,CurrentPrice.bid,stp,tgt,"");
         }
      }
   }
  
  
  }
//+------------------------------------------------------------------+
bool Filter_swings()
{
   if(CopyBuffer(ZigZaghandle,0,0,Bars(_Symbol,0)-2,ZizZagbuffer)<0)       {Alert("Error");ResetLastError();return(0);}
   if(CopyBuffer(ZigZaghandle,1,0,Bars(_Symbol,0)-2,ZizZagbufferhighs)<0)  {Alert("Error");ResetLastError();return(0);}
   if(CopyBuffer(ZigZaghandle,2,0,Bars(_Symbol,0)-2,ZizZagbufferlows)<0)   {Alert("Error");ResetLastError();return(0);}
   int x; int l=0; int h=0;
   for(x=0 ; x<100 ; x++)
   {
      if(ZizZagbufferhighs[x]!=0 && ZizZagbuffer[x]!=0)  {if(h<5){highs[h][0]=x;highs[h][1]=ZizZagbufferhighs[x];h++;}} 
      if(ZizZagbufferlows[x]!=0 && ZizZagbuffer[x]!=0)   {if(l<5){lows[l][0]=x;lows[l][1]=ZizZagbufferlows[x];l++;}}
      if(h>=5 && l>=5)break; 
   }
   //Searching for last resistance
   for(x=0;x<5;x++) 
   {
      if(highs[x][0]>4)
      {
         Current_res=highs[x][1];
         Pos_res=highs[x][0];
         break;
      }
   }  
   //Searching for last support
   for(x=0;x<5;x++) 
   {
      if(lows[x][0]>4)
      {
         Current_sup=lows[x][1];
         Pos_sup=lows[x][0];
         break;
      }
   }
   //Alert("Res: ",Pos_res," ",Current_res," Sup: ",Pos_sup," ",Current_sup);
   return(1);
}

Automated Trading and Strategy Testing
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
Alexey Da
Moderator
6605
Alexey Da 2010.09.30 19:23  

1. Insert code properly, please.

2. Your code are big enough so It would be better if you attached your code.

3. Attach all includes too.

MQL5.community - User Memo
  • 2010.02.25
  • MetaQuotes Software Corp.
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
Patrick Bouche
195
Patrick Bouche 2010.10.01 00:12  
alexvd:

1. Insert your code properly.

2. Your code are big enough so It would be better if you attached your code.

3. Attach all includes

 

There it is. Maybe I'm missing something....

Pat. 

Alexey Da
Moderator
6605
Alexey Da 2010.10.01 10:26  
bouchepat:

There it is. Maybe I'm missing something....

Pat. 

Are you sure that variables have their values assigned before?

Most likely execution doesn't reach the lines where you set new values for them, so they have values which they were assigned to them during declaration.

Patrick Bouche
195
Patrick Bouche 2010.10.01 13:01  
alexvd:
Are you sure that variables have their values assigned before?

Most likely execution doesn't reach the lines where you set new values for them, so they have values which they were assigned to them during declaration.

Well it works and returns the correct values when i attach the EA to a chart; but somehow the strategy tester doesn't run the function : Filter_swings() enterely, therefore the variables are not assigned any values.

Why would the strategy tester doesn't reach the lines of assignement ?

 I even tried to insert the lines, where i assign the values, directly in the program (OnTick()), same result works well in normal execution but not in strategy tester. ??

Pat....  

Alexey Da
Moderator
6605
Alexey Da 2010.10.01 18:56  
bouchepat:

Well it works and returns the correct values when i attach the EA to a chart; but somehow the strategy tester doesn't run the function : Filter_swings() enterely, therefore the variables are not assigned any values.

Why would the strategy tester doesn't reach the lines of assignement ?

 I even tried to insert the lines, where i assign the values, directly in the program (OnTick()), same result works well in normal execution but not in strategy tester. ??

Pat....  

Yes. You are right.

It has been already fixed. Wait for updates.

To add comments, please log in or register