I have an automated self-updating moving average, which basically is the average of the prices of the last x minutes, polled once per minute.
So this means the macros print price once every minute.
Someone else had written these macros for me years ago, and until now, being an amateur VBA programmer, I still haven't fully understood it.
This would not be a problem, because they work but the reason I want to understand them is to simplify them, because I started off with just one moving average and now I will need about 13 of them, on different markets.
Here's the macros:
1) Everything starts from this macro, which gets started by "ThisWorkbook":
Sub ma_timer()
For i = 1 To 500
ma.Cells(i, 1) = tickers.Cells(12, 20)
Next
TimerOn 60000
End Sub
And this is clear but I don't know what happens next
2) Then we get on another sheet, where I have all these macros:
Private Declare Function SetTimer Lib "User32" _
(ByVal hWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "User32" _
(ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
Dim averageprice(2) As Double
Dim minutes As Integer
Dim TimerID As Long
Public Sub TimerOn(Interval As Long)
On Error Resume Next
TimerID = SetTimer(0, 0, Interval_eur, AddressOf myroutine)
End Sub
Private Sub myroutine()
On Error Resume Next
minutes = minutes + 1
averageprice(0) = averageprice(0) + tickers.Cells(12, 20)
If minutes = 1 Then
For i = 1 To 499
ma.Cells(i, 1) = ma.Cells(i + 1, 1)
Next
meu.Cells(500, 1) = averageprice(0) / minuti
Erase averageprice
minutes = 0
End If
End Sub
Please let me know if you can help me. It works but I don't know why, and I would like to understand it in order to simplify it and not have these macros multiplied by 13, because it would be too heavy for my CPU.
So this means the macros print price once every minute.
Someone else had written these macros for me years ago, and until now, being an amateur VBA programmer, I still haven't fully understood it.
This would not be a problem, because they work but the reason I want to understand them is to simplify them, because I started off with just one moving average and now I will need about 13 of them, on different markets.
Here's the macros:
1) Everything starts from this macro, which gets started by "ThisWorkbook":
Sub ma_timer()
For i = 1 To 500
ma.Cells(i, 1) = tickers.Cells(12, 20)
Next
TimerOn 60000
End Sub
And this is clear but I don't know what happens next
2) Then we get on another sheet, where I have all these macros:
Private Declare Function SetTimer Lib "User32" _
(ByVal hWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "User32" _
(ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
Dim averageprice(2) As Double
Dim minutes As Integer
Dim TimerID As Long
Public Sub TimerOn(Interval As Long)
On Error Resume Next
TimerID = SetTimer(0, 0, Interval_eur, AddressOf myroutine)
End Sub
Private Sub myroutine()
On Error Resume Next
minutes = minutes + 1
averageprice(0) = averageprice(0) + tickers.Cells(12, 20)
If minutes = 1 Then
For i = 1 To 499
ma.Cells(i, 1) = ma.Cells(i + 1, 1)
Next
meu.Cells(500, 1) = averageprice(0) / minuti
Erase averageprice
minutes = 0
End If
End Sub
Please let me know if you can help me. It works but I don't know why, and I would like to understand it in order to simplify it and not have these macros multiplied by 13, because it would be too heavy for my CPU.