Chart Object works fine in Visual test but returns no values in backtest

 

Hi,


I've written a piece of code that creates a linear regression object on the chart based recent swings. I then need to use the values from the upper and lower channel in my trade criteria. When I run it in visual backtest mode, everything works fine. When I turn off the visual mode, it stops working. Instead of returning the values of the lines as it did in visual mode, it returns 0. 

Below is the code used to create the object where swinghighdate is an array containing the bar the swing occurred on. This is sending correct information verified by Journal

ObjectCreate(chart_id,cname,OBJ_REGRESSION,NULL,swinghighdate[limit-1],0,swinghighdate[0],0);
ObjectSetInteger(chart_id,cname,OBJPROP_COLOR,clrRed);
ObjectSetInteger(chart_id,cname,OBJPROP_WIDTH,2);
ObjectSetInteger(chart_id,cname,OBJPROP_RAY_RIGHT,true);
ObjectSetInteger(chart_id,cname,OBJPROP_STYLE,STYLE_DOT);


Below is the code I use to get the value of the channels for the last bar

 if(ObjectFind(chart_id,cname)>=0)
   {
      linreg_upper = ObjectGetValueByTime(chart_id,cname,Time[1],1);
      linreg_lower = ObjectGetValueByTime(chart_id,cname,Time[1],2); 
      linreg_mid = ObjectGetValueByTime(chart_id,cname,Time[1],0);
      return (true);
   }
        

I'm not sure how to solve this. Is it a problem with the RAY_RIGHT not extending and therefore there is no channel at that value? Or am I missing something obvious? 

Any help would be appreciated

Thanks

 
wildkev146: Or am I missing something obvious?

Chart Object works fine in Visual test but returns no values in backtest

There is no chart to put the objects on.
 
William Roeder:
There is no chart to put the objects on.

Ok, that does make sense. Is there a workaround you can suggest? Does it need to be in the form of an indicator? 

Thank you

 
William Roeder:
There is no chart to put the objects on.

Further digging around the MQL manuals, I found this page https://docs.mql4.com/runtime/testing

In it, there is this section


Graphical Objects in Testing

During visualization, the Expert Advisor interacts with a real chart. In case there is no visualization, the Expert Advisor works with a "virtual" chart that is not displayed. The former case has some peculiarities. During optimization, working with graphical objects is not supported.


Unfortunately it doesn't give guidance on how to get workaround it


Thanks

Operation of Programs in the Strategy Tester - MQL4 programs - MQL4 Reference
Operation of Programs in the Strategy Tester - MQL4 programs - MQL4 Reference
  • docs.mql4.com
There are operation limitations for some functions in the client terminal's Strategy Tester. Calling that functions leads to error 4059 (Function is not allowed in testing mode). The Sleep() Function The Print() and PrintFormat() Functions To increase performance, Print() and PrintFormat() functions are not executed when optimizing the trading...