Bottom Axis without weekends, but with null data

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
vlaho
Newbie
Newbie
Posts: 9
Joined: Wed Jun 25, 2008 12:00 am
Contact:

Bottom Axis without weekends, but with null data

Post by vlaho » Wed Oct 29, 2008 10:32 am

Hello,

I have a problem with Candle Series and maybe some other. I want to display OHLC chart with some upper indicators (moving average, bollinger...) and some indicators below (like volume, MACD OBV, some custom functions...). They all share the same horizontal axis and it is not problem if I take only valid data into Series (like no weekends example).

But, if I want to display all datetime intervals, even with no data, I have a problem.

For example, in the following code, Candle is wrong (data for non-existing days must not be shown or can be shown as some 'x' mark), and Volume is ok (not shown).

Code: Select all

DataTable dataTable = new DataTable();
dataTable.Columns.Add("Date", typeof(DateTime));
dataTable.Columns.Add("Open", typeof(double));
dataTable.Columns.Add("High", typeof(double));
dataTable.Columns.Add("Low", typeof(double));
dataTable.Columns.Add("Close", typeof(double));
dataTable.Columns.Add("Volume", typeof(double));

dataTable.Rows.Add(DateTime.Now.Date.AddDays(-9), 10, 12, 9, 11, 2);
dataTable.Rows.Add(DateTime.Now.Date.AddDays(-8), 10, 12, 9, 11, 3);
dataTable.Rows.Add(DateTime.Now.Date.AddDays(-1), 10, 12, 9, 11, 4);
dataTable.Rows.Add(DateTime.Now.Date, 10, 12, 9, 11, 5);

Candle candleSeries1 = new Candle(tChart1);
candleSeries1.XValues.DateTime = false;

Volume volumeSeries1 = new Volume(tChart1);

Steema.TeeChart.Styles.StringList labels = new Steema.TeeChart.Styles.StringList();

DateTime dateFrom = DateTime.Date.Now.AddDays(-10);
DateTime dateTo = DateTime.Date.Now;

TimeSpan ts = dateTo - dateFrom;

int dataCount = 0;
int j = 0;

for (int i = 0; i <= ts.Days; i++)
        {
            DateTime dataDay = dateFrom.Date.AddDays(i);
            if (dataDay.DayOfWeek != DayOfWeek.Saturday && dataDay.DayOfWeek != DayOfWeek.Sunday)
            {
                if (dataTable.Rows.Count > j)
                {
                    DataRow row = dataTable.Rows[j];
                    DateTime dayTemp = (DateTime)row["Date"];

                    if (dataDay == dayTemp)
                    {
                        candleSeries1.Add(dataCount,
                            (double)row["Open"],
                            (double)row["High"],
                            (double)row["Low"],
                            (double)row["Close"]);
                        volumeSeries1.Add(dataCount, (double)row["Volume"]);
                        j++;
                    }
                    else // add empty data
                    {
                        candleSeries1.Add();
                        volumeSeries1.Add();
                    }

                    labels.Add(dataDay.ToShortDateString());
                }

                dataCount++;
            }
        }
candleSeries1.Labels = labels;
Is there any workaround or maybe I'm doing something wrong?

Goran

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

Post by Narcís » Thu Oct 30, 2008 11:19 am

Hi Goran,

Sorry but I may not understand which is the exact problem with the code snippet you posted. Coul you please give us some more details about what you expect?

Thanks in advance.
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

vlaho
Newbie
Newbie
Posts: 9
Joined: Wed Jun 25, 2008 12:00 am
Contact:

Post by vlaho » Thu Oct 30, 2008 12:38 pm

Hi Narcís

