Excel VBA code (technical index for trading system)

Excel VBA Source Code

Technical code for trading system.

Sub Envelope()

'''-----http://www.samurai-logic.com/
'''-----Project of Trading System Development
'''------------------------------------------------------------------
''----B列(日付)、C列(始値)、D列(高値)、E列(安値)、F列(終値)
''----
''----TextBox1に転換線の期間、TextBox2に基準線の期間
''--------------------------------------------------------------------

Dim length1%, length2%, length3%, LastRow&, i&

Application.ScreenUpdating = False

Worksheets("Envelope").Activate

LastRow = (Range("B4").End(xlDown).Row)
    
length1 = CInt(ActiveSheet.TextBox1.Value)  'period of average
length2 = CInt(ActiveSheet.TextBox2.Value)  '±%

Range("H3") = "Envelope:" & length1
Range("I3") = "Envelope:" & length2 & "%"

Range("H5:I10000").ClearContents

For i = length1 + 4 To LastRow

 Cells(i, 8).Value = _
    WorksheetFunction.Average(Range("F" & i, "F" & i - (length1) + 1)) * _
                                                       (1 - length2 / 100)
 Cells(i, 9).Value = _
    WorksheetFunction.Average(Range("F" & i, "F" & i - (length1) + 1)) * _
                                                       (1 + length2 / 100)
 
Next i

Range("H5", "I" & LastRow).NumberFormatLocal = "0"

Application.ScreenUpdating = True

End Sub