Page 1 of 1

Fibonacci Retracement v7

Posted: Tue Jul 18, 2006 7:23 am
by 9530819
Hi

I need to draw a Fibonacci retracement on my financial chart. I'm just looking for some advice on the best method to use to draw the required lines?

Thanks

Posted: Tue Jul 18, 2006 7:38 am
by narcis
Hi Rossmc,

Using DrawLines tool may be helpful to draw those lines. Another option would be custom drawing on TeeChart's canvas.

RE: Retracement with Drawlines

Posted: Tue Jul 18, 2006 9:13 am
by 9530819
Hi Narcis

Once again thanks for always being so helpful, it's REALLY appreciated.

I have decided to use Drawlines since, if I have it right, they are quite well suited as the user draws the base line and then I programatically AddLine's to the base line's Lines collection. So far, so good.

It seems it then makes the last line in the lines collection the 'control' line. For example to delete all the lines I have to select the last line added and then press delete. Is there some way to make sure the user has to select the first line that they drew to delete?

Lastly, as my app is relatively complex, there could be multiple DrawLine tools added for other reasons. Is there a way to uniquely identify drawlines other than through their Tools index?

Thanks again

Posted: Mon Jul 24, 2006 8:42 am
by Pep
Hi,
to select the last line added and then press delete. Is there some way to make sure the user has to select the first line that they drew to delete?
How abou using similar code to :

Code: Select all

Private Sub Command1_Click()
i = TChart1.Tools.Items(0).asDrawLine.Selected
If i = 0 Then
TChart1.Tools.Items(0).asDrawLine.DeleteSelected
End If
End Sub
Lastly, as my app is relatively complex, there could be multiple DrawLine tools added for other reasons. Is there a way to uniquely identify drawlines other than through their Tools index?
I'm afraid there's not other way.

Drawlines Tool

Posted: Mon Jul 24, 2006 10:18 am
by 9530819
Is the drawline tool known to have problems, or is it just me? I eventually worked out that the asDrawline.Selected property returns 0 when the line IS selected and -1 when it is NOT which is exactly the opposite of VB's TRUE and FALSE constants.

It seems there is no way to programatically set a line to NOT selected though, unless I pass a 0 to that property I get an Index error?!

What I want to do is popup a context-sensitive menu when the user right-clicks on a drawline and also know which drawline they clicked so I can change it's properties. The Index parameter of the _OnDrawLineToolSelecting event seems to always be 0?

Solved!

Posted: Mon Jul 24, 2006 1:14 pm
by 9530819
I worked it out with a little bit of homework and help from my friends :) Thought I'd post for some future readers benefit. On the mouse up event, if the button is the right mouse button I call the following code to see if the point clicked is on a drawline: (The variables are a little OTT but it was just for readability while developing)

Private Function Trendline_Clicked(X As Long, Y As Long) As Boolean
Dim i As Long
Dim x1 As Double
Dim x2 As Double
Dim y1 As Double
Dim y2 As Double
Dim yClicked As Double
Dim yInvert As Double
Dim c1 As Double
Dim c2 As Double
Dim c3 As Double
Dim m As Double
Dim t As Double

With taMain.Tools
For i = 0 To .Count - 1
If .Items(i).ToolType = tcDrawLine Then
yInvert = taMain.Axis.Left.CalcYPosValue(taMain.Axis.Left.Minimum)

x1 = .Items(i).asDrawLine.FromPoint.X
x2 = .Items(i).asDrawLine.ToPoint.X
y1 = yInvert - .Items(i).asDrawLine.FromPoint.Y
y2 = yInvert - .Items(i).asDrawLine.ToPoint.Y
yClicked = yInvert - Y

'y = mx + c

m = Abs((y2 - y1) / (x2 - x1)) 'm=gradient
c1 = y1 - (m * x1) 'c=y intercept point
c2 = y2 - (m * x2)
c3 = yClicked - (m * X)

If Round(c3) >= Round(c1) - 1 And Round(c3) <= Round(c1) + 1 Then
Trendline_Clicked = True
Exit For
End If

End If
Next i
End With

End Function