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 |

CODE FOR RSI Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
giomorales
Posted : Monday, July 13, 2009 12:39:16 AM
Registered User
Joined: 3/12/2007
Posts: 10
Can you please help me with the code for the following 4-period RSI rules?

1.  RSI drops three days in a row and the first day it drops below 60

2.  RSI drops below 10 on the third day

Thanks,
Gio
Bruce_L
Posted : Monday, July 13, 2009 11:02:06 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
If you Drag and Drop the RSI Indicator into the RealCode Editor, it should create something similar to the first line of the RealCode Rule:

'# WR = indicator.WildersRSI
If WR.Value < WR.Value(1) AndAlso _
    WR.Value(1) < WR.Value(2) AndAlso _
    WR.Value(2) < WR.Value(3) AndAlso _
    WR.Value(2) < 60 AndAlso _
    WR.Value < 10 Then Pass

This RealCode Rule only checks for the Values to be below 60 and below 10 on the given days. If you need them to have crossed down through 60 and 10 on the given days, you might wish to try the following RealCode Rule instead:

'# WR = indicator.WildersRSI
If WR.Value < 10 AndAlso _
    WR.Value(1) >= 10 AndAlso _
    WR.Value(1) < WR.Value(2) AndAlso _
    WR.Value(2) < 60 AndAlso _
    WR.Value(3) >= 60 Then Pass

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
rassom
Posted : Thursday, July 16, 2009 3:51:42 AM
Registered User
Joined: 3/18/2009
Posts: 61
Hi,

I've just read about a similar (simple) indicator to RSI that I would like to test in two different versions. The indicator is called DV(2).

Would someone help me with the code for them, please?

Version 1 - unbounded:
a) For each trading day calculate: [(close / average of the high and low price) – 1].
b) take the average of today and yesterday’s result.

Version 2 - bounded:
a) Take today’s unbounded value and compare it to the last year (252 trading days). The highest value over the last year receives a value of 100, the lowest 0, and everything else its percentage rank in between.


Thanks very much in advance :)

Best regards,
Rasmus
Bruce_L
Posted : Thursday, July 16, 2009 9:40:42 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
You should be able to create the first version using the following RealCode Indicator (it assumes a Simple Moving Average for the second step):

'# Period = UserInput.Integer = 2
Static DV As Single
If isFirstBar Then
    DV = 0
End If
DV += (2 * Price.Last / (Price.High + Price.Low) - 1) / Period
If CurrentIndex >= Period Then
    DV -= (2 * Price.Last(Period) / (Price.High(Period) + Price.Low(Period)) - 1) / Period  
End If
If CurrentIndex >= Period - 1 Then
    Plot = DV
Else
    Plot = Single.NaN
End If

Adding a Stochastics of Indicator to the RealCode Indicator given above as a Child Indicator should create the second bounded version.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
rassom
Posted : Friday, July 17, 2009 4:37:03 AM
Registered User
Joined: 3/18/2009
Posts: 61
Thanks *very* much, Bruce :)

I'll go and give it a try right away.

If I was to create a DVI(5), would that just require replacing the number 2 in the code with 5 or is it more complex than that?

Thanks again :-))

Rasmus
rassom
Posted : Friday, July 17, 2009 6:33:40 AM
Registered User
Joined: 3/18/2009
Posts: 61
Never mind about my last question about replacing 2 with 5, double clicking the indicator gives me the option of selecting days.
rassom
Posted : Friday, July 17, 2009 7:11:20 AM
Registered User
Joined: 3/18/2009
Posts: 61
Hi again,

A couple of questions: a) The SMA you are referring to for the second step, is that supposed to be applied to the DV(2) indicator?
b) Which settings should I use for the stochastics child indicator once I've created it? c) Stochastics for the indicator creates a "%D 5, Simple" - should I delete/hide that or is it used for anything?

Thanks again,
Rasmus
Bruce_L
Posted : Friday, July 17, 2009 9:32:30 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
QUOTE (rassom)
The SMA you are referring to for the second step, is that supposed to be applied to the DV(2) indicator?

It is the average mentioned in your description of Version 1 as b and is an average of what results from a. The assumption by me is that the average of today and yesterday's result is because the DV period is 2.

QUOTE (rassom)
Version 1 - unbounded:
a) For each trading day calculate: [(close / average of the high and low price) – 1].
b) take the average of today and yesterday’s result.


QUOTE (rassom)
Which settings should I use for the stochastics child indicator once I've created it?

Set the Period to 252 and the %K to 1. Since the %K is 1, the Avg Type does not matter.

QUOTE (rassom)
Stochastics for the indicator creates a "%D 5, Simple" - should I delete/hide that or is it used for anything?

It's just a Moving Average of the Stochastic. If you want this Moving Average (for crossovers or just to have a smoother version of the Indicator) you can keep it. Otherwise you can delete it.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
rassom
Posted : Friday, July 17, 2009 11:06:30 AM
Registered User
Joined: 3/18/2009
Posts: 61
That's all I needed. Thanks very much, Bruce. Appreciate your help!
Bruce_L
Posted : Friday, July 17, 2009 11:10:34 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
You're welcome.

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