finding price on a trendline ( equation of a straight line)
- ObjectCreate Trendline
- I would like to know how to get the object by number
- trendline trigger
double x1 = ObjectGet( strName, OBJPROP_TIME1); double y1 = ObjectGet( strName, OBJPROP_PRICE1); double x2 = ObjectGet( strName, OBJPROP_TIME2); double y2 = ObjectGet( strName, OBJPROP_PRICE2); double m = (y2-y1)/(x2-x1); double b=y1 -m*x1; double time=TimeCurrent(); double value=m*time+b;
Your problem is the assumption of continuous time. You have missing bars (weekend.) Therefor the trendline doesn't have constant slope in time.
"Free-of-Holes" Charts -
MQL4 Articles
No candle
if open = close ? - MQL4 and MetaTrader 4 -
MQL4 programming forum
Compare to
double x1 = iBarShift(_Symbol, PERIOD_CURRENT, ObjectGet( strName, OBJPROP_TIME1) ); double y1 = ObjectGet( strName, OBJPROP_PRICE1); double x2 = iBarShift(_Symbol, PERIOD_CURRENT, ObjectGet( strName, OBJPROP_TIME2) ); double y2 = ObjectGet( strName, OBJPROP_PRICE2); double m = (y2-y1)/(x2-x1); double b=y1 -m*x1; double time=iBarShift(_Symbol, PERIOD_CURRENT, TimeCurrent() ); double value=m*time+b;
Your problem is the assumption of continuous time. You have missing bars (weekend.) Therefor the trendline doesn't have constant slope in time.
"Free-of-Holes" Charts -
MQL4 Articles
No candle
if open = close ? - MQL4 and MetaTrader 4 -
MQL4 programming forum
Compare to