Null Values in Candle Series and Functions

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
dave
Newbie
Newbie
Posts: 40
Joined: Tue Dec 07, 2010 12:00 am

Null Values in Candle Series and Functions

Post by dave » Tue Dec 14, 2010 2:29 pm

I am attempting to set up basic OHLC bar charts and then overlay a study like a Moving Average. The Y scale may be 1, 5, 10, etc. minute bars. I need to be able to manage the "gaps" in the data for periods where there is no trade. For example, I do not want to show a gap horizontally where the market is closed, like on a Saturday. When the market is open, if we go a few minutes without any trade I want to leave a gap. That is to say, while the market is open I want to chart exactly what is happening. I saw all the talk about the time based scale not providing such functionality, so I have created my charts using an integer index number for each bar. That works just fine. As time goes by, my charts update. If there is no trade, nothing is plotted.

The problem I have relates to functions like moving averages. I can not seem to get the study to ignore null values. If you have a suggestion for properly entering the data or setting something correctly in the chart, I would like your feedback.

Here is an example. If one does a 1-day moving average of the close, the moving average line should connect each successive bar's close. You can see in the image below where the moving average line drops to 0 (presumably) on each bar where there is no data.
Chart.gif
Chart Image - 1day Average
Chart.gif (27.14 KiB) Viewed 4067 times
The code I use to insert the "null" data is as follows. I have tried using actual NULL objects, values of 0 and anything else I can think of. In the following code, the price value is actually the previous close value.

If IsMarketOpen(nBarDate) Then
CandleSeries1.Add(BarNum, lLast, Color.Transparent)
CandleSeries1.Labels(BarNum) = nBarDate.ToString("MM/dd/yyyy HH:mm")
VolumeSeries1.Add(BarNum, 0, Color.Transparent)
BarNum = BarNum + 1
End If

The study itself is created as:

Dim line2 As New Steema.TeeChart.Styles.Line(TChart1.Chart)
Dim Average1 As New Steema.TeeChart.Functions.Average()
Average1.IncludeNulls = False
line2.Function = Average1
line2.DataSource = CandleSeries1
line2.YValues.DataMember = "Close"
line2.Function.Period = 1
line2.Function.PeriodAlign = Functions.PeriodAligns.First
line2.Function.PeriodStyle = Functions.PeriodStyles.Range
line2.Color = Color.Blue
line2.CustomVertAxis = GreenAxis
line2.LinePen.Style = Drawing2D.DashStyle.Solid
line2.CheckDataSource()

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Null Values in Candle Series and Functions

Post by Sandra » Wed Dec 15, 2010 3:33 pm

Hello Dave,
You have different options:
1.- You can use property of average IncludeNulls to false and function will be calculated without null points. You also can change property of Line TreatNulls to DoNotPaint . You can do something as next:

Code: Select all

private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;
            Steema.TeeChart.Styles.Candle series1 = new Steema.TeeChart.Styles.Candle(tChart1.Chart);
            Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
            Steema.TeeChart.Functions.Average average1 = new Steema.TeeChart.Functions.Average();
            series1.FillSampleValues(5);
            series1.SetNull(2);
            series1.SetNull(4);
            line1.DataSource = series1;
            average1.IncludeNulls = false;
            line1.Function = average1;
            line1.YValues.DataMember = "Close";
            line1.Function.Period = 1;
            line1.Function.PeriodAlign = Steema.TeeChart.Functions.PeriodAligns.First;
            line1.Function.PeriodStyle = Steema.TeeChart.Functions.PeriodStyles.Range;
            line1.Color = Color.Blue;
            line1.TreatNulls = Steema.TeeChart.Styles.TreatNullsStyle.DoNotPaint;
            line1.LinePen.Style= System.Drawing.Drawing2D.DashStyle.Solid;
           tChart1.Axes.Bottom.Labels.Angle = 90;     
        }
2.- You can create your average function, using a line series, for example and set nulls the points that you don't want paint.

I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / 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

dave
Newbie
Newbie
Posts: 40
Joined: Tue Dec 07, 2010 12:00 am

Re: Null Values in Candle Series and Functions

Post by dave » Wed Dec 15, 2010 3:43 pm

I had the Average.IncludeNulls = False in there. I had missed the TreatNulls = DoNotPaint. That was the key. Thank you very much for the timely answer. We are good to go now!

:D (You guys ROCK!) :D

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Null Values in Candle Series and Functions

Post by Sandra » Wed Dec 15, 2010 4:52 pm

Hello dave,

I am glad that your problem solved :).

Thanks,
Best Regards,
Sandra Pazos / 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