Null Values in Candle Series and Functions
Posted: 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.
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()
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.
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()