Different results ObjectGetShiftByValue and ObjectGetShiftByValueMQL4 in MQL5

 

As mentioned here:

https://www.mql5.com/fa/articles/81

To get the number of candles in the intersection of a line and a price, in MQL5, instead of the ObjectGetShiftByValue function, I used ObjectGetShiftByValueMQL4, the code of which is suggested as follows:

int ObjectGetShiftByValueMQL4(string name,
                              double value)
  {
   ENUM_TIMEFRAMES timeframe=TFMigrate(PERIOD_CURRENT);
   datetime Arr[];
   int shift;
   MqlRates mql4[];
   if(ObjectGetTimeByValue(0,name,value)<0) return(-1);
   CopyRates(NULL,timeframe,0,1,mql4);
   if(CopyTime(NULL,timeframe,mql4[0].time,
      ObjectGetTimeByValue(0,name,value),Arr)>0)
      return(ArraySize(Arr)-1);
   else return(-1);
  }


For when the intersection of price and object is in the chart range, a positive number is returned and is not a problem. But when the intersection point is in the empty part of the chart. In MQL4 its value is negative and in MQL5 the number zero is always returned. As shown in the image below:


The expected and logical value is a negative number.

What is your suggestion for solving this problem in MQL5?

Migrating from MQL4 to MQL5
Migrating from MQL4 to MQL5
  • www.mql5.com
This article is a quick guide to MQL4 language functions, it will help you to migrate your programs from MQL4 to MQL5. For each MQL4 function (except trading functions) the description and MQL5 implementation are presented, it allows you to reduce the conversion time significantly. For convenience, the MQL4 functions are divided into groups, similar to MQL4 Reference.
Reason: