Registered User Joined: 1/3/2008 Posts: 20
|
The following formula doesnt show any errors, but it doesn't work correctly either. For instance when I change the first variable that is subtracting "0.5", to say "10.0", it doesn't change the results in backscanner (i.e. the number of winners and losers remian constant). That's problem #1.
Problem #2 - Is there a better way code the close of the 4-day moving average?
If (price.open-.5) < ((price.close(1) + price.close(2) + price.close(3) + price.close(4)) / 4) AndAlso _
price.open < price.low(1) Then pass
|

 Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You haven't outlined your BackScan beyond a single Rule. If I use your RealCode Rule as a Buy Rule (no adjustments) and Exit with a Trade Length of 1 (no other adjustments), I definitely get different results when using both versions.
That said, when you replace .5 with 10.0, for many symbols, you are replacing a first line that is almost always True when the second line is True with a first line that is even more likely to be True when the second line is True. That the differences are subtle is not surprising.
Assuming you want something that matches your RealCode (which would be the previous, not the current, Moving Average), I would probably write it as something like the following (but that doesn't mean it is better):
Static AvgC4p1 As Single
If CurrentIndex >= 5 Then
AvgC4p1 += (Price.Last(1) - Price.Last(5)) / 4
Else If CurrentIndex >= 1 Then
AvgC4p1 += Price.Last(1) / 4
Else
AvgC4p1 = 0
End If
If CurrentIndex >= 4 Then
If (Price.Open - .5) < AvgC4p1 AndAlso _
Price.Open < Price.Low(1) Then pass
Else
SetIndexInvalid
End If
If you want the current 4-Period Simple Moving Average, I would write something like the following instead:
Static AvgC4 As Single
If CurrentIndex >= 4 Then
AvgC4 += (Price.Last - Price.Last(4)) / 4
Else If CurrentIndex >= 1 Then
AvgC4 += Price.Last / 4
Else
AvgC4 = Price.Last / 4
End If
If CurrentIndex >= 3 Then
If (Price.Open - .5) < AvgC4 AndAlso _
Price.Open < Price.Low(1) Then pass
Else
SetIndexInvalid
End If
-Bruce Personal Criteria Formulas TC2000 Support Articles
|