Page 1 of 1
Trading days on bottom axis
Posted: Mon Feb 26, 2007 3:37 pm
by 9339638
It would be super nice to be able to have the bottom axis popular with only actual trading days (no weekends or holidays). Although I have spoofed this by something like the following skeleton code:
Code: Select all
sBars.XValues.DateTime:=False;
// add past chart before data
for j:=1 to DaysToExtend do
sBars.AddNull;
// add data bars
while (not alladded) do begin
sBars.AddOHLC(OpenD, HighD, LowD, CloseD);
sBars.XLabel[ sBars.Count-1 ]:= SDate;
...
end;
// add future dates but only week days & no holidays
for j:=1 to DaysToExtend do begin
{ calc SDate week days & no holidays }
.....
sBars.AddNull(SDate);
end;
While this works by itself, it does tend to make some functions like moving average, etc. not work.
It would be nice for all the financial programmers out there to have a more 'built in' in way of only showing actual days traded for the whole bottom axis and that would work with all the financial functions.
Posted: Mon Feb 26, 2007 4:18 pm
by narcis
Hi pssdelphi,
There's an example of what you request at All Features\Welcome!\Chart Styles\Financial\Candle (OHLC)\Axis Labels no Weekends in the features demo. You'll find the demo at TeeChart's program group created by the binary installer.
Posted: Mon Feb 26, 2007 5:22 pm
by 9339638
Yes, that is basically what I have done above without using the OnGetAxisLabel event for formatting, but if you add a function series to that example you pointed out (like moving average), youll see that the function does not plot.
Posted: Mon Feb 26, 2007 5:26 pm
by narcis
Hi pssdelphi,
It works fine for me here in the demo, double-clicking on the yellowish memo to open the chart editor and add a moving average function to the chart having Series1 as source series. Does this work at your end?
Posted: Mon Feb 26, 2007 7:03 pm
by 9339638
Interesting, it does work inside the demo that way, but outside, it is not for me..what am I missing?
My suggestion for future was to add options for trading dates (like in the Chart -> Axis -> Scales section) just to compliment the financial portion of your package.
This does not plot the moving average line when the program is running, if you uncomment the Series1.FillSampleValues(100); and Series1.XValues.DateTime:=true; and comment out the rest of the code in the procedure it works as expected:
Code: Select all
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, TeEngine, Series, OHLChart, CandleCh, ExtCtrls, TeeProcs, Chart,
StatChar;
type
TForm1 = class(TForm)
Chart1: TChart;
Series1: TCandleSeries;
Series2: TLineSeries;
TeeFunction1: TMovingAverageFunction;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var tmpOpen : Double;
tmpClose : Double;
t : Integer;
tmpYear : Word;
tmpMonth : Word;
tmpDay : Word;
begin
// Series1.FillSampleValues(100);
// Series1.XValues.DateTime:=true;
Series1.XValues.DateTime:=False;
tmpOpen:=Random(1000);
Series1.Clear;
for t:=1 to 100 do
begin
tmpOpen :=tmpOpen+(Random(100)-50);
tmpClose:=tmpOpen-(Random(100)-50);
Series1.AddCandle( t, tmpOpen, tmpOpen+Random(10),
tmpClose-Random(10), tmpClose );
DecodeDate(Date+t, tmpYear, tmpMonth, tmpDay );
Series1.Labels[ Series1.Count-1 ]:= FormatFloat('0000',tmpYear)+
FormatFloat('00',tmpMonth)+
FormatFloat('00',tmpDay);
end;
end;
Posted: Tue Feb 27, 2007 8:18 am
by narcis
Hi pssdelphi,
This is because after populating your series you need to call CheckDataSource method for the function series, this works:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
var tmpOpen : Double;
tmpClose : Double;
t : Integer;
tmpYear : Word;
tmpMonth : Word;
tmpDay : Word;
begin
// Series1.FillSampleValues(100);
// Series1.XValues.DateTime:=true;
Series1.XValues.DateTime:=False;
tmpOpen:=Random(1000);
Series1.Clear;
for t:=1 to 100 do
begin
tmpOpen :=tmpOpen+(Random(100)-50);
tmpClose:=tmpOpen-(Random(100)-50);
Series1.AddCandle( t, tmpOpen, tmpOpen+Random(10),
tmpClose-Random(10), tmpClose );
DecodeDate(Date+t, tmpYear, tmpMonth, tmpDay );
Series1.Labels[ Series1.Count-1 ]:= FormatFloat('0000',tmpYear)+
FormatFloat('00',tmpMonth)+
FormatFloat('00',tmpDay);
end;
Series2.CheckDataSource;
end;
My suggestion for future was to add options for trading dates (like in the Chart -> Axis -> Scales section) just to compliment the financial portion of your package.
Ok, I'll add your request to our wish-list to be considered for inclusion in future releases.
Posted: Tue Feb 27, 2007 2:40 pm
by 9339638
Thanks for showing me the solution for that.
It is interesting that the copy function in the same circumstances does not need the call to CheckDataSource to work properly, which I have used alot.