Download MetaTrader 5
To add comments, please log in or register
Do you want to write a trading robot? Find solution in MQL5 Reference!
fifthfloor
15
fifthfloor 2011.08.15 19:24 

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
11562
Rashid Umarov 2011.08.16 11:23  
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 2011.08.16 17:09  

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
6511
Alexey Da 2011.08.16 18:48  
Thanks. We will check it.
Alexey Da
Moderator
6511
Alexey Da 2011.08.17 12:21  
Fixed. Please wait for the next build.
/
To add comments, please log in or register