# Trendling Angle Calculation [Deleted]

I am trying to calculate the angle from a previous bars High/Low to the open of the next bar. Does this code look right?

double getAngleByType(int orderType) {
double changeInY;
double changeInX = 60;
int buyNormalizer = 90;
if (orderType == OP_BUY)
{
changeInY = MathAbs(Low - Open);
}
else if (orderType == OP_SELL)
{
changeInY = MathAbs(High - Open);
buyNormalizer = 0;
}

return (MathAbs( //MathArctan(
buyNormalizer - (MathTan(
changeInY / changeInX)) * (180 / 3.14159) * angleMultiplier));

It seems to me that visually the angle calculated isn't what I was expecting.

Thanks [Deleted]

jyett,

Is above me - maths side. But look at this thread which may well benifit you Help to calculate the slope of a line that is Perpendicular to a known line

Also phy gives good coverage in this thread Angled Trendlines

How to get the angle of a moving average?

afaik, Tovan has posted somewhere... (man! I cannot find it now) with link to good maths site). Will look some more but I definitely remember him doing this...

good luck

.

more:

Angle of 2 candles [Deleted]
fbj wrote >>

jyett,

Is above me - maths side. But look at this thread which may well benifit you Help to calculate the slope of a line that is Perpendicular to a known line

Also phy gives good coverage in this thread Angled Trendlines

How to get the angle of a moving average?

afaik, Tovan has posted somewhere... (man! I cannot find it now) with link to good maths site). Will look some more but I definitely remember him doing this...

good luck

.

more:

Angle of 2 candles

I will look into it, thanks! 170

jyett77:

I am trying to calculate the angle from a previous bars High/Low to the open of the next bar. Does this code look right?

double getAngleByType(int orderType) {
double changeInY;
double changeInX = 60;
int buyNormalizer = 90;
if (orderType == OP_BUY)
{
changeInY = MathAbs(Low - Open);
}
else if (orderType == OP_SELL)
{
changeInY = MathAbs(High - Open);
buyNormalizer = 0;
}

return (MathAbs( //MathArctan(
buyNormalizer - (MathTan(
changeInY / changeInX)) * (180 / 3.14159) * angleMultiplier));

It seems to me that visually the angle calculated isn't what I was expecting.

Thanks

jyett, I have devoted considerable time in developing a means for calculating angles. First, let me say this --- the 45 degree angle you see on your chart today will not be a 45 degree angle on your chart in a few days. The reason is all computer generated charts use variable scaling of the vertical scale where the price scale is located. They do this so the data takes up the entire screen. Thus, let's say for example that mathmatically, 1 PIP/Bar = 45 degrees. Sometimes that may visually look like a 45 degree angle on your screen, and sometimes it may visually look like a 60 degree angle --- it all depends on the pricing scale for the chart on your screen at that given moment. Now having said that, as you can now see, it is a complicated topic. What really does constitute a 45 degree angle? Well you're going to have to pick a number, and of course in doing so you do not want to be overly arbitrary. Here's what I did:

1) Downloaded the M15 data for EURUSD and opened the file in Excel - that's a quarter-million bars worth of data.

2) Calc'd a 100SMA, and manipulated the data to find how many trends exceeded 100 bars (ie 25 hrs)

3) Calc'd the average rate of change for the middle third of the trend (the part that tends to be the straightest)

4) Sorted those trends exceeding 100+ bars (approximately 1000 trends) by the newly calc'd rate of change for the middle-third, and decided to use the 500th rate of change (ie the one midway thru the sorted data) as the rate of change I would use for 45 degrees. Thus, for the M15 chart, I use 0.742 PIPs per Bar as the standard for a 45 degree angle.

It appears that you are trying to calc the angle from one bar to the next. I would avoid doing that. I am currently using a 5-bar average for calculating the angle, and even that is a bit jumpy (and that's a 5-bar average on the 100SMA line). I will most likely go to a 10-bar average as it produces a more consistent result.

Mathematically, the calculation is a follows:

If the current rate of change for the 5-bar average is 0.876 PIPs per bar, then the angle is:

Arctan(0.876/0.742)=49.7 degrees

An additional cautionary note: In periods of high volatility such as we have experienced in the last 6-9 months, you will get a lot of big angles, if you go to a period low volatility say 2006, the angles will not be as large. Therefore, volatility has a large impact on the angles that get calculated. So what works this year if you set some minimum threshold angle in your EA may not work next year.

Best regards, [Deleted]
FXtrader2008 wrote >>

jyett, I have devoted considerable time in developing a means for calculating angles. First, let me say this --- the 45 degree angle you see on your chart today will not be a 45 degree angle on your chart in a few days. The reason is all computer generated charts use variable scaling of the vertical scale where the price scale is located. They do this so the data takes up the entire screen. Thus, let's say for example that mathmatically, 1 PIP/Bar = 45 degrees. Sometimes that may visually look like a 45 degree angle on your screen, and sometimes it may visually look like a 60 degree angle --- it all depends on the pricing scale for the chart on your screen at that given moment. Now having said that, as you can now see, it is a complicated topic. What really does constitute a 45 degree angle? Well you're going to have to pick a number, and of course in doing so you do not want to be overly arbitrary. Here's what I did:

1) Downloaded the M15 data for EURUSD and opened the file in Excel - that's a quarter-million bars worth of data.

2) Calc'd a 100SMA, and manipulated the data to find how many trends exceeded 100 bars (ie 25 hrs)

3) Calc'd the average rate of change for the middle third of the trend (the part that tends to be the straightest)

4) Sorted those trends exceeding 100+ bars (approximately 1000 trends) by the newly calc'd rate of change for the middle-third, and decided to use the 500th rate of change (ie the one midway thru the sorted data) as the rate of change I would use for 45 degrees. Thus, for the M15 chart, I use 0.742 PIPs per Bar as the standard for a 45 degree angle.

It appears that you are trying to calc the angle from one bar to the next. I would avoid doing that. I am currently using a 5-bar average for calculating the angle, and even that is a bit jumpy (and that's a 5-bar average on the 100SMA line). I will most likely go to a 10-bar average as it produces a more consistent result.

Mathematically, the calculation is a follows:

If the current rate of change for the 5-bar average is 0.876 PIPs per bar, then the angle is:

Arctan(0.876/0.742)=49.7 degrees

An additional cautionary note: In periods of high volatility such as we have experienced in the last 6-9 months, you will get a lot of big angles, if you go to a period low volatility say 2006, the angles will not be as large. Therefore, volatility has a large impact on the angles that get calculated. So what works this year if you set some minimum threshold angle in your EA may not work next year.

Best regards,

Thanks FXtrader2008! This at least gives me a base line to look into. I completely agree that the angle on the screen DOES NOT LOOK like what we were calculating. I am going to try your method and see how I might be able to fit it into my stategy. The reason I am using it from previous bar to current bar is because it is designed as a filter rather then a signal generator. It really was suppose to be able help filter out bad positions. Once again thanks, I will try to report results if i find it works for my program. 541

After reading the entries here I am wondering if there is a way to calculate the absolute angle (the actual Line in line charts in my case) and use it in further calculations regardless of the scaling of the chart, the monitor aspect ratio etc?