I uploaded example web page and images what I get and what I need, to your upload page (http://www.steema.net/upload). I seems that what I need is combination of two versions of my code... with "else" and without "else".
I included ExpMovAverage function. For this data it has to be straight line.

File name is ohlcProblem.rar

I hope this explains my problem.

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 » Fri Oct 31, 2008 3:04 pm

Hi Goran,

You can achieve what you request using this code:

Code: Select all

        protected void Page_Load(object sender, EventArgs e)
        {
            Steema.TeeChart.Chart tChart1;
            tChart1 = WebChart1.Chart;

						DataTable dataTable = new DataTable();
						dataTable.Columns.Add("Date", typeof(DateTime));
						dataTable.Columns.Add("Open", typeof(double));
						dataTable.Columns.Add("High", typeof(double));
						dataTable.Columns.Add("Low", typeof(double));
						dataTable.Columns.Add("Close", typeof(double));
						dataTable.Columns.Add("Volume", typeof(double));

						dataTable.Rows.Add(DateTime.Now.Date.AddDays(-9), 10, 12, 9, 11, 2);
						dataTable.Rows.Add(DateTime.Now.Date.AddDays(-8), 10, 12, 9, 11, 3);
						dataTable.Rows.Add(DateTime.Now.Date.AddDays(-1), 10, 12, 9, 11, 4);
						dataTable.Rows.Add(DateTime.Now.Date, 10, 12, 9, 11, 5);

						Candle candleSeries1 = new Candle(tChart1);
						candleSeries1.XValues.DateTime = false;

						Volume volumeSeries1 = new Volume(tChart1);

						Steema.TeeChart.Styles.StringList labels = new Steema.TeeChart.Styles.StringList();

						DateTime dateFrom = DateTime.Now.AddDays(-10);
						DateTime dateTo = DateTime.Now;

						TimeSpan ts = dateTo - dateFrom;

						int dataCount = 0;
						int j = 0;

						for (int i = 0; i <= ts.Days; i++)
						{
							DateTime dataDay = dateFrom.Date.AddDays(i);
							if (dataDay.DayOfWeek != DayOfWeek.Saturday && dataDay.DayOfWeek != DayOfWeek.Sunday)
							{
								if (dataTable.Rows.Count > dataCount)
								{
									DataRow row = dataTable.Rows[dataCount];
									DateTime dayTemp = (DateTime)row["Date"];

									if (dataDay == dayTemp)
									{
										candleSeries1.Add(dataCount,
										(double)row["Open"],
										(double)row["High"],
										(double)row["Low"],
										(double)row["Close"]);
										volumeSeries1.Add(dataCount, (double)row["Volume"]);
										dataCount++;
									}

									labels.Add(dataDay.ToShortDateString());
								}

							}
						}
						candleSeries1.Labels = labels;

						Steema.TeeChart.Styles.Line line = new Steema.TeeChart.Styles.Line(tChart1);
						Steema.TeeChart.Functions.ExpMovAverage function = new Steema.TeeChart.Functions.ExpMovAverage();

						function.Period = 1;

						line.Function = function;
						line.DataSource = candleSeries1;
						line.VertAxis = candleSeries1.VertAxis;

						line.CheckDataSource();
        }
Hope this helps!
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

vlaho
Newbie
Newbie
Posts: 9
Joined: Wed Jun 25, 2008 12:00 am
Contact:

Post by vlaho » Fri Oct 31, 2008 3:42 pm

Hi Narcís,

Thank you for all your help, but this is not what I want. With this code, I only get data I have, not gap between days I don't have. I thought that image I sent "WhatINeed.png" explains it. It shows gap between data and dates for that data on bottom axis.

For example if we want to show a line with "Close" values in regular intervals (every 5 minutes) and we don't have data for that interval we need to have empty space, and a mark on axis for that interval. This is because some illiquid stocks have small trade count and with this gaps it's more clear to the user.

How to show that gap? Off course functions would still have to work.

By the way, the code you provided shows wrong data... dates on axis doesn't relate to right candle data...

Best regards, Goran

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 Nov 03, 2008 3:22 pm

Hi Goran,

We have looked at the issue again and we think it is a bug that adding null points to a candle series still plots a candle and I have added the issue (TF02013524) to the defect list to be fixed for next releases.

We will also investigate if what you requested can be achieved and get back to you when we have further news.
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

vlaho
Newbie
Newbie
Posts: 9
Joined: Wed Jun 25, 2008 12:00 am
Contact:

Post by vlaho » Tue Nov 04, 2008 9:03 am

Hi Narcis,

I'm sorry to hear that. For now I am using dummy Line to fill labels for bottom axis... something like this:

Code: Select all

        // dummy line for non existing days/periods
        Steema.TeeChart.Styles.Line dummyLine = new Steema.TeeChart.Styles.Line(tChart1);
        for (int labelsIndex = 0; labelsIndex < labelsCount; labelsIndex++)
        {
            dummyLine.Add();
        }
        dummyLine.Labels = labels;
How are formulas calculated if we have not data for some periods? Are the data between interpolated or used only available data? How about Moving Average for Candle Series where we need a range of data for calculation and there are gaps inside Period?

Now we have a problem with Custom Functions. In CalculateEvent, if we don't have data for that point, what to do? e.Y can't be null so it stays 0 (zero) and chart is drawn on zero line. What is the best solution for this?

Thank you for all your trouble.

Best regards, Goran

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 Nov 04, 2008 3:02 pm

Hi Goran,

Using code below you get the same chart as you requested. Could you please check if this works fine for you?

Code: Select all

        protected void Page_Load(object sender, EventArgs e)
        {
            Steema.TeeChart.Chart tChart1;
            tChart1 = WebChart1.Chart;

						DataTable dataTable = new DataTable();
						dataTable.Columns.Add("Date", typeof(DateTime));
						dataTable.Columns.Add("Open", typeof(double));
						dataTable.Columns.Add("High", typeof(double));
						dataTable.Columns.Add("Low", typeof(double));
						dataTable.Columns.Add("Close", typeof(double));
						dataTable.Columns.Add("Volume", typeof(double));


						dataTable.Rows.Add(DateTime.Parse("20/10/2008"), 10, 12, 9, 11, 2);
						dataTable.Rows.Add(DateTime.Parse("21/10/2008"), 10, 12, 9, 11, 3);
						dataTable.Rows.Add(DateTime.Parse("29/10/2008"), 10, 12, 9, 11, 4);
						dataTable.Rows.Add(DateTime.Parse("30/10/2008"), 10, 12, 9, 11, 5);


						Candle candleSeries1 = new Candle(tChart1.Chart);
						candleSeries1.XValues.DateTime = false;

						Volume volumeSeries1 = new Volume(tChart1.Chart);

						Steema.TeeChart.Styles.StringList labels = new Steema.TeeChart.Styles.StringList();

						DateTime dateFrom = DateTime.Parse("20/10/2008");
						DateTime dateTo = DateTime.Parse("30/10/2008");

						TimeSpan ts = dateTo - dateFrom;

						int dataCount = 0;
						int j = 0;

						for (int i = 0; i <= ts.Days; i++)
						{
							DateTime dataDay = dateFrom.Date.AddDays(i);
							if (dataDay.DayOfWeek != DayOfWeek.Saturday && dataDay.DayOfWeek !=
			DayOfWeek.Sunday)
							{
								if (dataTable.Rows.Count > j)
								{
									DataRow row = dataTable.Rows[j];
									DateTime dayTemp = (DateTime)row["Date"];

									if (dataDay == dayTemp)
									{
										candleSeries1.Add(dataCount,
												(double)row["Open"],
												(double)row["High"],
												(double)row["Low"],
												(double)row["Close"]);
										volumeSeries1.Add(dataCount, (double)row["Volume"]);
										j++;
									}
									else // add empty data
									{
										volumeSeries1.Add();
									}

									labels.Add(dataDay.ToShortDateString());
								}

								dataCount++;
							}
						}
						volumeSeries1.Labels = labels;

						Steema.TeeChart.Styles.Line line = new Steema.TeeChart.Styles.Line(tChart1.Chart);
						Steema.TeeChart.Functions.ExpMovAverage function = new Steema.TeeChart.Functions.ExpMovAverage();

						function.Period = 1;

						line.Function = function;
						line.DataSource = candleSeries1;
						line.VertAxis = candleSeries1.VertAxis;

						line.CheckDataSource();
        }
Thanks in advance.
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

Post Reply