Fibonacci Retracement v7

TeeChart for ActiveX, COM and ASP
Post Reply
Rossmc
Newbie
Newbie
Posts: 23
Joined: Thu Mar 30, 2006 12:00 am

Fibonacci Retracement v7

Post by Rossmc » Tue Jul 18, 2006 7:23 am

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

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Tue Jul 18, 2006 7:38 am

Hi Rossmc,

Using DrawLines tool may be helpful to draw those lines. Another option would be custom drawing on TeeChart's canvas.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Rossmc
Newbie
Newbie
Posts: 23
Joined: Thu Mar 30, 2006 12:00 am

RE: Retracement with Drawlines

Post by Rossmc » Tue Jul 18, 2006 9:13 am

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

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Mon Jul 24, 2006 8:42 am

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.

Rossmc
Newbie
Newbie
Posts: 23
Joined: Thu Mar 30, 2006 12:00 am

Drawlines Tool

Post by Rossmc » Mon Jul 24, 2006 10:18 am

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?

Rossmc
Newbie
Newbie
Posts: 23
Joined: Thu Mar 30, 2006 12:00 am

Solved!

Post by Rossmc » Mon Jul 24, 2006 1:14 pm

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

Post Reply