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