Hi to all
I am a newbie at VBA and macros. I want to get BTC price and charting 1 min candlestick chart.
Getting BTC Price with RTD at DATA sheet A1 Cell and Time A2 cell
Logging price every second for every minute at LOG sheet
at CANDLE sheet getting time, open, high, low and close price from LOG sheet for charting.
Below is my Code and attached Excel file and Screenshots.
My problem is, this is not accurate, it is delaying 30 secs, every 10-15 mins. And code is very bulky so many data storing for charting.
Is there a proper way to store in a table Open, High, Low and Close Price for every minute?
Public i As Integer
Public j As Integer
Sub basla()
If Second(Time) = 0 Then
i = 1
UpdateData
Else
Application.OnTime Now + TimeValue("0:0:1"), "basla"
End If
End Sub
Sub UpdateData()
If i = 1 Then
CopyTime
CopyData
i = i + 1
Application.OnTime Now + TimeValue("0:0:1"), "UpdateData"
Else
If i <= 59 Then
CopyData
i = i + 1
Application.OnTime Now + TimeValue("0:0:1"), "UpdateData"
Else
i = 1
Application.OnTime Now + TimeValue("0:0:1"), "UpdateData"
End If
End If
End Sub
Sub CopyTime()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim sht1 As Worksheet
Dim sht2 As Worksheet
Dim cRng1 As Range
Dim dCol1 As Long
Set sht1 = ThisWorkbook.Sheets("DATA")
Set sht2 = ThisWorkbook.Sheets("LOG")
Set cRng1 = sht1.Range("A2")
dCol1 = sht2.Cells(Rows.Count, 1).End(xlUp).Row + 1
sht2.Range(Cells(dCol1, 1).Address, Cells(dCol1, 1).Address) = cRng1.Value
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Sub CopyData()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim sht1 As Worksheet
Dim sht2 As Worksheet
Dim cRng1 As Range
Dim dCol1 As Long
Dim dCol2 As Long
Set sht1 = ThisWorkbook.Sheets("DATA")
Set sht2 = ThisWorkbook.Sheets("LOG")
Set cRng1 = sht1.Range("A1")
dCol2 = sht2.Cells(Rows.Count, 1).End(xlUp).Row
dCol1 = sht2.Cells(dCol2, Columns.Count).End(xlToLeft).Column + 1
sht2.Range(Cells(dCol2, dCol1).Address, Cells(dCol2, dCol1).Address) = cRng1.Value
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Bookmarks