Excel VBA code (technical index for trading system)

Excel VBA Source Code --- RSI

Technical code for trading system.

Sub RSI()

'''-----http://www.samurai-logic.com/
'''-----Project of Trading System Development
'''------------------------------------------------------------------
''----B列(日付)、C列(始値)、D列(高値)、E列(安値)、F列(終値)
''----
''----TextBox1に計算期間
''--------------------------------------------------------------------

Dim Temp!, pTemp!, MTemp!, length1%, i&, j&

Application.ScreenUpdating = False

Worksheets("RSI").Activate

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

Range("AB5:AC10000").ClearContents
    
length1 = CInt(ActiveSheet.TextBox1.Value)  'RSIの期間 1
    
Range("H3") = "RSI(" & length1 & ")"
   
  For i = length1 + 5 To LastRow
     Temp = 0: pTemp = 0: MTemp = 0
     For j = 1 To length1
        Temp = Cells(i - (length1) + j, 6).Value - _
               Cells(i - (length1) + j - 1, 6).Value
         If Temp > 0 Then
          pTemp = pTemp + Temp
         Else
          MTemp = MTemp + Temp
         End If
     Next j
       If (pTemp - MTemp) = 0 Then
        Cells(i, 8).Value = 50
       Else
        Cells(i, 8).Value = (pTemp / (pTemp - MTemp)) * 100
       End If

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