Trading days on bottom axis

Ideas and wishes for TeeChart
Post Reply
pssdelphi
Newbie
Newbie
Posts: 29
Joined: Thu Oct 21, 2004 4:00 am

Trading days on bottom axis

Post by pssdelphi » Mon Feb 26, 2007 3:37 pm

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.

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

Post by Narcís » Mon Feb 26, 2007 4:18 pm

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.
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

pssdelphi
Newbie
Newbie
Posts: 29
Joined: Thu Oct 21, 2004 4:00 am

Post by pssdelphi » Mon Feb 26, 2007 5:22 pm

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.

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

Post by Narcís » Mon Feb 26, 2007 5:26 pm

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?
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

pssdelphi
Newbie
Newbie
Posts: 29
Joined: Thu Oct 21, 2004 4:00 am

Post by pssdelphi » Mon Feb 26, 2007 7:03 pm

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;

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 Feb 27, 2007 8:18 am

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.
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

pssdelphi
Newbie
Newbie
Posts: 29
Joined: Thu Oct 21, 2004 4:00 am

Post by pssdelphi » Tue Feb 27, 2007 2:40 pm

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.

Post Reply