Page 1 of 1
Fibonacci tool - levels and drag mouse
Posted: Wed Nov 04, 2009 4:56 pm
by 10554474
Hi guys,
I want to add more levels in the default three levels avaiable on the fibonacci tool, but when i add more levels they desapear when I open
the tool again.
Do someone know how I can add more levels in the fibonacci tool?
Another question is about drag mouse on the chart and draw a rectangle. Is this possible?
Thanks
Ronaldo HP
Re: Fibonacci tool - levels and drag mouse
Posted: Thu Nov 05, 2009 10:32 am
by yeray
Hi Ronaldo,
ronaldohp wrote:I want to add more levels in the default three levels avaiable on the fibonacci tool, but when i add more levels they desapear when I open
the tool again.
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.View3D:=false;
Series1.FillSampleValues(25);
ChartTool1.Series:=Series1;
ChartTool1.StartX:=Series1.DateValues[5];
ChartTool1.StartY:=Series1.CloseValues[5];
ChartTool1.EndX:=Series1.DateValues[15];
ChartTool1.EndY:=Series1.CloseValues[15];
ChartTool1.Levels.Add;
ChartTool1.Levels[ChartTool1.Levels.Count-1].Value:=70.5;
end;
ronaldohp wrote:Another question is about drag mouse on the chart and draw a rectangle. Is this possible?
Yes, you should use OnMouseDown, OnMouseMove, OnMouseUp and OnAfterDraw events to do it. Here in the forums you will find some examples:
http://www.teechart.net/support/viewtop ... f=3&t=9421
Re: Fibonacci tool - levels and drag mouse
Posted: Fri Nov 06, 2009 7:22 pm
by 10554474
Well, thanks by the usefull answer, but I would to specify my question:
I want to draw a rectangle dragging the mouse over a graphic and in the same time draw the lines of Fibonacci levels.
The started point, for example, will be the most lower price of a candle chart and the ended point will be the most high price of the trend,
and while I move the mouse from lower to high points the lines level of Fibonacci will be drawed.
Thanks for the help
Ronaldo HP
Re: Fibonacci tool - levels and drag mouse
Posted: Mon Nov 09, 2009 12:39 pm
by yeray
Hi Rolando,
Please take a look at this example but note that the conditions at OnAfterDraw should be probably refined:
Code: Select all
uses series, CandleCh, TeeFibonacci;
var Series1: TCandleSeries;
ChartTool1: TFibonacciTool;
XStart, XEnd, YStart, YEnd: Integer;
DrawRect: Boolean;
RectToDraw: TRect;
procedure TForm1.FormCreate(Sender: TObject);
begin
Series1:=Chart1.AddSeries(TCandleSeries.Create(self)) as TCandleSeries;
ChartTool1:=Chart1.Tools.Add(TFibonacciTool.Create(self)) as TFibonacciTool;
Chart1.View3D:=false;
Series1.FillSampleValues(25);
ChartTool1.Series:=Series1;
XStart:=-1;
XEnd:=-1;
YStart:=-1;
YEnd:=-1;
DrawRect:=false;
Chart1.Zoom.Allow:=false;
end;
procedure TForm1.Chart1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
If DrawRect then
begin
DrawRect := false;
RectToDraw.Left := XStart;
RectToDraw.Top := YStart;
RectToDraw.Right := XEnd;
RectToDraw.Bottom := YEnd;
end;
end;
procedure TForm1.Chart1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
DrawRect := True;
XStart := X;
YStart := Y;
end;
procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if DrawRect then
begin
XEnd := X;
YEnd := Y;
Chart1.Draw;
end;
end;
procedure TForm1.Chart1AfterDraw(Sender: TObject);
var i: Integer;
tmp: Double;
begin
if DrawRect then
begin
Chart1.Canvas.Pen.Color := clBlack;
Chart1.Canvas.Brush.Style := bsClear;
Chart1.Canvas.Rectangle(XStart,YStart,XEnd,YEnd);
tmp:=Chart1.Axes.Bottom.CalcPosPoint(XStart);
for i:=0 to Series1.Count-1 do
if Series1.XValue[i] > tmp then
break;
ChartTool1.StartX:=Series1.DateValues[i];
tmp:=Chart1.Axes.Left.CalcPosPoint(YStart);
for i:=0 to Series1.Count-1 do
if Series1.YValue[i] > tmp then
break;
ChartTool1.StartY:=Series1.CloseValues[i];
tmp:=Chart1.Axes.Bottom.CalcPosPoint(XEnd);
for i:=0 to Series1.Count-1 do
if Series1.XValue[i] > tmp then
break;
ChartTool1.EndX:=Series1.DateValues[i-1];
tmp:=Chart1.Axes.Left.CalcPosPoint(YEnd);
for i:=0 to Series1.Count-1 do
if Series1.YValue[i] > tmp then
break;
ChartTool1.EndY:=Series1.CloseValues[i-1];
end;
end;