i can not used this function (ObjectGetValueByTime) - page 2

 
Alain Verleyen #:

I removed your inflammatory post.

This is an MT5 topic.

Unless proven otherwise there is no issue with ObjectGetValueByTime(), it works as documented.

Well, I've just found out that it is actually been said about ChartRedraw() in the documentation, so I came here to say 'I'm sorry'...

But still I don't see anything about the necessary usage of the Sleep() function. Any information about the way I can calculate the time necessary for my script to be put to Sleep() so that it will work correctly for sure. So no, not sorry yet.


Thanks for not banning me anyway, that was noble.

Object Functions - MQL4 Reference
Object Functions - MQL4 Reference
  • docs.mql4.com
Object Functions - MQL4 Reference
 
Mikhail Sobolev #:

Well, I've just found out that it is actually been said about ChartRedraw() in the documentation, so I came here to say 'I'm sorry'...

But still I don't see anything about the necessary usage of the Sleep() function. Any information about the way I can calculate the time necessary for my script to be put to Sleep() so that it will work correctly for sure. So no, not sorry yet.


Thanks for not banning me anyway, that was noble.

No problem, it happens.

There is no need for Sleep() to my knowledge (on MT5 I am sure it doesn't need it).

Please post your code, I will check.

 
Alain Verleyen #:

No problem, it happens.

There is no need for Sleep() to my knowledge (on MT5 I am sure it doesn't need it).

Please post your code, I will check. 

Actually I have a glimpse of the same problem in MQL5 too. May I ask you to discuss it instead of MQL4? I have made some research for MQL5 and I can tell something.
Also I need to say, the problem is not of much importance to me, the dispute was more about moral, so, please, if you don't think it's worthy your time, do not waste it. Otherwise I will continue. Someone might find it useful. 

The Chart is EURUSD, M15.
Here is the code:

void OnStart()
  {
//---
   string regrName = "Regression " + TimeToString(TimeCurrent(), TIME_SECONDS);
   datetime time1 = StringToTime("2023.03.27 01:30");
   datetime time2 = StringToTime("2023.03.27 03:45");
   ObjectCreate(0, regrName, OBJ_REGRESSION, 0, time1, 0.0, time2, 0.0);
   ObjectSetInteger(0, regrName, OBJPROP_HIDDEN, false);
   ObjectSetInteger(0, regrName, OBJPROP_SELECTABLE, true);
   ObjectSetInteger(0, regrName, OBJPROP_RAY_RIGHT, true);
   
   ChartRedraw(0);
   //Sleep(10);
   
   datetime timeGet = StringToTime("2023.03.27 04:00");
   
   double priceGet0 = ObjectGetValueByTime(0, regrName, timeGet, 0);
   string arrowName0 = "Arrow0 " + DoubleToString(priceGet0);
   ObjectCreate(0, arrowName0, OBJ_ARROW, 0, timeGet, priceGet0);
   ObjectSetInteger(0, arrowName0, OBJPROP_HIDDEN, false);
   ObjectSetInteger(0, arrowName0, OBJPROP_SELECTABLE, true);
   ObjectSetInteger(0, arrowName0, OBJPROP_ARROWCODE, 241);
   
   double priceGet1 = ObjectGetValueByTime(0, regrName, timeGet, 1);
   string arrowName1 = "Arrow1 " + DoubleToString(priceGet1);
   ObjectCreate(0, arrowName1, OBJ_ARROW, 0, timeGet, priceGet1);
   ObjectSetInteger(0, arrowName1, OBJPROP_HIDDEN, false);
   ObjectSetInteger(0, arrowName1, OBJPROP_SELECTABLE, true);
   ObjectSetInteger(0, arrowName1, OBJPROP_ARROWCODE, 241);
   
   double priceGet2 = ObjectGetValueByTime(0, regrName, timeGet, 2);
   string arrowName2 = "Arrow2 " + DoubleToString(priceGet2);
   ObjectCreate(0, arrowName2, OBJ_ARROW, 0, timeGet, priceGet2);
   ObjectSetInteger(0, arrowName2, OBJPROP_HIDDEN, false);
   ObjectSetInteger(0, arrowName2, OBJPROP_SELECTABLE, true);
   ObjectSetInteger(0, arrowName2, OBJPROP_ARROWCODE, 241);
   
   //Alert("Manual deletion, no Sleep() ", priceGet0, " ", priceGet1, " ", priceGet2);
  }


For better demonstration I put Arrows at the points I'm looking for. At first, after each test I've been deleting them and the Channel manually, and for the most of the tests ObjectGetValueByTime() without Sleep(10) was returning me 0.0 for the Line 0 of the Channel. (For the most of the tests except for the very first one after the start of the Metatrader 5 or after I change the code a bit. The change is necessary; if I will recompile it without a change, for some reason it will not count as the 'first time'. (And then it started to work at random.)) With Sleep(10) there was no such issue.
You can see results in the file '
1. Manual deletion.png'.

Then I've added deletion to the script with these lines in the beginning of the OnStart():

   ObjectDelete(0, "Regression");
   ObjectsDeleteAll(0, "Arrow");
   
   ChartRedraw(0);

Works almost good without Sleep(), but still sometimes fails to get value of the Line 0, '2. Auto deletion.png', and works perfectly with Sleep().


Then I've changed the order of Channel Lines I'm getting values from in the code. First goes the Line 1 and then the Line 0:

void OnStart()
  {
//---
   ObjectDelete(0, "Regression");
   ObjectsDeleteAll(0, "Arrow");
   
   ChartRedraw(0);
   
   string regrName = "Regression " + TimeToString(TimeCurrent(), TIME_SECONDS);
   datetime time1 = StringToTime("2023.03.27 01:30");
   datetime time2 = StringToTime("2023.03.27 03:45");
   ObjectCreate(0, regrName, OBJ_REGRESSION, 0, time1, 0.0, time2, 0.0);
   ObjectSetInteger(0, regrName, OBJPROP_HIDDEN, false);
   ObjectSetInteger(0, regrName, OBJPROP_SELECTABLE, true);
   ObjectSetInteger(0, regrName, OBJPROP_RAY_RIGHT, true);
   
   ChartRedraw(0);
   //Sleep(10);
   
   datetime timeGet = StringToTime("2023.03.27 04:00");
   
   double priceGet1 = ObjectGetValueByTime(0, regrName, timeGet, 1);
   string arrowName1 = "Arrow1 " + DoubleToString(priceGet1);
   ObjectCreate(0, arrowName1, OBJ_ARROW, 0, timeGet, priceGet1);
   ObjectSetInteger(0, arrowName1, OBJPROP_HIDDEN, false);
   ObjectSetInteger(0, arrowName1, OBJPROP_SELECTABLE, true);
   ObjectSetInteger(0, arrowName1, OBJPROP_ARROWCODE, 241);
   
   double priceGet0 = ObjectGetValueByTime(0, regrName, timeGet, 0);
   string arrowName0 = "Arrow0 " + DoubleToString(priceGet0);
   ObjectCreate(0, arrowName0, OBJ_ARROW, 0, timeGet, priceGet0);
   ObjectSetInteger(0, arrowName0, OBJPROP_HIDDEN, false);
   ObjectSetInteger(0, arrowName0, OBJPROP_SELECTABLE, true);
   ObjectSetInteger(0, arrowName0, OBJPROP_ARROWCODE, 241);
   
   double priceGet2 = ObjectGetValueByTime(0, regrName, timeGet, 2);
   string arrowName2 = "Arrow2 " + DoubleToString(priceGet2);
   ObjectCreate(0, arrowName2, OBJ_ARROW, 0, timeGet, priceGet2);
   ObjectSetInteger(0, arrowName2, OBJPROP_HIDDEN, false);
   ObjectSetInteger(0, arrowName2, OBJPROP_SELECTABLE, true);
   ObjectSetInteger(0, arrowName2, OBJPROP_ARROWCODE, 241);
   
   //Alert("Auto deletion, no Sleep(), Lines replaced ", priceGet0, " ", priceGet1, " ", priceGet2);
  }

As a result it seems like without Sleep() the value of the Line 1 corresponds to the beginning of this Line and not to the time I was looking for, 3. Lines replaced.png.

 
Mikhail Sobolev #:

Actually I have a glimpse of the same problem in MQL5 too. May I ask you to discuss it instead of MQL4? I have made some research for MQL5 and I can tell something.
Also I need to say, the problem is not of much importance to me, the dispute was more about moral, so, please, if you don't think it's worthy your time, do not waste it. Otherwise I will continue. Someone might find it useful. 

Here is the code:


For better demonstration I put Arrows at the points I'm looking for. At first, after each test I've been deleting them and the Channel manually, and for the most of the tests ObjectGetValueByTime() without Sleep(10) was returning me 0.0 for the Line 0 of the Channel. (For the most of the tests except for the very first one after the start of the Metatrader 5 or after I change the code a bit. The change is necessary; if I will recompile it without a change, for some reason it will not count as the 'first time'. (And then it started to work at random.)) With Sleep(10) there was no such issue.
You can see results in the file '
1. Manual deletion.png'.

Then I've added deletion to the script with these lines in the beginning of the OnStart():

Works almost good without Sleep(), but still sometimes fails to get value of the Line 0, '2. Auto deletion.png', and works perfectly with Sleep().


Then I've changed the order of Channel Lines I'm getting values from in the code. First goes the Line 1 and then the Line 0:

As a result it seems like without Sleep() the value of the Line 1 corresponds to the beginning of this Line and not to the time I was looking for, 3. Lines replaced.png.

I will check and keep you posted.

EDIT:

You are right, it should not need a Sleep(), I will report it to Metaquotes.

Reason: