Trendlines and calculating the actual price

 

Hi,

when I draw a line into my chart, I want to calculate the actual price of my line, the price is only correct, when the left and/or the right point is in the near of the actual price,

int x1 = ObjectGet(ObjectArray[i], OBJPROP_TIME1);   
double y1 = ObjectGet(ObjectArray[i], OBJPROP_PRICE1);
int x2 = ObjectGet(ObjectArray[i], OBJPROP_TIME2);   
double y2 = ObjectGet(ObjectArray[i], OBJPROP_PRICE2);  
         
double steigung1 = (y2-y1)/(x2-x1);
double yabschnitt1 = y1 - (x1*steigung1);
GlobalVariableSet(ObjectArray[i]+"_"+MagicNumber+"_Steigung", steigung1);
GlobalVariableSet(ObjectArray[i]+"_"+MagicNumber+"_YAbschnitt", yabschnitt1);         
double aktuell = (TimeCurrent()*steigung1+yabschnitt1) ;

When the left of the right point is far away from the actual price, the calculated trend line price is also relative far away from the price I can see.

I think the code is right, or does anybody something wrong???

 
sunshineh:


I think the code is right, or does anybody something wrong???

Are you allowing for weekends ? Why not use ObjectGetValueByShift() ?