Perpendicular line in the midpoint of another

 

Hi All,

please can any one help me in coding mql4 for drawing a line perpendicular to another line from the mid point.

the picture attached for clarification. the red line is perpendicular to the yellow.

for the yellow line one end (price1,datetime1) the other end (price2,datetime2). how to get the middle point between them and draw the red line.

picture1

 

To turn the line by 90 degrees counterclockwise you need to swap price delta and time delta, and flip the sign of the price delta.

So if the yellow line is (price1,time1) to (price2,time2) the red line is (sp,st) to (sp+dt,st-dp), where dt=time2-time1, dp=price2-price1, sp=(price1+price2)/2 and st=(time1+time2)/2.

 

thanks for your reply , but i cannt figure this out.

i try your method , but other issues popped up like time difference is not accurate. and if i change the start time or price the lines will be messy.

please help in coding guys.

 

Yes I can see that it's difficult to solve because you have to deal with different dimensions (time vs price.) My approach would be to convert times and prices to pixel coordinates before doing the rotation.

But even if this works, consider what happens to your setup when the chart is scaled differently:

prices scaled down               prices scaled up

It's still the same chart. Where's your right angle now? None of the lines are perpendicular. Maybe you should rework your approach.