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 |

Real Code Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
amykobell
Posted : Monday, October 12, 2009 1:25:50 PM
Registered User
Joined: 5/12/2007
Posts: 5
In Real Code, how would I write the statement(s) for the +DX (14 day) not to exceed the SMA (3 day) (SMA is of the +DX 14 day)  by 20% over a period of 5 bars?  I have the +DX and SMA has indicators up on my screen already.  I am trying to avoid my backtest from including bars where the trend gets carried away i.e. from the SMA.  Thanks!
Bruce_L
Posted : Monday, October 12, 2009 1:43:53 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
If you Drag and Drop the +DI and Moving Average into the Code tab of the RealCode Editor, it should create something similar to the first two lines of the following RealCode Rule (you may need to change the variable names assigned to match the variable names given in the RealCode - or change the variables throughout the rest of the RealCode to match whatever names are assigned):

'# DMD = indicator.DirectionalMovementDI
'# MA = indicator.MovingAverage
Static Count As Integer
If isFirstBar Then
    Count = 0
End If
If DMD.Value <= 1.2 * MA.Value Then
    Count += 1
End If
If CurrentIndex >= 5 AndAlso _
    DMD.Value(5) <= 1.2 * MA.Value(5) Then
    Count -= 1
End If
If Count = 5 Then Pass

-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.