MT5 Strategy Tester - strange object creation behaviour

 

Gents,

I'm currently playing with the new bar event handler lib (https://www.mql5.com/en/articles/159).

My goal is to simply draw a green arrow_up on a new bar. This is for testing and familiarising only ;-)


However, I'm seeing a lot of strange things happening:

1. Although the log shows that a new bar is detected from the very first second on, the arrows first time show up half a month after starting in strategy tester

2. In live testing the arrow is suddenly not an arrow like in strategy tester but a thumb up?

3. Often, the arrow does not get drawn at all, though in the same if statement and Print() is being run from the same if statement


My function to draw the arrow (for better readability I removed the error management):

bool IndicatorValues::DrawArrowUp(void)
  {
   bool result;
   arrow_label++;
   string label = IntegerToString(arrow_label);
   switch(ObjectFind(0,label))
     {
      case -1:
         ObjectCreate(ChartID(),label,OBJ_ARROW_UP,0,TimeCurrent(),SymbolInfoDouble(_Symbol,SYMBOL_BID));
         ObjectSetInteger(ChartID(),label,OBJPROP_ARROWCODE,241);
         ObjectSetInteger(ChartID(),label,OBJPROP_ANCHOR,ANCHOR_TOP);
         ObjectSetInteger(ChartID(),label,OBJPROP_WIDTH,8);
         ObjectSetInteger(ChartID(),label,OBJPROP_COLOR,clrRed);
         ObjectSetInteger(ChartID(),label,OBJPROP_STYLE,STYLE_SOLID);
         ObjectSetInteger(ChartID(),label,OBJPROP_HIDDEN,false);
         ObjectSetInteger(ChartID(),label,OBJPROP_BACK,false);
         ObjectSetString(ChartID(),label,OBJPROP_TEXT,IntegerToString(ObjectGetInteger(ChartID(),label,OBJPROP_TIME)));
         ObjectSetInteger(ChartID(),label,OBJPROP_SELECTABLE,true);
         result=true;
         break;
      case 0:
         result=false;
         break;
     }
     return(result);
  }


my function call in the EA (OnTick):

if(current_chart.isNewBar()>0)
     {
      ea.DrawArrowUp();
     
      Print("### MATCH ###");
      Print("LC: ",last_close_price," EMA: ",current_ema," RSI: ",current_rsi," LRSI: ",lastbar_rsi);
     }


I already considered my lack of coding knowledge (just started) as well as any possible bugs in MT5? The delayed start of arrow object creation in the strategy tester, could this possibly be related to poor history data?


Looking forward to your thoughts and ideas.

The "New Bar" Event Handler
The "New Bar" Event Handler
  • www.mql5.com
Authors of indicators and experts have always been interested in writing the compact code in terms of execution time. You can approach to this problem from different angles. From this broad topic in this article we will cover the problem, that is seemingly already have been solved: check for a new bar. This is quite a popular way to limit the...
 
update - just found out my history quality is shocking 5%. Working on improving the history now. Hopefully that's why things fail...
 
That didn't fix it. History quality now at 100%. Still seeing arrows starting delayed by 18 days when backtesting three months, while the new bar journal messages in the same if statement start right away...
 

Really strange...

As you guys can see, trading live MT5 first prints an arrow and then all of a sudden switches to thumbs_up? 

Files:
 
   arrow_label++;
   string label = IntegerToString(arrow_label);

You can't use an as-series index in names as they are not unique. As soon as a new bar starts, you will be trying to create a new name (e.g. "name0",) same, existing, previous, name (e.g. "name0" now on bar one.)

Use time (as int) or a non-series index:

#define  SERIES(I)   (Bars - 1 - I) // As-series to non-series or back.
Reason: