Meowmechon
New Member
- Joined
- Sep 12, 2013
- Messages
- 4
Hi people !
Could anyone kindly point me to where this nuisance error comes from ? I check practically every corner of the coding but just don't see how come there is any "for" or "next" absent. I also tried to solve the problem myself by looking up some online forums on similar questions, but it seems most of the cases are invariably missing an "end if", which doesn't really fit my kind of circumstance. Also, is there any other potential errors seeming obvious in the coding lines apart from the known "for...next" ? Cause I read that VBA has a tendency to propagate glitches and I would love to target down as early as possible too ! I know the coding may appear to be a bit lengthy and might get your eyes somewhat sore, but I'm really a freshman with limited knowledge on VBA so please forgive me !
Many thanks !
Could anyone kindly point me to where this nuisance error comes from ? I check practically every corner of the coding but just don't see how come there is any "for" or "next" absent. I also tried to solve the problem myself by looking up some online forums on similar questions, but it seems most of the cases are invariably missing an "end if", which doesn't really fit my kind of circumstance. Also, is there any other potential errors seeming obvious in the coding lines apart from the known "for...next" ? Cause I read that VBA has a tendency to propagate glitches and I would love to target down as early as possible too ! I know the coding may appear to be a bit lengthy and might get your eyes somewhat sore, but I'm really a freshman with limited knowledge on VBA so please forgive me !
Many thanks !
Code:
Function FR_xy(P, n, x, xn, y, yn, S_M, R_F)
Dim R(), Best(), PH, PL, P0, Cnb, Cns, Cb, Cs, Dn, Db, Ds, Ct, Mean(), Sharpe(), Max(), Hit, RH, RL, B_Win, B_Lose, S_Win, S_Lose
ReDim R(n - 1), Mean(n), Sharpe(n), Max(13), Best(n)
Hit = 0
For w = 1 To xn
For q = 1 To yn
If y(q) >= x(w) Then GoTo 1
Ct = Ct + 1
i = 0
PH = P(1)
PL = P(1)
P0 = P(1)
RH = 0
RL = 0
Dn = 1
Db = 0
Ds = 0
Cb = 0
Cs = 0
Cnb = 0
Cns = 0
B_Win = 0
B_Lose = 0
S_Win = 0
S_Lose = 0
For t = 2 To n
If P(t) = 0 Then
If i = 0 Then
Dn = Dn + 1
GoTo 0
If i = 1 Then
Db = Db + 1
GoTo 0
If i = -1 Then
Ds = Ds + 1
GoTo 0
End If
If i = 0 Then
R(t) = 0
Dn = Dn + 1
If P(t) > P(t - 1) Then
If PH < P(t) Then
PH = P(t)
End If
ElseIf P(t) < P(t - 1) Then
If PL > P(t) Then
PL = P(t)
End If
End If
If (P(t) - PL) / PL >= x(w) Then
i = 1
Cnb = Cnb + 1
PH = P(t)
P0 = P(t)
PL = P(t)
ElseIf (PH - P(t)) / PH >= y(q) Then
i = -1
Cns = Cns + 1
PH = P(t)
P0 = P(t)
PL = P(t)
End If
End If
If i = 1 Then
R(t) = Application.Ln(P(t) / P(t - 1))
Db = Db + 1
RH = RH + R(t)
If P(t) > P(t - 1) Then
If PH < P(t) Then
PH = P(t)
End If
End If
If (PH - P(t)) / PH >= y(q) Then
If P(t) - P0 > 0 Then
B_Win = B_Win + 1
ElseIf P(t) - P0 <= 0 Then
B_Lose = B_Lose + 1
End If
i = 0
Cb = Cb + 1
PH = P(t)
PL = P(t)
End If
End If
If i = -1 Then
R(t) = Application.Ln(P(t - 1) / P(t))
Ds = Ds + 1
RL = RL + R(t)
If P(t) < P(t - 1) Then
If PL > P(t) Then
PL = P(t)
End If
End If
If (P(t) - PL) / PL >= x(w) Then
If P(t) - P0 < 0 Then
S_Win = S_Win + 1
ElseIf P(t) - P0 >= 0 Then
S_Lose = S_Lose + 1
End If
i = 0
Cs = Cs + 1
PH = P(t)
PL = P(t)
End If
End If
0
Next
If S_M = "M" Then
Mean(Ct) = Application.Sum(R) / (Ds + Db) * 252
If Mean(Ct) > 0 Then
Hit = Hit + 1
End If
If Ct > 2 Then
If Mean(Ct) > Mean(Ct - 1) Then
Max(0) = x(w)
Max(1) = y(q)
Max(2) = Mean(Ct)
Max(3) = Db
Max(4) = Ds
Max(5) = Cb
Max(6) = Cs
Max(7) = B_Win
Max(8) = B_Lose
Max(9) = S_Win
Max(10) = S_Lose
Max(11) = RH
Max(12) = RL
Max(13) = Hit
For u = 2 To n
Best(u) = R(u)
Next
End If
End If
ElseIf S_M = "S" Then
'Sharpe Formula : TBA
End If
1
Next
Next
If R_F = "R" Then
FR_xy = Best
ElseIf R_F = "F" Then
FR_xy = Ct
End If
End Function
Last edited by a moderator: