actual price where lines intersect

 

Anyone know if is it possible to get the actual price where two lines intersect as this usually happens in between bars ?

 

yes.

With the help of the two points that define each line you can write down the two line equations for the two lines:

y1 = a1x + b1

y2 = a2x + b2


they intersect where y1 = y2:

a1x+b1 = a2x+b2

now solve for x. I am too lazy now. After you have x you can easily calculate y

 

thanks 7bit I'll work on that

 
SDC:

thanks 7bit I'll work on that


did you solve it? Can you show me how?
 

No i didnt need that in the end but I guess we could test it ...

7bit said you need two points to define each line, the mt4 trendline parameters conveniently has two points, so I'll put 2 converging trendlines on a chart and use their parameters.

Trendline1: point1 = 1.327437, point 2 = 1.332253

Trendline2: point1 = 1.324306, point 2 = 1.330406

then he said Y1 = a1x + b1 and Y2 = a2x + b2

so

Y1 = 1.327437x + 1.324306

Y2 = 1.332253x + 1.330406

he said Y1 = Y2

a1x+b1 = a2x+b2

so make them be equal

1.327437x + 1.324306 = 1.332253x + 1.330406

so now switch them about to put all the x stuff on the left ( that's what they do in algebra )

1.327437x + 1.332253x = 1.324306 + 1.330406

do the additions and we get

2.65969x = 2.654712

so x must be 2.654712 / 2.65969

x = 0.998128

so now we have x we can solve Y

take either of the original line equations

Y1 = 1.327437x + 1.324306

replace x with the now known value of x

Y1 = 1.327437 x 0.998128 + 1.324306 so Y1 = 2.649258

lets check that with the other line equation (they should be the same or real close allowing for some dp rounding)

Y2 = 1.332253x + 1.330406

replace x again with our x value x = 0.998128

Y2 = 1.332253 x 0.998128 + 1.330406 so Y2 = 2.660165

so ....

they dont match :(

so I am going to check those trendlines on the chart to see what the value is when they actually intersect.

the value where they actually intersect is 1.3353

So both my results from the equation is about as incorrect as you could get.

That means one of two things happend, either SDC still cant do algebra any better than he could when he failed it twice in high school :(

or 7bits equation is a bunch of crap.

I would be inclined to blame my algebra first unless someone else corroborates my result.

Algebra brings back memories of torturous math lessons. i would happily beat on whoever invented algebra with a 6lb hammer. Then stomp all over him. Then tie him to a rope behind my car and drag him all the way to California. Then dump him in the ocean during shark week.

 
SDC:

No i didnt need that in the end but I guess we could test it ...

7bits said you need two points to define each line, the mt4 trendline parameters conveniently has two points, so I'll put 2 converging trendlines on a chart and use their parameters.

Trendline1: point1 = 1.327437, point 2 = 1.332253

Trendline2: point1 = 1.324306, point 2 = 1.330406

then he said Y1 = a1x + b1 and Y2 = a2x + b2

so

Y1 = 1.327437x + 1.324306

Y2 = 1.332253x + 1.330406

...


y = ax + b is the general equation for a straight line. a and b are not points. a is the slope of the line and b is the y axis intersect (value of y when x is set to zero)

 

well damn he never said anything about slope ... this is really bugging me now I'm going to do it again with the slope and see if it works

 
SDC:

well damn he never said anything about slope ... this is really bugging me now I'm going to do it again with the slope and see if it works


Let me know if you want the answer. I'm in the mood for a bit of brain exercise :)
 

Alright two new trendlines ;(

This time I'll set the trendline parameters to make their 2 points on exact 4 digit prices and I'll do the calculations in pips instead of points so 1.3278 = 13278

So, b is the y axis value of each line where the y axis intersects both lines ? I'm going to set the two trendlines starting at the same bar so the first trendline parameter (price) will be b.

the Y axis is going to be incremented by bars ...or should it be minutes ? hmmm I think bars.

Y1 = ax + b

Y2 = ax +b

2 points on trendline1 1.3278, 1.3326

2 points on trendline2 1.3192, 1.3285

we know the values of b so I'll put them in already.

Y1 = ax + 13278

Y2 = ax + 13192

Now to calculate the value of slope ...

I'm going to calculate it like you would a gradient.

On both lines the two line points (A and B) on the x axis are 4 bars apart, so Ay is bar zero and By is bar 4.

slope = Ay - By / Ax - Bx

trendline1 slope 13278 - 13326 / 0 - 4

trendline2 slope 13192 - 13285 / 0 - 4

(in case anyone wants to know, that is also how you calculate the angle of the line. arctan(12) = 85°

ok so now we know the two slopes we can fill in the rest of the line equations

Y1 = 12x + 13278

Y2 = 23.25x + 13192

The intersect is when Y1 = Y2 so make the 2 line equations be equal

12x + 13278 = 23.25x + 13192

put all the x stuff on the left side

12x + 23.25x = 1.3278 + 1.3192

do the additions

35.25x = 26470

so x = 26470 / 35.25

that makes x = 750.9212 and that has got to be incorrect how can the intersection be 750 bars away i can see just be looking its only a few bars.

im not even going to continue with this BS it is obviously still wrong and im tired of it.

 
xorpheus:

Let me know if you want the answer. I'm in the mood for a bit of brain exercise :)

Sure go ahead although its not the answer i want, i already know just by looking at the chart where the lines intersect, I want to know how to do the calculation and why it didnt work.

 
SDC:

Sure go ahead although its not the answer i want, i already know just by looking at the chart where the lines intersect, I want to know how to do the calculation and why mine didnt work.


Okay so the inputs are the prices of the two lines on bar 1, and the prices of the two lines on bar 2. We want an equation to give us the price where the lines intersect each other.

A price is not a point so let's start by making them points (x,y). We'll make life easy for ourselves by making x = 0 for bar 1 and x = 1 for bar 2.

Let's call the bar 1 price of the first line p1, and the bar 2 price of the first line p2. For the second line we'll use p3 and p4.

Bar 1 points: (0,p1) and (0,p3)
Bar 2 points: (1,p2) and (1,p4)

Slope of first trendline = (y2 - y1) / (x2 - x1) = (p2 - p1) / (1 - 0) = p2 - p1
Slope of second trendline = (p4 - p3) / (1 - 0) = p4 - p3

The y intersect of each line is simply the bar 1 prices p1 and p3, because we defined x = 0 for bar 1.

So the two line equations are:

y1 = (p2 - p1)x + p1
y2 = (p4 - p3)x + p3

Intersection is where y1 = y2:

(p2 - p1)x + p1 = (p4 - p3)x + p3

Solve for x:

(p2 - p1)x - (p4 - p3)x = p3 - p1
(p2 - p1) - (p4 - p3) = (p3 - p1)/x
p2 - p1 - p4 + p3 = (p3 - p1)/x


x = (p3 - p1) / (p2 - p1 - p4 + p3)

So that will give us x. Now plug x back into one of the two line equations to get y (price):

y = (p2 - p1) x (p3 - p1) / (p2 - p1 - p4 + p3) + p1
I'm not going to bother trying to simplify that right now :)

Let's test it with bar 1 prices = 1 and 3; bar 2 prices = 4 and 2. One line goes up, the other down. Answer should be 2.5
p1 = 1
p2 = 4
p3 = 3
p4 = 2

y = (4 - 1) x (3 - 1) / (4 - 1 - 2 + 3) + 1
y = (3 x 2 / 4) + 1 (parentheses added for clarity)
y = 6 / 4 + 1
y = 1.5 + 1 = 2.5 woohooo!

Please do more tests I just did this now it could be wrong. Watch out for the case where the lines are parallel and do not intersect as it will give a divide by zero error.

Reason: