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?
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
datetime T1 = Time; double P1 = ObjectGetValueByTime(0, "TrendLine", T1);
datetime T2 = Time; double P2 = ObjectGetValueByTime(0, "TrendLine", T2);
double slope = (p1 - p2) / double(T1 - T2);
double curValue = P1 + slope * (TimeCurrent() - T1);