Hi,
I have an Enum file, as shown in first code block. Though it's first time I use an enum file, so maybe it's not correct to use it like this.. My purpose is just to be able to reference a global parameter from anywhere, so I can just type DataInterval.M1, and it will be treated as an integer... or.. will it not ?
Further I have a property in my DataSeries class, of type DataInterval. And in this class I also have a bunch of methods Get/Set etc. to do different work on the dataseries (Inherits List(Of BarData)).
Problem: The interval property keeps changing unexpectedly every time the GetNextCloseTime function is called.
So what am I doing wrong here.... ? Any other critic is also much welcomed!
Code:''' <summary> ''' "Time Frame" of data series ''' </summary> ''' <remarks></remarks> Public Enum DataInterval M1 = 1 M2 = 2 M3 = 3 M5 = 5 M10 = 10 M13 = 13 M15 = 15 M30 = 30 M60 = 60 M120 = 120 M240 = 240 D = 101 W = 102 M = 103 End EnumCode:<Serializable()> Public Class DataSeries Inherits List(Of BarData) Private _Interval As New DataInterval Private Property Interval() As DataInterval Get Return _Interval End Get Set(ByVal value As DataInterval) _Interval = value End Set End Property ' ................ Public Sub UpdateBarByTick(ByVal tickTime As Date, ByVal price As Double) Dim newBar As BarData If IsDataSeriesEmpty() Or IsTimeAfterCurrentBarCloseTime(tickTime) Then newBar = New BarData(GetNextCloseTime, price, price, price, price, 0) Me.AddBar(newBar) Else Dim currentBarUpdate As New BarData currentBarUpdate = GetLastBar() currentBarUpdate.Close = price ' Set new High/Low if occur If price > currentBarUpdate.High Then currentBarUpdate.High = price ElseIf price < currentBarUpdate.Low Then currentBarUpdate.Low = price End If UpdateBarIndex(Me.Count - 1, currentBarUpdate) End If RaiseEvent TickUpdate(GetLastBar) End Sub ' ................ Public Function GetNextCloseTime() As Date Dim intervalTimeSpan As New TimeSpan(0, Me.Interval, 0) Dim currentCloseInMinutes As Integer currentCloseInMinutes = Fix(Date.Now.Minute / Me.Interval) * Me.Interval Dim nextCloseTime As New Date(Date.Now.Year, Date.Now.Month, Date.Now.Day, Date.Now.Hour, currentCloseInMinutes, 0) nextCloseTime = nextCloseTime + intervalTimeSpan Return nextCloseTime End Function





Reply With Quote