- Rule과 Condition의 기준을 구현한 엑셀 vb 프로그램 소스 예시
Function mw_R_and_C(ParamArray varArgs() As Variant)
On Error GoTo EH_mw_R_and_C:
m1_end = varArgs(0)
m1_start = m1_end
If UBound(varArgs) > 0 Then
m1_start = varArgs(1)
Else
m1_start = mw_start(m1_end)
End If
m0_start = mw_m0_start(m1_start, m1_end)
m0_end = m1_start
m2_start = m1_end
m2_end = mw_m2_end(m1_start, m1_end)
rc = "R-"
ret_ratio = (Range(m2_end).Value - Range(m2_start).Value) / _
(Range(m1_end).Value - Range(m1_start).Value)
(Range(m1_end).Value - Range(m1_start).Value)
If ret_ratio < -2.618 Then
rc = rc + "7"
ElseIf ret_ratio <= -1.618 Then
rc = rc + "6"
ElseIf ret_ratio <= -1 Then
rc = rc + "5"
ElseIf ret_ratio < -0.618 Then
rc = rc + "4"
ElseIf ret_ratio = -0.618 Then
rc = rc + "3"
ElseIf ret_ratio <= -0.382 Then
rc = rc + "2"
Else
rc = rc + "1"
End If
ret_ratio = (Range(m0_end).Value - Range(m0_start).Value) / _
(Range(m1_end).Value - Range(m1_start).Value)
(Range(m1_end).Value - Range(m1_start).Value)
Select Case rc
Case "R-1"
If ret_ratio < -1.618 Then
rc = rc + "d"
ElseIf ret_ratio <= -1 Then
rc = rc + "c"
ElseIf ret_ratio <= -0.618 Then
rc = rc + "b"
Else
rc = rc + "a"
End If
Case "R-2"
If ret_ratio < -1.618 Then
rc = rc + "e"
ElseIf ret_ratio <= -1 Then
rc = rc + "d"
ElseIf ret_ratio <= -0.618 Then
rc = rc + "c"
ElseIf ret_ratio <= -0.382 Then
rc = rc + "b"
Else
rc = rc + "a"
End If
Case "R-3"
If ret_ratio < -2.618 Then
rc = rc + "f"
ElseIf ret_ratio <= -1.618 Then
rc = rc + "e"
ElseIf ret_ratio <= -1 Then
rc = rc + "d"
ElseIf ret_ratio <= -0.618 Then
rc = rc + "c"
ElseIf ret_ratio <= -0.382 Then
rc = rc + "b"
Else
rc = rc + "a"
End If
Case "R-4"
If ret_ratio < -2.618 Then
rc = rc + "e"
ElseIf ret_ratio <= -1.618 Then
rc = rc + "d"
ElseIf ret_ratio <= -1 Then
rc = rc + "c"
ElseIf ret_ratio <= -0.382 Then
rc = rc + "b"
Else
rc = rc + "a"
End If
Case Else
If ret_ratio < -2.618 Then
rc = rc + "d"
ElseIf ret_ratio <= -1.618 Then
rc = rc + "c"
ElseIf ret_ratio <= -1 Then
rc = rc + "b"
Else
rc = rc + "a"
End If
End Select
mw_R_and_C = rc
Exit Function
EH_mw_R_and_C:
'MsgBox (Err.Description)
'mw_R_and_C = CVErr(xlErrNA)
mw_R_and_C = rc
End Function
- 평균가 데이터와 모노파동 데이터가 기록된 엑셀 시트에 각 모노파동의 Rule과 Condition을 구하여 기록하는 매크로를 작성 및 실행하고 그 결과를 이후 분석 과정에서 활용할 수 있다.
- (예시)
Sub RuleAndCondition()
Range("E1").Value = "R_And_C"
'On Error GoTo EH_RuleAndCondition:
addr = Range("C2").Address
addr = Range(addr).Offset(1, 0).Address
Do Until Range(addr).Value = ""
p = Range(addr).Value
If (p - Range(addr).Offset(-1, 0).Value) * (Range(addr).Offset(1, 0).Value - p) _
< 0 Then
Range(addr).Offset(0, 2).Value = mw_R_and_C(Range(addr).Address)
End If
addr = Range(addr).Offset(1, 0).Address
Loop
'Exit Sub
'EH_RuleAndCondition:
End Sub
- 엑셀 화면 예시
댓글 없음:
댓글 쓰기