FILE: modSwing.bas
The module uses the global variables:
Q() As QUOTE_TYPE
S() As SWING_TYPE
NumQuotes As Long
NumSwings As Long
The calling format is:
NumQuotes = GetData()
NumSwings = CalculateSwingData(3)
Option Explicit
Public Function CalculateSwingData(RevAmt%) As Long
Dim i&, j&, Direction&
On Error GoTo Err_CalculateSwingData
' Initiatialize first swing pair
S(1).Price = Q(1).C
S(1).ArIdx = 1
' Initialize first direction
For i = 2 To NumQuotes
If Q(i).H >= Q(1).H Then
Direction = UP
S(2).Price = Q(i).H
S(2).ArIdx = i
Exit For
ElseIf Q(i).L < Q(1).L Then
Direction = DOWN
S(2).Price = Q(i).L
S(2).ArIdx = i
Exit For
End If
Next i
j = i
' Calculate remaining swing pairs iteratively
For i = j + 1 To NumQuotes
If Direction = UP Then
If Q(i).H > S(j).Price Then
S(j).Price = Q(i).H
S(j).ArIdx = i
ElseIf S(j).Price - Q(i).L >= RevAmt Then
Direction = DOWN
j = j + 1
S(j).Price = Q(i).L
S(j).ArIdx = i
End If
ElseIf Direction = DOWN Then
If Q(i).L < S(j).Price Then
S(j).Price = Q(i).L
S(j).ArIdx = i
ElseIf Q(i).H - S(j).Price >= RevAmt Then
Direction = UP
j = j + 1
S(j).Price = Q(i).H
S(j).ArIdx = i
End If
End If
Plotin giola dFtuar eFCr hdslRTm
339
If j = MAX_SWINGS Then
Exit For
End If
Next i
If S(j).ArIdx < NumQuotes Then
j = j + 1
S(j).Price = Q(NumQuotes).C
S(j).ArIdx = NumQuotes
End If
CalculateSwingData = j
Exit Function
Err_CalculateSwingData:
MsgBox Err.Description
End Function
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment