Download MetaTrader 5

Strategy Tester Visualization crashes when ObjectCreate is called

To add comments, please log in or register
fifthfloor
15
fifthfloor  

I had some trouble with the strategy tester visualization (which is a great tool) when the expert is creating objects on the chart.

Here is some sample code which forces the error when running in tester with visualization mode:

//+------------------------------------------------------------------+
//|                                           _TestCreateObjects.mq5 |
//|                                        Copyright 2011 Fifthfloor |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011 Fifthfloor"
#property version   "1.00"

int LinieCount=1;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DrawLine(string Name,datetime Time1,double Price1,datetime Time2,double Price2,color Color,ENUM_LINE_STYLE Style)
  {
//if(!MQL5InfoInteger(MQL5_TESTING))  //----remove comment mark as a work around
     {
      ObjectCreate(0,Name,OBJ_TREND,0,Time1,Price1,Time2,Price2);
      ObjectSetInteger(0,Name,OBJPROP_COLOR,Color);
      ObjectSetInteger(0,Name,OBJPROP_STYLE,Style);
      ObjectSetInteger(0,Name,OBJPROP_BACK,false);
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   static datetime Old_Time;
   datetime New_Time[3];
   bool IsNewBar=false;
   int copied=CopyTime(_Symbol,_Period,0,3,New_Time);
   if(Old_Time!=New_Time[0])
     {
      IsNewBar=true;
      Old_Time=New_Time[0];
     }
   if(IsNewBar)
     {
      MqlRates mrate[3];
      CopyRates(_Symbol,_Period,0,3,mrate);
      DrawLine("Object"+(string)LinieCount,New_Time[0],mrate[0].open,New_Time[1],mrate[1].open,clrPaleGreen,STYLE_DOT);
      LinieCount++;
     }
  }
//+------------------------------------------------------------------+
Maybe this could be fixed in a future version.
Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types
  • www.mql5.com
Standard Constants, Enumerations and Structures / Objects Constants / Object Types - Documentation on MQL5
Rashid Umarov
Admin
12066
Rashid Umarov  
fifthfloor:

I had some trouble with the strategy tester visualization (which is a great tool) when the expert is creating objects on the chart.

Here is some sample code which forces the error when running in tester with visualization mode:

Maybe this could be fixed in a future version.
I have checked and couldn't reproduced that. We need more details.
fifthfloor
15
fifthfloor  

Yes, you are right. The code above runs without an error.

Just comment out the last line:

// LinieCount++;

So that ObjectCreate tries to create an object with an exsisting name.

The visualization will crash, while in demo trading, this works properly.
Alexey Da
Moderator
6641
Alexey Da  
Thanks. We will check it.
Alexey Da
Moderator
6641
Alexey Da  
Fixed. Please wait for the next build.
To add comments, please log in or register