ChartTimePriceToXY() does not give the values correctly in NON-VISUAL mode tester

 
datetime timeLastTickProcessed = D'1971.01.01 00:00';
int OnInit()
  {   
   return(INIT_SUCCEEDED);
  }

void OnTick()
  {      
   if(isProcessThisIteration()){
   int x1 =0; int y1 =0; int x2 =0; int y2 =0;
   
   datetime time1 = iTime(_Symbol,PERIOD_H1,1);
   datetime time2 = iTime(_Symbol,PERIOD_H1,70);
   
   double rightPrice = iClose(_Symbol,PERIOD_H1,1);
   double leftPrice = iClose(_Symbol,PERIOD_H1,70);
  
   bool statusOne = ChartTimePriceToXY(0,0,time2,leftPrice,x1,y1);
   bool statusTwo = ChartTimePriceToXY(0,0,time1,rightPrice,x2,y2); 
   
   double angle = -MathArctan( (double)(y1-y2)/(double)(x1-x2) )*180/M_PI;
  
  Print("leftPrice ",leftPrice, " rightPrice ",rightPrice, " time1 ", time1, " time2 ", time2, " x1 ", x1, " x2 ", x2," y1 ", y1, " y2 ", y2," statusOne ",statusOne, " statusTwo ",statusTwo," error code ", GetLastError());
   Print("angle is ", angle);
   }
  
}

bool isProcessThisIteration(){
   bool processThisIteration = false;    
      if(timeLastTickProcessed != iTime(Symbol(), PERIOD_H1, 0)){
         processThisIteration = true;
         timeLastTickProcessed = iTime(Symbol(), PERIOD_H1, 0);
      }
   return processThisIteration;
}

Hi Guys,

I have a very straight forward code above. When I run in VISUAL mode, everything works perfectly fine.

BUT, in NON-VISUAL mode the x1,x2,y1,y2 are returned constants every time. Here is example of the output. 

NOTE: Others values got retrieved correctly as the candle pass.

leftPrice 1.12013 rightPrice 1.10816 time1 2023.07.24 18:00:00 time2 2023.07.19 21:00:00 x1 -1136 x2 -32 y1 -1 y2 -1 statusOne true statusTwo true error code 0

Please help, I have been stuck for days


 

Documentation on MQL5: MQL5 programs / Testing Trading Strategies

Graphical Objects in Testing #

During testing/optimization graphical objects are not plotted. Thus, when referring to the properties of a created object during testing/optimization, an Expert Advisor will receive zero values.

This limitation does not apply to testing in visual mode.

Documentation on MQL5: MQL5 programs / Testing Trading Strategies
Documentation on MQL5: MQL5 programs / Testing Trading Strategies
  • www.mql5.com
Testing Trading Strategies - MQL5 programs - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5