home *** CD-ROM | disk | FTP | other *** search
- {*********************************************}
- { TeeChart Delphi Component Library }
- { Stock Candle Series Type Demo }
- { Copyright (c) 1995-1997 by David Berneda }
- { All rights reserved }
- {*********************************************}
- unit Candle;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, Chart, Series, ExtCtrls, StatChar, StdCtrls, OHLChart,
- CandleCh, Teengine, Buttons, teeprocs, TeeComma;
-
- type
- TCandleForm = class(TForm)
- Chart1: TChart;
- Panel1: TPanel;
- CheckBox1: TCheckBox;
- Timer1: TTimer;
- CandleSeries1: TCandleSeries;
- RadioGroup1: TRadioGroup;
- VolumeSeries1: TVolumeSeries;
- Chart2: TChart;
- CBShowOpens: TCheckBox;
- CBShowCloses: TCheckBox;
- CheckBox2: TCheckBox;
- CheckBox3: TCheckBox;
- CheckBox4: TCheckBox;
- CheckBox5: TCheckBox;
- RSISeries1: TLineSeries;
- TeeFunction1: TRSIFunction;
- MovingAverageSeries1: TLineSeries;
- TeeFunction2: TMovingAverageFunction;
- TeeCommander1: TTeeCommander;
- BitBtn3: TBitBtn;
- procedure FormCreate(Sender: TObject);
- procedure CheckBox1Click(Sender: TObject);
- procedure Timer1Timer(Sender: TObject);
- procedure RadioGroup1Click(Sender: TObject);
- procedure Chart2GetNextAxisLabel(Sender: TChartAxis;
- LabelIndex: Longint; var LabelValue: Double; var Stop: Boolean);
- procedure CBShowClosesClick(Sender: TObject);
- procedure CBShowOpensClick(Sender: TObject);
- procedure CheckBox2Click(Sender: TObject);
- procedure CheckBox3Click(Sender: TObject);
- procedure Chart1UndoZoom(Sender: TObject);
- procedure Chart1Zoom(Sender: TObject);
- procedure Chart1Scroll(Sender: TObject);
- procedure CheckBox4Click(Sender: TObject);
- procedure CheckBox5Click(Sender: TObject);
- procedure Chart2DblClick(Sender: TObject);
- procedure BitBtn3Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- Procedure AddNewRandomCandle;
- end;
-
- implementation
-
- {$R *.DFM}
-
- Uses EditChar,CandlEdi; { <-- for Chart & Series Editing }
-
- { This method adds a new Candle point to the Series }
- { Calculates random Open, High, Low and Close values }
- Procedure TCandleForm.AddNewRandomCandle;
- Var AOpen,AClose,AHigh,ALow:Double;
- Begin
- With CandleSeries1 do
- begin
- if Count>0 then AOpen:=CloseValues.Last+Random(10)-5
- else AOpen:=Random(10000);
- GetRandomOHLC(AOpen,AClose,AHigh,ALow,10000);
- { Add a new random OHLC point }
- if Count>0 then AddOHLC(XValues.Last+1,AOpen,AHigh,ALow,AClose)
- else AddOHLC(Date,AOpen,AHigh,ALow,AClose);
- { Recalculate RSI and Moving Average }
- RefreshSeries;
- end;
- end;
-
- procedure TCandleForm.FormCreate(Sender: TObject);
- var t:Longint;
- begin
- { This means RSI and moving average will NOT be recalculated when
- deleting Candle points }
- With RSISeries1 do RecalcOptions:=RecalcOptions-[rOnDelete];
- With MovingAverageSeries1 do RecalcOptions:=RecalcOptions-[rOnDelete];
-
- With CandleSeries1 do
- for t:=1 to NumSampleValues do { <-- Some random points }
- AddNewRandomCandle;
-
- With VolumeSeries1 do
- for t:=1 to NumSampleValues do { <-- Some random points }
- AddXY(Date+t-1,100+Random(1000),'',clTeeColor);
-
- { set volume series vertical axis maximum to ten times max volume value }
- { this will draw volume series on the chart bottom }
- VolumeSeries1.GetVertAxis.SetMinMax(0,10000);
-
- { Date Time Axis support }
- Chart1.BottomAxis.ExactDateTime:=True;
- Chart1.BottomAxis.Increment:=DateTimeStep[dtOneMonth];
- Chart1.BottomAxis.DateTimeFormat:='mmm/yy';
-
- { Date Time Axis support }
- Chart2.BottomAxis.ExactDateTime:=True;
- Chart2.BottomAxis.Increment:=DateTimeStep[dtOneMonth];
- Chart2.BottomAxis.DateTimeFormat:='mm-yyyy';
- end;
-
- procedure TCandleForm.CheckBox1Click(Sender: TObject);
- begin
- Timer1.Enabled:=CheckBox1.Checked; { <-- on / off animation }
- if Timer1.Enabled then
- begin
- Chart1.UndoZoom;
- Chart2.UndoZoom;
- end;
- end;
-
- procedure TCandleForm.Timer1Timer(Sender: TObject);
- begin
- Timer1.Enabled:=False;
- With CandleSeries1 do
- Begin
- Delete(0); { <-- remove the first point }
-
- { If the MovingAverage RecalcOptions property contains the [rOnDelete]
- recalc option, then MovingAverage will be cleared and recalculated.
- If not, we should manually remove the first MovingAverage point.
- }
- if not (rOnDelete in MovingAverageSeries1.RecalcOptions) then
- MovingAverageSeries1.Delete(0);
- { Same as above, but with the RSI series }
- if not (rOnDelete in RSISeries1.RecalcOptions) then
- RSISeries1.Delete(0);
- AddNewRandomCandle;
-
- if Random(10)<2 then
- DownCloseColor:=ColorPalette[1+Random(MaxDefaultColors)];
- if Random(10)<2 then
- UpCloseColor:=ColorPalette[1+Random(MaxDefaultColors)];
- end;
- With VolumeSeries1 do
- Begin
- Delete(0);
- AddXY(XValues.Last+1,100+Random(1000),'',clTeeColor);
- RefreshSeries;
- end;
- Timer1.Enabled:=True;
- end;
-
- procedure TCandleForm.RadioGroup1Click(Sender: TObject);
- begin { change the candle series style }
- if RadioGroup1.ItemIndex=0 then
- CandleSeries1.CandleStyle:=csCandleStick
- else
- CandleSeries1.CandleStyle:=csCandleBar;
-
- { Open and Close allowed only with Candle Bars }
- CBShowOpens.Enabled:=RadioGroup1.ItemIndex=1;
- CBShowCloses.Enabled:=RadioGroup1.ItemIndex=1;
- end;
-
- procedure TCandleForm.Chart2GetNextAxisLabel(Sender: TChartAxis;
- LabelIndex: Longint; var LabelValue: Double; var Stop: Boolean);
- begin
- if Sender=Chart2.RightAxis then
- Begin
- Stop:=False;
- { this demonstrates how to draw the 20% and 80% RSI axis labels only }
- Case LabelIndex of
- 0: LabelValue:=20.0;
- 1: LabelValue:=80.0;
- else Stop:=True;
- end;
- end;
- end;
-
- procedure TCandleForm.CBShowClosesClick(Sender: TObject);
- begin
- CandleSeries1.ShowCloseTick:=CBShowCloses.Checked;
- end;
-
- procedure TCandleForm.CBShowOpensClick(Sender: TObject);
- begin
- CandleSeries1.ShowOpenTick:=CBShowOpens.Checked;
- end;
-
- procedure TCandleForm.CheckBox2Click(Sender: TObject);
- begin
- Chart1.View3d:=CheckBox2.Checked;
- if Chart1.View3D then Chart1.BackColor:=clYellow
- else Chart1.BackColor:=clTeeColor;
- end;
-
- procedure TCandleForm.CheckBox3Click(Sender: TObject);
- begin
- Chart1.BottomAxis.ExactDateTime:=CheckBox3.Checked;
- if CheckBox3.Checked then
- Chart1.BottomAxis.DateTimeFormat:='mmm/yy'
- else
- Chart1.BottomAxis.DateTimeFormat:='dd/mm/yy';
- Chart2.BottomAxis.ExactDateTime:=CheckBox3.Checked;
- if CheckBox3.Checked then
- Chart2.BottomAxis.DateTimeFormat:='mm-yyyy'
- else
- Chart2.BottomAxis.DateTimeFormat:='mmm-dd';
- end;
-
- procedure TCandleForm.Chart1UndoZoom(Sender: TObject);
- begin
- VolumeSeries1.GetVertAxis.SetMinMax(0,10000);
- end;
-
- procedure TCandleForm.Chart1Zoom(Sender: TObject);
- begin
- if not CheckBox5.Checked then
- VolumeSeries1.GetVertAxis.SetMinMax(0,10000);
- end;
-
- procedure TCandleForm.Chart1Scroll(Sender: TObject);
- begin
- if not CheckBox5.Checked then
- VolumeSeries1.GetVertAxis.SetMinMax(0,10000);
- end;
-
- procedure TCandleForm.CheckBox4Click(Sender: TObject);
- begin
- Chart1.BottomAxis.RoundFirstLabel:=CheckBox4.Checked;
- Chart2.BottomAxis.RoundFirstLabel:=CheckBox4.Checked;
- if not CheckBox4.Checked then CheckBox3.Checked:=False;
- Chart1.Repaint;
- Chart2.Repaint;
- end;
-
- procedure TCandleForm.CheckBox5Click(Sender: TObject);
- begin
- if not CheckBox5.Checked then VolumeSeries1.GetVertAxis.SetMinMax(0,10000);
- end;
-
- procedure TCandleForm.Chart2DblClick(Sender: TObject);
- begin
- EditChart(Self,Chart2);
- end;
-
- procedure TCandleForm.BitBtn3Click(Sender: TObject);
- begin
- Close;
- end;
-
- end.
-