Help to calculate the slope of a line that is Perpendicular to a known line

 

I want to calculate the slope of a line that is Perpendicular to a known line:


Line A is Perpendicular to line B;

Slope of Line A: SlopeA = (Price1-Price2)/(bar2-bar1);

Because Line A is vertical to line B, So:

SlopeA*SlopeB = -1;

Therefore: SlopeB = - 1/SlopeA = - (bar2-bar1)/(Price1-Price2);

furthermore, the priceX on line B at bar X should be: price X = aknownpriceonlineB + SlopeB*barX

BUT, when I put this into my indicator, it will never work!


What's wrong here? Could anybody help please?


Thanks

I figured out that in order for the condition SlopeB = - (1/SlopeA) become true, we need to put a conversion factor for the price. For the x-axis we use the number of bars, for the y-axis we use price, BUT, we have to define the unit of price, only when price/bar = 1, then we are in proportion, only in this condition we can calculate angle between two lines, so, the introduction of a conversion facotr is necessary, so, the operation should be: IF SlopeB = - (1/SlopeA) = - (bar1-bar2)/(Price1-Price2)*conversion factor; THEN Price = SlopeB * (Bar - KnownBar) + KnownPrice will be TRUE, How to calculate or accomplish this?

HELP please!

 

I follow most of what you are saying and I agree with the formula Slope B = - (1/Slope A) but I do not understand why a conversion factor is needed, nor do I understand why a "unit" price is needed. Why doesn't 1 pip/bar suffice as the desired unit? Are you also trying to calc angles?


Can you explain more. I can probably help.


raft

 
#property copyright "Copyright ?2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

extern int ExtDepth=45;
extern int ExtDeviation=5;
extern int ExtBackstep=3;

int start()
  {
int i,ix,H,L,Hx,Lx;
double PH,PL,PHx,PLx;
//----   
   for(i = 500; i >=0; i--)
   {

double a0=iCustom(NULL, 0, "Zigzag2_R_", ExtDepth, ExtDeviation, ExtBackstep, 0, i);

double a1=iCustom(NULL, 0, "Zigzag2_R_", ExtDepth, ExtDeviation, ExtBackstep, 1, i);


   if(a0!=0.0){PH=a0;H=i;}
   if(a1!=0.0){PL=a1;L=i;}

}
int   Ox = (H+L)/2;
double  yyx =(PH+PL)/2;

double    k = (-1/(PL-PH)/(Time[L]-Time[H]));


double    kbbs =yyx-(-1/(PL-PH)/(Time[L]-Time[H]))*(Time[Ox]-Time[H]);


     ObjectDelete("Trendline1");
     ObjectCreate("Trendline1",OBJ_TREND,0,Time[H],kbbs,Time[Ox],yyx); 

   return(0);

  }

BUT, when I put this into my indicator, it will never work!

How to get the angle of a Zigzag Perpendicular to a known line?

In my formula, use (delt Y) / (delt X) to calculate angle :
MathArctan
(MathTan(
((price1-price2)/(WindowPriceMax()- WindowPriceMin())) // is delt Y
/
((shift2-shift1)/WindowBarsPerChart()) // is delt X
))
*180/3.14

 

Okay, now I see where you are headed with this. The conversion factor that you are seeking is a function of the "Window" dimensions as it appears on your monitor.


You started in the right direction but did not finish. You are appropriately calculating the vertical scale (ie WindowPriceMax() - WindowPriceMin() ) but you have not calc'd the slope from the lower left corner to the upper right corner of your monitor. Therefore, the next step is to divide ( WindowPriceMax() - WindowPriceMin() ) by WindowBarsPerChart() This calc yields "X PIPs/Bar" which we will call the "StdSlope". Essentially, it is the StdSlope of your chart of your monitor.


The next step is to physically measure the chart on your monitor with a ruler. Measure from the lower left corner to the upper right corner. Calc that angle using trig; we'll call that angle the "StdAngle".


Now that you have established two known variables StdSlope and a StdAngle we begin the calculations for the "Conversion Factor"


Note: The conversion factor is based on a 45 degree angle because the Tan of 45 degrees is "1", but the StdAngle on your chart on computer monitor is probably in the mid-30's. Once you know how many PIPs/Bar it is for the StdAngle you can then determine how many PIPs/Bar it is for 45 degrees.


Using the sample chart below, where the StdAngle was 33.26 degrees ---- the calcs flow as follows:


Tan(33.26) = 0.6559


Conversion Factor = Tan(45) / Tan(StdAngle) * StdSlope = (1/ 0.6559 * X PIPS/Bar)






StdAngle = Arctan (chart height in inches or cm/chart width in inches or cm)


Tan(StdAngle) = ( WindowPriceMax() - WindowPriceMin() ) / WindowBarsPerChart() = StdSlope = X PIPs/Bar





All other slopes and angles must be calc'd as follows:


Slope A = ((Price1- Price 2)/Point) / (shift1-shift2);


Slope B = - (shift1 - shift2) / ((Price1-Price2)/Point);



Angle A = MathArctan( Slope A / Conversion Factor ) * (180/3.14159);


Angle B = MathArctan ( Slope B / Conversion Factor ) * (180/3.14159);




Let me know if you have any questions.


raft



d

 

Yes, thank you for given in detail.

raft