The code I have written allows the user to identify two points on a chart, using date, time and price to identify the location, and then drawing a trendline between those two points.
Here is the code:
Code: Select all
Inputs: PointADate("03/14/2012"), PointATime(2045), PointAPrice(1391);
Inputs: PointBDAte("03/14/2012"), PointBTime(2345), PointBPrice(1393.50);
Inputs: LineColor(DarkBlue), LineWidth(2);
Inputs: RotateAngle(0);
Variables: PointCDate(0), PointCTime(0), PointCPrice(0), PointCBarNum(0);
Variables: PointDDate(0), PointDTime(0), PointDPrice(0), PointDBarNum(0);
Variables: TempADate(0), TempBDate(0),TestDate(0);
Variables: Line1_ID(0);
If BarNumber = 1 Then Begin
TestDate = StringToDate(PointADate);
TempADate = JulianToDate(TestDate);
TestDate = StringToDate(PointBDate);
TempBDate = JulianToDate(TestDate);
End;
If Date = TempADate And Time = PointATime Then Begin
If PointCDate <> 0 Then Begin
PointDDate = Date;
PointDTime = Time;
PointDPrice = PointAPrice;
PointDBarNum = BarNumber;
End;
If PointCDate = 0 Then Begin
PointCDate = Date;
PointCTime = Time;
PointCPrice = PointAPrice;
PointCBarNum = BarNumber;
End;
End;
If Date = TempBDate And Time = PointBTime Then Begin
If PointCDate <> 0 Then Begin
PointDDate = Date;
PointDTime = Time;
PointDPrice = PointBPrice;
PointDBarNum = BarNumber;
End;
If PointCDate = 0 Then Begin
PointCDate = Date;
PointCTime = Time;
PointCPrice = PointBPrice;
PointCBarNum = BarNumber;
End;
End;
If LastBarOnChart = TRUE Then begin
Line1_ID = TL_new(PointCDate,PointCTime,PointCPrice,PointDDate,PointDTime,PointDPrice);
value1 = TL_SetColor(Line1_ID,LineColor);
value1 = TL_SetSize(Line1_ID,LineWidth);
End;
I have seen that the formula for rotating a line about an axis is as follows:
x' = x Cos(θ) - y Sin(θ)
y' = x Sin(θ) + y Cos(θ)
The problem I have is that I don't know how to rotate this line using the coordinate system of price vs. bar number.
In other words, the way to calculate the new bar number (x') incorporates both a price level and a bar number - these are two different units, but the traditional rotation formula presented above is based on having the x-axis and y-axis being of the same units.
Does anyone have any thoughts or suggestions on how to reconcile calculations using two different unit types?
Thanks!