Page 2 of 2 FirstFirst 12
Results 41 to 57 of 57

Thread: [RESOLVED] Beginning: Array of Object (looking for critique)

  1. #41

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,245

    Re: Beginning: Array of Object (looking for critique)

    Quote Originally Posted by georgekar View Post
    Another idea. For each series of prices you have an internal document where you divide each time you add a Ma. So your document may have enabled and not enabled ma. You may divide any ma to two or three, and the reason to do that is to control overlapping, so with splitting you don't give a chance to make anyone an overlapping ma. Why is not good to have overlapping Ma? Because you can't see two of them but one except you have flashing drawings that rotate so at any time one ma is drawing only....
    I understand that duplicate MA's are unwanted as you won't be able to see them separately anyway. What I do not understand is this "internal document" that you 'divide'.

    Couldn't I just check the ListView items first to make sure one does not already exist before even creating the MA?

    :-)

  2. #42

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,245

    Re: Beginning: Array of Object (looking for critique)

    Here's the modified ADD MA button code that includes checking for possible duplicate.

    Code:
    Private Sub btnAddMA_Click()
    Dim bExists As Boolean
    Dim lColor As Long
    Dim Key As String
    Dim Period As Integer
    
        Period = CInt(txtPeriod.Text)
        lColor = ColorPick1.ColorCode
        Key = "ma" & Format$(Period, "000") & CStr(chkExp.Value)
        
        'Check list to make sure another MA does not match this one exactly
        bExists = CheckMAList(List1, MAs)
        
        If Not bExists Then 'Add new MA
                       
            Set MA = MAs.AddNewMA(Key, Period, chkExp.Value, lColor, chkWidth.Value, 1, True)
            
        Else
            MsgBox "MA already exists!", vbOKOnly
        End If
    
        FillMAsInto List1, MAs
    
    
    End Sub
    I've replaced the List with ListView control so that I can have color and bold effects.

    Code:
    Private Sub FillMAsInto(Lst As ListView, MAs As cMAs)
    Dim sStr As String
    Dim sTF As String 'TimeFrame spelled out
    Dim sExp As String
    
        If MAs.Count < 1 Then: Exit Sub
        
        
        Lst.ListItems.Clear
        
        For Each MA In MAs
          
            sExp = " "
            If MA.Exponential = True Then: sExp = " Exponential "
            If MA.TimeFrame = 1 Then: sTF = " Day"
            sStr = MA.Period & sTF & sExp
          
            With Lst.ListItems.Add(, MA.Key, sStr & "Moving Average")
                .Bold = MA.Bold
                .ForeColor = MA.Color
            End With
            
        Next
        
    End Sub
    Changed the Properties for Width (Int) to Bold (Bool).

    Code:
    Public Key As String
    Public Visible As Boolean  'visibility of the Line in a given Chart
    Public TimeFrame As Integer  'time frame of chart
    Public Exponential As Boolean  'exponential or simple MA?
    Public Color As Long 'color of MA line
    Public Period As Integer 'averaging period
    Public Bold As Boolean 'thin or bold line
    I've attached the code of what has been done 'so far' for anyone interested.
    Attached Files Attached Files
    Last edited by webbiz; Aug 10th, 2015 at 08:51 PM. Reason: Adding code and attaching code.

  3. #43
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,289

    Re: Beginning: Array of Object (looking for critique)

    Imagine that all your data are one Ma.You have also a property to make it visible or not. Now think two process, one to divide a Ma to two or three parts. Also you can change the visible property...for two parts you have option for upper or lower Ma, for three you have an option for middle only. With these as rules you can prepare any combination. The same happen when you press enter in a document, you divide a paragraph to two paragraphs, but think if you have to place a paragraph in a paragraph you have to place in three possible positions, top, middle, bottom.

  4. #44

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,245

    Re: Beginning: Array of Object (looking for critique)

    Quote Originally Posted by georgekar View Post
    Imagine that all your data are one Ma.You have also a property to make it visible or not. Now think two process, one to divide a Ma to two or three parts. Also you can change the visible property...for two parts you have option for upper or lower Ma, for three you have an option for middle only. With these as rules you can prepare any combination. The same happen when you press enter in a document, you divide a paragraph to two paragraphs, but think if you have to place a paragraph in a paragraph you have to place in three possible positions, top, middle, bottom.
    Thank you georgekar for your comments.

    I understand what you are suggesting, being able to turn off or on 'parts' of the MA.

    However, for this project that particular method would not be needed.

    The app will do two things with the MA data:

    1) Display the MA for the FIRST (gFirstBarRecNum) to the LAST (gLastBarRecNum) bar on the price chart (since drawing outside the viewing area is a waste).

    2) Allowing hiding the MA (there is a ToolHide function within the app that hides all drawn tools).

  5. #45

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,245

    Re: Beginning: Array of Object (looking for critique)

    In module1 (module1.bas), here is the code that allows for populating the MA object arrays. CalculateMA in reality is more elaborate that what you see below. I did this to simulate that the data was calculated by CalculateMA.

    Code:
    Option Explicit
    
    Public MAs As New cMAs, MA As cMA
    
    Public sngPrices() As Single
    Public gLastRecNum As Long
    
    Public Sub PopulateMA(MAs As cMAs, Optional ByVal Key As String)
    Dim x As Integer
    Dim arrMAresults() As Single
    
        ReDim arrMAresults(gLastRecNum)
        
        If Key = "" Then
        
            'Calculate the MA in MAs and populate the array
            For Each MA In MAs
                If Not MA.arrFilled Then 'Make sure array not filled
                    
                    arrMAresults = CalculateMA(MA.Period, MA.Exponential)
                    
                    For x = 1 To UBound(sngPrices)
                        MA.arrMA(x) = arrMAresults(x - 1) 'This will be replaced by actual calculated data
                    Next x
                    
                End If
            Next
        
        Else 'Just fill the MA object indicated by the Key
            
            For Each MA In MAs
                If MA.Key = Key Then
                    
                    arrMAresults = CalculateMA(MA.Period, MA.Exponential)
                    
                    For x = 1 To UBound(sngPrices)
                        MA.arrMA(x) = arrMAresults(x - 1)
                    Next x
                    
                End If
            Next
        
        End If
    
    
    End Sub
    
    Public Function CalculateMA(ByVal Period As Integer, ByVal IsExponential As Boolean) As Single()
    
        CalculateMA = sngPrices 'simulating the results of calculation
    
    End Function
    I'm not sure the code that references by KEY is the correct way to go about this. Can the object be referenced directly based on Key without having to loop through every MA within the object?

  6. #46
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,289

    Re: Beginning: Array of Object (looking for critique)

    Not exactly a suggestion for on/off a MA but a way to handle and validate the user input. There are a front where a user see some graphics and there is a layer under that the programmer (you) process a "database" or "array", to create parts, to delete parts and to render. So I wrote the previous post for the manage of MA not exactly for the rendering, the display of MA.
    Using a listbox for three or four MA maybe is easy to find anyone a specific one, but for more maybe is better to choose by clicking the drawing. So what I have to offer is a way to use a cursor. So when user click anywhere in the graphic then you get the click and translate to a real position in a like a document structure. Maybe you find a non used block, so click do nothing, or you find a block...and so maybe you change color to make it as cursor like. Then with ctrl and mouse maybe user can expand or reduce the span of MA, and with a shift and mouse move maybe user can shift MA...

  7. #47

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,245

    Re: Beginning: Array of Object (looking for critique)

    Quote Originally Posted by georgekar View Post
    Not exactly a suggestion for on/off a MA but a way to handle and validate the user input. There are a front where a user see some graphics and there is a layer under that the programmer (you) process a "database" or "array", to create parts, to delete parts and to render. So I wrote the previous post for the manage of MA not exactly for the rendering, the display of MA.
    Using a listbox for three or four MA maybe is easy to find anyone a specific one, but for more maybe is better to choose by clicking the drawing. So what I have to offer is a way to use a cursor. So when user click anywhere in the graphic then you get the click and translate to a real position in a like a document structure. Maybe you find a non used block, so click do nothing, or you find a block...and so maybe you change color to make it as cursor like. Then with ctrl and mouse maybe user can expand or reduce the span of MA, and with a shift and mouse move maybe user can shift MA...
    I appreciate the ideas flowing!

    So you are talking about 'manipulation' of the MA drawn on the chart by clicking on the chart.

    Perhaps if MAs were the only thing on the chart I could do those things to give it more flexible manipulation. However, many tools can be on the chart at one time and currently the mouse click is being used to either scroll the chart (double-click and hold/move), or to delete tools off the chart (right-click), etc.

    For those like myself that use MAs on a chart, it feels more natural to control the MAs by means of a 'setup' window.

    But it is an interesting idea.

    Thank you. :-)

  8. #48

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,245

    Re: Beginning: Array of Object (looking for critique)

    And here is the MA drawing routine.

    Code:
    Public Sub DrawMA(MAs As cMAs)
    Dim sngVertRange As Single
    Dim sngVertIncr As Single
    Dim x As Long
    
        frmChart.pctChart.Scale (1, MAs.Item(1).MaxVal)-(150, MAs.Item(1).MinVal)
        
        For Each MA In MAs
                    
                 For x = MA.Period + 1 To gLastRecNum - 1
                    frmChart.pctChart.Line (x, MA.arrMA(x))-(x + 1, MA.arrMA(x + 1)), MA.Color
                 Next x
                    
            
        Next
        
    End Sub

  9. #49

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,245

    Re: Beginning: Array of Object (looking for critique)

    Well I think I have the code that I need for my main app. Didn't see any critiques for the code I did post (aside from feature suggestions), so I have to assume the way I wrote this code is appropriate.

    The code is attached for anyone who wishes to check it.

    Thanks.

    ObjectMA.zip

  10. #50
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,289

    Re: [RESOLVED] Beginning: Array of Object (looking for critique)

    Use with ... end with for Ma. And it is obvious that you use pixels.That means that the handling of rounding is yours.
    With Ma
    For X=.Period ....
    End With

    With first look you have a fault. What are the Bounds of arrMA()...because for each MA you place gLastRecNum-1. You use for next from a specific value in any MA to a global limit. It is totally wrong aproach

  11. #51
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,253

    Re: [RESOLVED] Beginning: Array of Object (looking for critique)

    I would use the existing Let-Property by which you fill the internal array,
    to not only assign the new incoming Value to the Array-slot, but at this
    occassion I'd also "drag-along" two internal m_Min, m_Max Variables ...

    The needed If-Checks would be cheap at this occasion - this way you
    won't have to perform an extra-loop as you do currenly in your Min/Max
    Properties (instead just hand m_Min and m_Max out, they are always correct,
    since any new incoming value was "validated" against them already).

    Olaf

  12. #52

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,245

    Re: [RESOLVED] Beginning: Array of Object (looking for critique)

    Quote Originally Posted by georgekar View Post
    Use with ... end with for Ma. And it is obvious that you use pixels.That means that the handling of rounding is yours.
    With Ma
    For X=.Period ....
    End With

    With first look you have a fault. What are the Bounds of arrMA()...because for each MA you place gLastRecNum-1. You use for next from a specific value in any MA to a global limit. It is totally wrong aproach
    Thanks for the critique. I will go through the code and add those With...End statements.

    The Bounds of arrMA() is ALWAYS gLastRecNum, because that is how it is dimensioned in the class. In my main app, where this code is to go eventually, gLastRecNum is the LAST RECORD available for the chart. The MA array is to match this index value in UBOUND. There are NO MAs that will go beyond this boundary nor fall short of it.

  13. #53

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,245

    Re: [RESOLVED] Beginning: Array of Object (looking for critique)

    Quote Originally Posted by Schmidt View Post
    I would use the existing Let-Property by which you fill the internal array,
    to not only assign the new incoming Value to the Array-slot, but at this
    occassion I'd also "drag-along" two internal m_Min, m_Max Variables ...

    The needed If-Checks would be cheap at this occasion - this way you
    won't have to perform an extra-loop as you do currenly in your Min/Max
    Properties (instead just hand m_Min and m_Max out, they are always correct,
    since any new incoming value was "validated" against them already).

    Olaf
    So what you are suggesting is to put the Min/Max updating code inside the Let arrMA() method?

    Code:
    Private Sub Class_Initialize()
        m_arrMAmaxentries = gLastRecNum
        m_minVal = 99999
        ReDim m_arrMA(m_arrMAmaxentries) 'Initialize array to global value
    End Sub
    Code:
    Option Explicit
    
    Public Key As String
    Public Visible As Boolean  'visibility of the Line in a given Chart
    Public TimeFrame As Integer  'time frame of chart
    Public Exponential As Boolean  'exponential or simple MA?
    Public Color As Long 'color of MA line
    Public Period As Integer 'averaging period
    Public Bold As Boolean 'thin or bold line
    
    Private m_arrMA() As Single  'holds the moving averages
    Private m_arrMAmaxentries As Long
    Private m_maxVal As Single
    Private m_minVal As Single
    Code:
    Friend Property Let arrMA(ByVal Index As Long, ByVal MA_value As Single)
      If Index < 0 Or Index > m_arrMAmaxentries Then Err.Raise 9
      m_arrMA(Index) = MA_value
      
      'Update min/max if necessary
      If MA_value > 0 Then
        If MA_value > m_maxVal Then: m_maxVal = MA_value
        If MA_value < m_minVal Then: m_minVal = MA_value
      End If
      
    End Property
    Code:
    Public Property Get MinVal() As Single
        MinVal = m_minVal
    End Property
    
    Public Property Get MaxVal() As Single
        MaxVal = m_maxVal
    End Property

    Something like this?

    Thanks.
    Last edited by webbiz; Aug 12th, 2015 at 12:09 PM.

  14. #54

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,245

    Re: [RESOLVED] Beginning: Array of Object (looking for critique)

    dupl
    Last edited by webbiz; Aug 12th, 2015 at 11:34 AM.

  15. #55

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,245

    Re: [RESOLVED] Beginning: Array of Object (looking for critique)

    Quote Originally Posted by georgekar View Post
    Use with ... end with for Ma. And it is obvious that you use pixels.That means that the handling of rounding is yours.
    With Ma
    For X=.Period ....
    End With
    So georgekar, is this what you are suggesting?

    Code:
    Public Sub DrawMA(MAs As cMAs)
    Dim sngVertRange As Single
    Dim sngVertIncr As Single
    Dim x As Long
    
        With MAs
            frmChart.pctChart.Scale (1, .Item(1).MaxVal)-(150, .Item(1).MinVal)
        End With
        
        For Each MA In MAs
            With MA
                 For x = .Period + 1 To gLastRecNum - 1
                    frmChart.pctChart.Line (x, .arrMA(x))-(x + 1, .arrMA(x + 1)), .Color
                 Next x
            End With
        Next
        
    End Sub

  16. #56
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,253

    Re: [RESOLVED] Beginning: Array of Object (looking for critique)

    [suggestion, to move Min-Max Value-Dragging directly into the Array-Item Let-Prop]

    Quote Originally Posted by webbiz View Post
    ...
    Something like this?
    Yes - exactly - doesn't really add many extra-cpu-cycles in the new place where
    you now moved it to - and on the other hands saves quite a bunch of cycles
    by avoiding a complete looping in your former Min/Max-Properties.

    I think that example shows, that whilst working through (Friend)-Properties
    to fill the Member-Slots of an internal Array (where you lose a bit of performance
    compared to direct Array-Member-assignments), there's also a few occasions
    where this somewhat slower design offers a few chances to get some of those
    "wasted Cycles" back...

    What you did with the Min- Max-stuff (during Slot-Assignments of the current
    incoming NewValue), you could expand to calculate even other Class-internal stuff
    which depends on "looking at every single, ever assigned new Value-Member".

    Olaf

  17. #57

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,245

    Re: [RESOLVED] Beginning: Array of Object (looking for critique)

    Quote Originally Posted by Schmidt View Post
    [suggestion, to move Min-Max Value-Dragging directly into the Array-Item Let-Prop]



    Yes - exactly - doesn't really add many extra-cpu-cycles in the new place where
    you now moved it to - and on the other hands saves quite a bunch of cycles
    by avoiding a complete looping in your former Min/Max-Properties.

    I think that example shows, that whilst working through (Friend)-Properties
    to fill the Member-Slots of an internal Array (where you lose a bit of performance
    compared to direct Array-Member-assignments), there's also a few occasions
    where this somewhat slower design offers a few chances to get some of those
    "wasted Cycles" back...

    What you did with the Min- Max-stuff (during Slot-Assignments of the current
    incoming NewValue), you could expand to calculate even other Class-internal stuff
    which depends on "looking at every single, ever assigned new Value-Member".

    Olaf
    Cool. I must be catching on. Thanks. :-)

    I can't think of anything else at the moment that I need to do to these 'single' values internally. From here they go straight to being plotted on the chart.

    I've learned a bunch. Mucho Gracias guys!

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width