Use iBarShift for the time points, then you can calculate the rise/fall for x bars
Then you can use this value to calculate the rise/fall over y bars
sunshineh: I am trying to calculate the actual value of my trendline that way:
ObjectGetValueByShift - Object Functions - MQL4 ReferenceObjectGetValueByTime - Object Functions - MQL4 Reference
sunshineh:
I am trying to calculate the actual value of my trendline that way:
x1 = (datetime)ObjectGet(AlertElement, OBJPROP_TIME1);
y1 = (double)ObjectGet(AlertElement, OBJPROP_PRICE1);
x2 = (datetime)ObjectGet(AlertElement, OBJPROP_TIME2);
y2 = (double)ObjectGet(AlertElement, OBJPROP_PRICE2);
stg1 = (y2-y1)/(x2-x1);
yab1 = y1 - (x1*stg1);
ActualLineValue = (Time[0]*stg1+yab1) ;
Sometimes this is working fine, but in other times the value pretty far away. Do you have a solution?
I am trying to calculate the actual value of my trendline that way:
x1 = (datetime)ObjectGet(AlertElement, OBJPROP_TIME1);
y1 = (double)ObjectGet(AlertElement, OBJPROP_PRICE1);
x2 = (datetime)ObjectGet(AlertElement, OBJPROP_TIME2);
y2 = (double)ObjectGet(AlertElement, OBJPROP_PRICE2);
stg1 = (y2-y1)/(x2-x1);
yab1 = y1 - (x1*stg1);
ActualLineValue = (Time[0]*stg1+yab1) ;
Sometimes this is working fine, but in other times the value pretty far away. Do you have a solution?
Maybe the reason for your problem is datetime? It gives you seconds but on the chart you see some kind or enumeration of bars.
E.g. the two points of a straight line were [0,100] and [5,200]. x (=0 & 5) were bar numbers so stg1 = (200-100)/(5-0) = 20.
But in case this were h1-bars you get for (x2-x1) = 5 (bars) * 60 (min) * 60 (sec) = 18'000 and stg1 = 0,00555555555555555555555555555556.
You can try tdiff = (x2-x1)/(Period()*60) => 18'000/(60*60) = 5?

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
x1 = (datetime)ObjectGet(AlertElement, OBJPROP_TIME1);
y1 = (double)ObjectGet(AlertElement, OBJPROP_PRICE1);
x2 = (datetime)ObjectGet(AlertElement, OBJPROP_TIME2);
y2 = (double)ObjectGet(AlertElement, OBJPROP_PRICE2);
stg1 = (y2-y1)/(x2-x1);
yab1 = y1 - (x1*stg1);
ActualLineValue = (Time[0]*stg1+yab1) ;
Sometimes this is working fine, but in other times the value pretty far away. Do you have a solution?