Excel VBA code (technical index for trading system)

Excel VBA Source Code --- ボリュームレシオ2(Volume Ratio 2)

Technical code for trading system.

Sub VR2()

'''-----http://www.samurai-logic.com/
'''-----Project of Trading System Development
'''------------------------------------------------------------------
''----B列(日付)、C列(始値)、D列(高値)、E列(安値)、F列(終値)
''----G列に出来高
''----TextBox1に期間1、TextBox2に期間2
''--------------------------------------------------------------------
Dim length1%, length2%, LastRow&, i&, j%, j2&
Dim S!, U!, D!, TempU!, TempD!, TempS!

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

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

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

Range("H5:I5000").ClearContents

Range("H4") = "VR2:" & length1
Range("I4") = "VR2:" & length2

For i = length1 + 5 To LastRow
 U = 0: D = 0: S = 0
 
  For j = 1 To length1
  
   If Cells(i - (length1) + j, 6).Value > _
      Cells(i - (length1) + j - 1, 6).Value Then
    TempU = Cells(i - (length1) + j, 7).Value
    U = U + TempU
    
   ElseIf Cells(i - (length1) + j, 6).Value < _
          Cells(i - (length1) + j - 1, 6).Value Then
    TempD = Cells(i - (length1) + j, 7).Value
    D = D + TempD
    
   Else
    TempS = Cells(i - (length1) + j, 7).Value
    S = S + TempS
   End If
   
  Next j
  
   If U + D + S = 0 Then
    Cells(i, 8).Value = 0
   Else
    Cells(i, 8).Value = (U + S / 2) * 100 / (U + D + S)
   End If
   U = 0: D = 0: S = 0
   
 If i > (length2) + 5 Then
  For j = 1 To length2

    If Cells(i - (length2) + j, 6).Value > _
       Cells(i - (length2) + j - 1, 6).Value Then
     TempU = Cells(i - (length2) + j, 7).Value
     U = U + TempU
     
    ElseIf Cells(i - (length2) + j, 6).Value < _
           Cells(i - (length2) + j - 1, 6).Value Then
     TempD = Cells(i - (length2) + j, 7).Value
     D = D + TempD
     
    Else
     TempS = Cells(i - (length2) + j, 7).Value
     S = S + TempS
    End If
    
  Next j
  
   If U + D + S = 0 Then
    Cells(i, 9).Value = 0
   Else
    Cells(i, 9).Value = (U + S / 2) * 100 / (U + D + S)
   End If
  End If

Next i

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