Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

RealCode Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
rostifritz
Posted : Tuesday, June 9, 2009 1:30:51 AM
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

 

Bruce_L
Posted : Tuesday, June 9, 2009 8:46:39 AM


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
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.