I created some indicators that calculate the angle/steepness of a line/trendline.
I use this code, that works fine für time based charts (like minute charts).
Code: Select all
....
double x1 = BarsOfData(0).Time[highestCumIndex].Ticks / TimeSpan.TicksPerMillisecond;
double x2 = BarsOfData(0).Time[0].Ticks / TimeSpan.TicksPerMillisecond;
angle = CalcAngle(x1, x2, highestCum, BarsOfData(0).CloseValue);
....
double CalcAngle(double x1, double x2, double y1, double y2)
{
double xDiff = x2 - x1;
double yDiff = Math.Abs(y2 - y1);
const double Rad2Deg = 180.0 / Math.PI;
double result = Math.Atan2(yDiff, xDiff/10000) * Rad2Deg;
result = Math.Round(Math.Abs(result), 1);
return result;
}
Does anyone knows a trick to calculate the angle of a line correctly in tick charts?
Thanks in advance
Ingo