|
|
Help Wanted - Normalized RSI Indicator Coding
Last post 07-29-2009, 10:05 by wabbit. 14 replies.
-
07-18-2009, 9:50 |
-
zigzag
-
-
-
Joined on 01-13-2009
-
-
Posts 38
-
-
|
Help Wanted - Normalized RSI Indicator Coding
Hello All
Borrowing from the idea of a RSI indicator with extremes normalized for bull and bear phases (from June 2009 issue of TASC by Giorgos Siligardos, copyright 2009 Technical Analysis Inc, all rights reserved), I have attempted to code an RSI that would have it's extreme boundaries automatically adjusted according to four "phases" of an ATR-based indicator, as follows:
indic:=ATR(21)/((H+L)/2)*100
The general formula for this normalized RSI is (rsi(prd)-rsi(prd) low boundary)/(rsi(prd) high boundary-rsi(prd) low boundary).
Here is my attempt at the code:
hi1:=Highest(ValueWhen(1,indichi2:=Highest(ValueWhen(1,1hi3:=Highest(ValueWhen(1,2hi4:=Highest(ValueWhen(1,indic>4,RSI(14)));
lo1:=Lowest(ValueWhen(1,indiclo2:=Lowest(ValueWhen(1,1lo3:=Lowest(ValueWhen(1,2lo4:=Lowest(ValueWhen(1,indic>4,RSI(14)));
hilo1:=hi1-lo1;
hilo2:=hi2-lo2;
hilo3:=hi3-lo3;
hilo4:=hi4-lo4;
If(indic
The problem is that it only plots the latest "phase" of the ATR indicator.
Would anybody like to take a swing at it?
Many thanks.
ZigZag
|
|
-
07-18-2009, 10:12 |
-
zigzag
-
-
-
Joined on 01-13-2009
-
-
Posts 38
-
-
|
Re: Help Wanted - Normalized RSI Indicator Coding
Somehow when I copy-paste the code it is not showing right in Forum. I apologize.
The idea is to normalize RSI for each phase (when ATR(21)/(H+L)/2*100 is below 1, between 1 and 2, between 2 and 4 and above 4).
Any help is appreciated.
|
|
-
07-18-2009, 21:39 |
-
johnl
-
-
-
Joined on 11-08-2005
-
-
Posts 388
-
-
|
Re: Help Wanted - Normalized RSI Indicator Coding
Here is my stab at it. Might give you some ideas.
ti := 100; p1:=ATR(21)/((H+L)/2)*100; p1f := 100/(HHV(p1,ti)-LLV(p1,ti)); p1m := (p1-LLV(p1,ti))*p1f; {----------------------------------------} a1:=ValueWhen(1,p1m=0,RSI(14)); a2:=ValueWhen(1,Cross(p1m,25),RSI(14)); a3:=ValueWhen(1,Cross(p1m,50),RSI(14)); a4:=ValueWhen(1,Cross(p1m,75),RSI(14)); b1:=(RSI(14)-a1/(a2-a1)); b2:=(RSI(14)-a2/(a3-a2)); b3:=(RSI(14)-a3/(a4-a3)); b4:=(RSI(14)-a1/(a2-a1)); c1:=If((p1m<25),b1, If((p1m>25) AND (p1m<50),b2, If((p1m>50) AND (p1m<75),b3, b4))); If((c1>100),100,If((c1<0),0,c1))
|
|
-
07-20-2009, 13:28 |
-
zigzag
-
-
-
Joined on 01-13-2009
-
-
Posts 38
-
-
|
Re: Help Wanted - Normalized RSI Indicator Coding
johnl
Thanks for your code - you are clearly a talented code-writer. What I actually had in mind was to have the following indicator plotted (sorry for having been unclear):
(rsi(c,14)-lowest(rsi(c,14)))/(highest(rsi(c,14))-lowest(rsi(c,14)))
using as the "lowest" and "highest" reference data the highest/lowest value of RSI(C,14) according to the range where the value of the formula below falls (ranges: x<=1, 1<x<=2, 2<x<=4 and x>4).
ATR(21)/((H+L)/2)*100
Not sure your code is doing that (I don't mean "not sure" as in "I don't think so"...).
My original (falied) attempt below:
indic:=ATR(21)/((H+L)/2)*100;
hi1:=Highest(ValueWhen(1,indic<=1,RSI(14)));
hi2:=Highest(ValueWhen(1,1<indic<=2,RSI(14)));
hi3:=Highest(ValueWhen(1,2<indic<=4,RSI(14)));
hi4:=Highest(ValueWhen(1,indic>4,RSI(14)));
lo1:=Lowest(ValueWhen(1,indic<=1,RSI(14)));
lo2:=Lowest(ValueWhen(1,1<indic<=2,RSI(14)));
lo3:=Lowest(ValueWhen(1,2<indic<=4,RSI(14)));
lo4:=Lowest(ValueWhen(1,indic>4,RSI(14)));
hilo1:=hi1-lo1;
hilo2:=hi2-lo2;
hilo3:=hi3-lo3;
hilo4:=hi4-lo4;
indic2:=If(indic<=1,(RSI(14)-lo1)/hilo1,If(1<indic<=2,(RSI(14)-lo2)/hilo2,If(2<indic<=4,(RSI(14)-lo3)/hilo3,(RSI(14)-lo4)/hilo4)));
Thanks again. Any help from Forum members is appreciated.
ZigZag
|
|
-
07-21-2009, 2:02 |
-
oztrader
-
-

-
Joined on 07-13-2007
-
Perth Western Australia
-
Posts 108
-
-
|
Re: Help Wanted - Normalized RSI Indicator Coding
Hi ZigZag,
This code works as an Indicator:-
{Wabbit's "Division by Zero" Error Trap} zero:=Power(10,-20);
data:=ATR(21)/MP()*100;
hi1:=Highest(ValueWhen(1,data<=1,RSI(14))); hi2:=Highest(ValueWhen(1,data>1 AND data<=2,RSI(14))); hi3:=Highest(ValueWhen(1,data>2 AND data<=4,RSI(14))); hi4:=Highest(ValueWhen(1,data>4,RSI(14)));
lo1:=Lowest(ValueWhen(1,data<=1,RSI(14))); lo2:=Lowest(ValueWhen(1,data>1 AND data<=2,RSI(14))); lo3:=Lowest(ValueWhen(1,data>2 AND data<=4,RSI(14))); lo4:=Lowest(ValueWhen(1,data>4,RSI(14)));
hilo1:=hi1-lo1; hilo2:=hi2-lo2; hilo3:=hi3-lo3; hilo4:=hi4-lo4;
If(data<=1,(RSI(14)-lo1)/MAX(hilo1,zero), If(data>1 AND data<=2,(RSI(14)-lo2)/Max(hilo2,zero), If(data>2 AND data<=4,(RSI(14)-lo3)/Max(hilo3,zero), (RSI(14)-lo4)/Max(hilo4,zero))));
I have used the the in-built Median Price Indicator which is the same as (H-L)/2.
Cheers,
oz
|
|
-
07-22-2009, 11:14 |
-
zigzag
-
-
-
Joined on 01-13-2009
-
-
Posts 38
-
-
|
Re: Help Wanted - Normalized RSI Indicator Coding
Oztrader
Many thanks for your post. I actually have the same problem with your code that I have with mine (posted previously): the indicator only starts plotting after ATR(21)/MP()*100 crosses above 4 for the first time (on 10/6/08 on daily SPY, for instance). I wonder if you would have the same problem.
I can't seem to be able to figure out why this is happening...
Thanks again for the help.
ZigZag
|
|
-
07-23-2009, 2:46 |
-
oztrader
-
-

-
Joined on 07-13-2007
-
Perth Western Australia
-
Posts 108
-
-
|
Re: Help Wanted - Normalized RSI Indicator Coding
ZigZag,
Yes, although I hadn't noticed this until you raised the issue, but the indicator does not start plotting until all 4 of the range values for the "indic" have been established and I'm not sure why this happens.
Out of interest this code "indic > 1 AND indic <= 2" gives a different result than using this code "1 < indic <=2" when used in your formula!
This can be checked by displaying the following indicators on a chart:-
{Ind1} data:=ATR(21)/((H+L)/2)*100; If(data<=1,1, If(data>1 AND data<=2,2, If(data>2 AND data<=4,3,4)))
{Ind2} indic:=ATR(21)/((H+L)/2)*100; If(indic<=1,1, If(1<indic<=2,2, If(2<indic<=4,3,4)))
oz
|
|
-
07-23-2009, 11:59 |
-
zigzag
-
-
-
Joined on 01-13-2009
-
-
Posts 38
-
-
|
Re: Help Wanted - Normalized RSI Indicator Coding
Oz
thanks for the post. i haven't tried plotting but "indic > 1 AND indic <= 2" is mathematically the same as "1 < indic <=2". it is curious that they would plot differently...
i am really perplexed as to why the indicator is plotting the way it is.
would anybody else like to take a swing at it?
ZigZag
|
|
-
07-24-2009, 0:18 |
-
wabbit
-
-

-
Joined on 10-28-2004
-
Perth, Western Australia
-
Posts 2,042
-
-
|
Re: Help Wanted - Normalized RSI Indicator Coding
zigzag: i haven't tried plotting but "indic > 1 AND indic <= 2" is mathematically the same as "1 < indic <=2". it is curious that they would plot differently...
Have a look in the MS Users Manual for the operator precedence. In the expression: the LT expression will be evaluated first, resulting in a binary 0 or 1; then the LTE expression will be evaluated, so it will be evaluated: |
(1 < indic) <= 2; {so, depending on user definition requirements, it's the same as saying something like} (0 <= 2) AND (1 <= 2); |
so the expression will always be true, and, is not the same as: wabbit
"The question of whether a computer can think is no more interesting than the question of whether a submarine can swim." Edsgar W. Dijkstra MS: 6.52 EOD, 7.x EOD, 8.0 PRO, 9.2 PRO w/QC, 10 PRO w/QC C, 11 PRO w/QC & MDK For custom MetaStock programming : http://www.wabbit.com.au My SkyPE status :  My SkyPE account : wabbit.com.au
|
|
-
07-24-2009, 13:11 |
-
zigzag
-
-
-
Joined on 01-13-2009
-
-
Posts 38
-
-
|
Re: Help Wanted - Normalized RSI Indicator Coding
Hi Wabbit
Thanks for your post - educational, as usual.
Would you care to take a look at the code for the indicator? It is not working as I expect and I cannot figure out why...
Thanks.
ZigZag
|
|
-
07-24-2009, 21:03 |
-
wabbit
-
-

-
Joined on 10-28-2004
-
Perth, Western Australia
-
Posts 2,042
-
-
|
Re: Help Wanted - Normalized RSI Indicator Coding
Hi zz, You will need to deal with the periods when ValueWhen() returns N/A. You could use a whole pile of calls to the forum.sum function but this would be rather unwieldy and probably quite slow; maybe even slow enough to warrant reverting to using a PREV based latch?? (Although I haven't looked too closely as to the specifics of how you'd employ it). zigzag:It is not working as I expect and I cannot figure out why..
Can you please post an annotated chart and more details? Comments like this aren't much use in bug-hunting! wabbit
"The question of whether a computer can think is no more interesting than the question of whether a submarine can swim." Edsgar W. Dijkstra MS: 6.52 EOD, 7.x EOD, 8.0 PRO, 9.2 PRO w/QC, 10 PRO w/QC C, 11 PRO w/QC & MDK For custom MetaStock programming : http://www.wabbit.com.au My SkyPE status :  My SkyPE account : wabbit.com.au
|
|
-
07-25-2009, 20:14 |
-
zigzag
-
-
-
Joined on 01-13-2009
-
-
Posts 38
-
-
|
Re: Help Wanted - Normalized RSI Indicator Coding
thanks Wabbit
the problem I am having is that the indicator doesn't start plotting until ATR(21)/MP()*100 first crosses above four.
how would one post a chart in Forum?
ZigZag
|
|
-
07-25-2009, 22:24 |
-
wabbit
-
-

-
Joined on 10-28-2004
-
Perth, Western Australia
-
Posts 2,042
-
-
|
Re: Help Wanted - Normalized RSI Indicator Coding
http://forum.equis.com/forums/thread/19928.aspxwabbit
"The question of whether a computer can think is no more interesting than the question of whether a submarine can swim." Edsgar W. Dijkstra MS: 6.52 EOD, 7.x EOD, 8.0 PRO, 9.2 PRO w/QC, 10 PRO w/QC C, 11 PRO w/QC & MDK For custom MetaStock programming : http://www.wabbit.com.au My SkyPE status :  My SkyPE account : wabbit.com.au
|
|
-
07-27-2009, 8:22 |
-
wabbit
-
-

-
Joined on 10-28-2004
-
Perth, Western Australia
-
Posts 2,042
-
-
|
Re: Help Wanted - Normalized RSI Indicator Coding
ZZ, Using the free forum.dll to eliminate the N/A from the ValueWhen() function calls: |
data:=ATR(21)/MP()*100; i:=RSI(14);
hi1:=Highest(ExtFml("forum.sum",ValueWhen(1,data<=1,i),1)); hi2:=Highest(ExtFml("forum.sum",ValueWhen(1,data>1 AND data<=2,i),1)); hi3:=Highest(ExtFml("forum.sum",ValueWhen(1,data>2 AND data<=4,i),1)); hi4:=Highest(ExtFml("forum.sum",ValueWhen(1,data>4,i),1));
lo1:=Lowest(ExtFml("forum.sum",ValueWhen(1,data<=1,i),1)); lo2:=Lowest(ExtFml("forum.sum",ValueWhen(1,data>1 AND data<=2,i),1)); lo3:=Lowest(ExtFml("forum.sum",ValueWhen(1,data>2 AND data<=4,i),1)); lo4:=Lowest(ExtFml("forum.sum",ValueWhen(1,data>4,i),1));
hilo1:=hi1-lo1; hilo2:=hi2-lo2; hilo3:=hi3-lo3; hilo4:=hi4-lo4;
zero:=Power(10,-8);
100* If(data<=1,(i-lo1)/Max(hilo1,zero), If(data>1 AND data<=2,(i-lo2)/Max(hilo2,zero), If(data>2 AND data<=4,(i-lo3)/Max(hilo3,zero), (i-lo4)/Max(hilo4,zero)))); |
Hope this helps. wabbit
"The question of whether a computer can think is no more interesting than the question of whether a submarine can swim." Edsgar W. Dijkstra MS: 6.52 EOD, 7.x EOD, 8.0 PRO, 9.2 PRO w/QC, 10 PRO w/QC C, 11 PRO w/QC & MDK For custom MetaStock programming : http://www.wabbit.com.au My SkyPE status :  My SkyPE account : wabbit.com.au
|
|
-
07-29-2009, 10:05 |
-
wabbit
-
-

-
Joined on 10-28-2004
-
Perth, Western Australia
-
Posts 2,042
-
-
|
Re: Help Wanted - Normalized RSI Indicator Coding
ZZ, As much as yesterday's code showed how to eliminate the N/A by using the forum.sum functionality, I don't think the code achieved the aim? I haven't spent much time thinking about what the resultant curve should look like and as no chart has been posted, I hope you'll find this version is faster whilst still eliminating the ValueWhen() N/A problem and produces a curve more inline with what I think the objective should be? |
ind:=RSI(14); data:=200*ATR(21)/(H+L);
zero:=Power(10,-8); i:=Cum(IsDefined(data))=1;
x:=data<=1; hi:=HighestSince(1,i OR x=0,ind); lo:=LowestSince(1,i OR x=0,ind); y1:=x*(ind-lo)/Max(hi-lo,zero);
x:=data>1 AND data<=2; hi:=HighestSince(1,i OR x=0,ind); lo:=LowestSince(1,i OR x=0,ind); y2:=x*(ind-lo)/Max(hi-lo,zero);
x:=data>2 AND data<=4; hi:=HighestSince(1,i OR x=0,ind); lo:=LowestSince(1,i OR x=0,ind); y3:=x*(ind-lo)/Max(hi-lo,zero);
x:=data>4; hi:=HighestSince(1,i OR x=0,ind); lo:=LowestSince(1,i OR x=0,ind); y4:=x*(ind-lo)/Max(hi-lo,zero);
100*(y1+y2+y3+y4);
|
I have been putting in 14-16 hour days on a contract this week so I haven't been able to spend much time looking too closely at anything else but my own stuff; some comments about what you think is working and what isn't will allow me to dedicate more time to this or other members, otherwise I will consider this thread resolved? Hope this helps. wabbit
"The question of whether a computer can think is no more interesting than the question of whether a submarine can swim." Edsgar W. Dijkstra MS: 6.52 EOD, 7.x EOD, 8.0 PRO, 9.2 PRO w/QC, 10 PRO w/QC C, 11 PRO w/QC & MDK For custom MetaStock programming : http://www.wabbit.com.au My SkyPE status :  My SkyPE account : wabbit.com.au
|
|
|
|