Problems with Linear Point-Slope Equation of a Line

 

Hi,

 

I'm currently having troubles with replicating the equation used by ObjectGetValueByShift. I think I'm having trouble getting the algebra correctly. I've been using this site as a source; https://www.mathsisfun.com/algebra/line-equation-point-slope.html , but I can't wrap my head around it.

 

I have the two points of Y-Y (vertical/price: s1-s2) and X-X (horizontal/time: st1-st2) for calculating the slope like this;

double dateS1=StrToDouble(Time[st1]);

double dateS2=StrToDouble(Time[st2]);

double CurrentT=StrToDouble(Time[0]); 

double Slope=(s1-s2)/(dateS1-dateS2);

As you can imagine subtracting two almost equals returns an infinite number 8.1231241352e-008 and I'm not sure if this is the problem.

 

Further I've tried several different approaches in finding where price would be on my slope at current time.

double s1B = Bid-TrendSlope*CurrentT;

double s1Current = TrendSlope*CurrentT+s1B; 

 and

double s1B = s1-TrendSlope*dateS1;

double s1Current = TrendSlope*dateS1+s1B;

 

The reason I need to recreate this equation is due to the fact that graphical objects aren't supported when running optimization, so ObjectGetValueByShift doesn't work.

 

I'd greatly appreciate any help as I'm kind of new to this. I've only been coding for a couple of weeks and I have been struggling with this for a good 12 hours now... 

 
Ok, I know I have to use ChartTimePriceToXY and ChartXYToTimePrice... But I still can't wrap my head around it. Do I need to use a distance from point to line equation in order to replicate the ObjectGetValueByShift?
 

The math. images show you x- and y-values in equidistance.

The chart does not!

If you e.g. take bar by bar you can use 0,1,2,3,... their difference is 1 (similar to the x-values) but the prices aren't 1,2,3 at all and the differences are some points which means e.g. 0.0010.

You have to adjust the scales before you can start to calculate!

 
I became aware of that. I figured the functions ChartTimePriceToXY and ChartXYToTimePrice would solve that problem. First converting price and time for both points into X and Y- and then convert it back again or simply having the EA being aware of time and price in terms of X and Y.
Reason: