Excel VBA code (technical index for trading system)

Excel VBA Source Code --- ROC

Technical code for trading system.

Sub ROC()

'''-----http://www.samurai-logic.com/
'''-----Project of Trading System Development
'''------------------------------------------------------------------
''----B列(日付)、C列(始値)、D列(高値)、E列(安値)、F列(終値)
''----
''----TextBox1にROC期間1、TextBox2にROC期間2
''--------------------------------------------------------------------
Dim length1%, length2%, LastRow&, i&

Application.ScreenUpdating = False
 
Worksheets("ROC").Activate

LastRow = (Range("B4").End(xlDown).Row)

length1 = CInt(ActiveSheet.TextBox1.Value)
length2 = CInt(ActiveSheet.TextBox2.Value)
 

Range("H3") = "ROC:" & length1
Range("I3") = "ROC:" & length2

Range("H5:I5000").ClearContents

For i = length1 + 4 To LastRow

 Cells(i, 8).Value = (Cells(i, 6).Value - Cells(i - _
 (length1) + 1, 6).Value) * 100 / Cells(i - (length1) + 1, 6).Value
 
 If i > (length2) + 5 Then
 
 Cells(i, 9).Value = (Cells(i, 6).Value - Cells(i - _
 (length2) + 1, 6).Value) * 100 / Cells(i - (length2) + 1, 6).Value
 
 End If

Next

Range("H5", "I" & LastRow).NumberFormatLocal = "0.00"
Application.ScreenUpdating = True
End Sub