Sub PB()
'''-----http://www.samurai-logic.com/
'''-----Project of Trading System Development
'''------------------------------------------------------------------
''----B列(日付)、C列(始値)、D列(高値)、E列(安値)、F列(終値)
''----
''----TextBox1にMaxAF、TextBox2に初期AF値
''----TextBox3にAF加算値、Temp(4)はパラボリックプライスの表示位置%
''--------------------------------------------------------------------
Dim length1!, length2!, length3!, length4%, LastRow&, i&
Dim SaR!, IsBuy As Boolean, IsBuy2 As Boolean
Dim Temp(4) As Single, Temp2!
Application.ScreenUpdating = False
Worksheets("パラボリック").Activate
Temp(1) = CSng(ActiveSheet.TextBox1.Value) 'MaxAF
Temp(2) = CSng(ActiveSheet.TextBox2.Value) 'AF初期値
Temp(3) = CSng(ActiveSheet.TextBox3.Value) 'AF加算値
Temp(4) = 2.5 '表示位置(±%)
Range("H3") = "PaR"
Range("I3") = "パラボリック"
Range("H5:I10000").ClearContents
LastRow = (Range("B4").End(xlDown).Row)
'初期設定
If (Cells(5, 4).Value + Cells(5, 5).Value) / 2 _
<= Cells(10, 6).Value Then
IsBuy = True
Cells(10, 9).Value = True
Else
IsBuy = False
Cells(10, 9).Value = False
End If
If (Cells(6, 4).Value + Cells(6, 5).Value) / 2 _
<= Cells(11, 6).Value Then
IsBuy2 = True
Cells(11, 9).Value = True
SaR = Cells(6, 5).Value
Else
IsBuy2 = False
Cells(11, 9).Value = False
SaR = Cells(6, 4).Value
End If
Cells(11, 8).Value = SaR
For i = 12 To LastRow + 1
If ((Cells(i - 1, 9).Value = True And _
Cells(i - 2, 9).Value = True) Or _
(Cells(i - 1, 9).Value = False And _
Cells(i - 2, 9).Value = False)) And _
Temp(2) <= Temp(1) Then
Temp(2) = Temp(2) + Temp(3)
Else
Temp(2) = 0.02
End If
Cells(i, 9).Value = Temp(2)
If Cells(i - 1, 9).Value = True Then
SaR = Cells(i - 1, 8).Value + Temp(2) * _
(Cells(i - 1, 4).Value - (Cells(i - 1, 8).Value))
Cells(i, 8).Value = SaR
Else
SaR = Cells(i - 1, 8).Value + Temp(2) * _
(Cells(i - 1, 5).Value - (Cells(i - 1, 8).Value))
Cells(i, 8).Value = SaR
End If
If Cells(i, 6).Value > SaR Then
IsBuy2 = True
Cells(i, 9).Value = True
Else
IsBuy2 = False
Cells(i, 9).Value = False
End If
Next i
Range("I5:I" & LastRow + 1).ClearContents
For i = 24 To LastRow + 1
If Cells(i, 6).Value >= Cells(i, 8).Value Then
Cells(i, 9).Value = Cells(i, 8).Value * (1 - Temp(4) / 100)
ElseIf Cells(i, 6).Value < Cells(i, 8).Value Then
Cells(i, 9).Value = Cells(i, 8).Value * (1 + Temp(4) / 100)
End If
Next i
Erase Temp
Range("H5", "I" & LastRow + 1).NumberFormatLocal = "0"
Application.ScreenUpdating = True
End Sub