Angle of a trend

 

Hello,

I'm trying to calculate the angle of a trend. I've tried using the price difference in points as the height of the triangle formed and the number of periods as the base then finding the tangent inverse but since the height and the base are fundamentally measured in different units i feel my results is not accurate. Some one please advise me.

 
 

Can't is a word i don't like in my vocabulary. Is there no library i can use to get the pixel coordinates of the points on the chart??.

 
Lema_Carl:

Can't is a word i don't like in my vocabulary. Is there no library i can use to get the pixel coordinates of the points on the chart??.

OK, you can . . . but it makes zero logical sense.

What might make sense is to calculate the slope . . . gradient if you like . .

Other than that, you can get the window size in pixels using . . .

#import "user32.dll"
int GetWindowRect(int hWnd, int rect[4]); // Get window dimensions (x,y -> x,y)
#import

int WindowDims[4];            // used to store window coordinates from "user32.dll"

if (IsDllsAllowed()) 
   {
   GetWindowRect(WindowHandle(Symbol(), Period()), WindowDims);
   SizeX = WindowDims[2] - WindowDims[0];
   SizeY = WindowDims[3] - WindowDims[1];
   }
else Print("DLLs not allowed ! !");

and the window price max and min with the WindowPriceMax() WndowPriceMin() functions . . . and the bar numbers from WindowsBarPerChart() and WindowFirstVisibleBar() . . . and then when you change timeframe or zoom you can calculate all this lot all over again to get the new meaningless angle . . . enjoy.

 
I'm trying to make sense of the code above but if I can use it to calculate the gradient then I think that solves the problem because irrespective of whether you zoom in or out the gradient remains the same. And by the same logic so does the angle because all triangles on the same slope have the same angle. Right?
 
Lema_Carl:
And by the same logic so does the angle because all triangles on the same slope have the same angle. Right?

Exactly. In situations were there exists an angle (because x and y are of the same dimension) then there would be a fixed relationship between slope and the angle and same slope would result in same angle. But since in the chart there exists no meaningful definition of angle you only have the slope but you can use the slope for all intents and purposes you would otherwise have wanted to use an angle.

The dimension of the slope would be something like dPrice/dt (for example pips per day) which makes perfect sense and its meaning is intuitive to understand and also used elsewhere where the rate of growth of something is measured.

 
7bit:

Exactly. In situations were there exists an angle (because x and y are of the same dimension) then there would be a fixed relationship between slope and the angle and same slope would result in same angle. But since in the chart there exists no meaningful definition of angle you only have the slope but you can use the slope for all intents and purposes you would otherwise have wanted to use an angle.

The dimension of the slope would be something like dPrice/dt (for example pips per day) which makes perfect sense and its meaning is intuitive to understand and also used elsewhere where the rate of growth of something is measured.



What do you think what will happen with zoom in and zoom out with WindowPriceMax() WndowPriceMin()
 
Angle=0;

if (IsDllsAllowed())
{
GetWindowRect(WindowHandle(Symbol(), Period()), WindowDims);
int SizeX = WindowDims[2] - WindowDims[0];
int SizeY = WindowDims[3] - WindowDims[1];
}
else
Print("DLLs not allowed ! !");

double Pixels_Per_Point=SizeY/((WindowPriceMax()-WindowPriceMin())/Point);
double Pixels_Per_Bar=SizeX/WindowBarsPerChart();

double Price_1=iClose(Symbol(),0,WindowBarsPerChart()-1),Price_2=iClose(Symbol(),0,1),
Point_Diff=(Price_2-Price_1)/Point;
int Bar_Diff=WindowBarsPerChart()-1;

double Point_Diff_In_Pixels=Point_Diff*Pixels_Per_Point,
Bar_Diff_In_Pixels=Bar_Diff*Pixels_Per_Bar;

if(Point_Diff > 0){
Angle=57.2957795*MathArctan(Point_Diff_In_Pixels/Bar_Diff_In_Pixels);
Print("Buy trend at ",Angle," degrees");
return;
}
else{
Angle=MathAbs(57.2957795*MathArctan(Point_Diff_In_Pixels/Bar_Diff_In_Pixels));
Print("Sell trend at ",Angle," degrees");
return;

}
The function recalculates the Pixels per point and pixels per bar each time its called. The zooming in and out isn't necessarily a bad thing because that just determines how many bars back it calculates the angle of the trend since the bars per chart stay constant for a particular zoom. My only problem is that the difference between WindowPriceMax() and WindowPriceMin() changes as you scroll which doesnt make sense if the window dimensions are constant??