Inaccurate results from "ObjectGetValueByTime" and "ObjectGetValueByShift"

 
Hello, I need to be able to extrapolate the current values of trend lines every hour on an EA which runs on the H4 time frame. A separate section of my EA runs at the beginning of each hour and most variables contained within that section update accurately and fine. However "Var1 = ObjectGetValueByShift("TrendLine",0);" (run once during initialisation) and "Var2 = ObjectGetValueByTime(NULL,"TrendLine",TimeCurrent(),0);" (run at the beginning of each hour) both produce the line's value at the beginning of the current H4 four-hour period. The value after, for example, three and a half hours is often materially different from that at the beginning of the four-hour period, leading to inaccurate trading decisions by the EA. TimeCurrent() does not seem to produce the value 'now'. Also I have searched this site and also on the internet generally and I cannot find any explanation of the fourth element in the ObjectGetValueByTime expression i.e. "line_id". What does that mean please and might it be the problem as I have set it to 0?
 

Sneck55: I need to be able to extrapolate the current values of trend lines every hour on an EA which runs on the H4 time frame.

A separate section of my EA runs at the beginning of each hour and most variables contained within that section update accurately and fine. However "Var1 = ObjectGetValueByShift("TrendLine",0);" (run once during initialisation) and "Var2 = ObjectGetValueByTime(NULL,"TrendLine",TimeCurrent(),0);" (run at the beginning of each hour) both produce the line's value at the beginning of the current H4 four-hour period.

The value after, for example, three and a half hours is often materially different from that at the beginning of the four-hour period, leading to inaccurate trading decisions by the EA.

TimeCurrent() does not seem to produce the value 'now'. Also I have searched this site and also on the internet generally and I cannot find any explanation of the fourth element in the ObjectGetValueByTime expression i.e. "line_id". What does that mean please and might it be the problem as I have set it to 0?

Don't post your questions inside SRC blocks, it is impossible to read. Please Edit your post.
  1. There is no such function ObjectGetValueByShift in MT5Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)

  2. TimeCurrent does produce the value 'now', which ObjectGetValueByTime uses to get the bar index, and your still getting the beginning of the H4 value as you see.
  3. Perhaps you should read the manual.

    An object can have several values in one price coordinate, therefore it is necessary to specify the line number. This function applies only to the following objects:

    • Trendline (OBJ_TREND)
    • Trendline by angle (OBJ_TRENDBYANGLE)
    • Gann line (OBJ_GANNLINE)
    • Equidistant channel (OBJ_CHANNEL) - 2 lines
    • Linear regression channel (OBJ_REGRESSION) - 3 lines
    • Standard deviation channel (OBJ_STDDEVCHANNEL) - 3 lines
  4. Those functions will not give you interbar results. You'll have to compute the slope and interpolate it yourself.
    Not compiled, not tested.
    datetime T1 = Time[0];  double P1 = ObjectGetValueByTime(0, "TrendLine", T1);
    datetime T2 = Time[1];  double P2 = ObjectGetValueByTime(0, "TrendLine", T2);
    double   slope = (p1 - p2) / double(T1 - T2);
    double   curValue = P1 + slope * (TimeCurrent() - T1);
    Not compiled, not tested.