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
double a0=iCustom(NULL, 0, "Zigzag2_R_", ExtDepth, ExtDeviation, ExtBackstep, 0, i);
double a1=iCustom(NULL, 0, "Zigzag2_R_", ExtDepth, ExtDeviation, ExtBackstep, 1, i);
double k = (-1/(PL-PH)/(Time[L]-Time[H]));
double kbbs =yyx-(-1/(PL-PH)/(Time[L]-Time[H]))*(Time[Ox]-Time[H]);
}
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
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
Yes, thank you for given in detail.
raft
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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!