Ehler's Adaptive RSI

Posted By: yoki

Ehler's Adaptive RSI - 05/27/16 20:09

Hello everyone,
I'm relatively new to the forum and zorro. I just wanted to be sure that Ehler's adaptive RSI indicator from his "Cycle Analytics for Traders" book is not on the zorro indicator list. is that right? just want to be sure before I attempt to code it lol.
Posted By: yoki

Re: Ehler's Adaptive RSI - 06/02/16 05:53

I've worked a little bit on converting John Ehler's Easy Language code for his adaptive RSI into zorro code. I'm a beginner to coding in general and have only gone through a beginner's python course. Hoping that somebody can help me put this together.

Below is John Ehler's Easy Language code for the adaptive RSI:

Quote:

//Declares all variables...

//Highpass filter cyclic components whos periods are shorter than 48 bars
Alpha1 = (Cosine(.707*360/48) + Sine (.707*360 / 48) – 1) / Cosine (.707*360 / 48);
HP = (1-alpha1 / 2) * (1 – alpha1 / 2) * (Close – 2*Close[1]) + Close[2]) + 2*(1-alpha1*HP[1] – (1-alpha1)*(1-alpha1)*HP[2]
//Smooth with a super smoother filter
a1 = exp(-1.414*3.14159 / 10);
b1 = 2*a1*cos(1.414*180 / 10);
c2 = b1;
c3 = -a1*a1;
c1 = 1 - c2 - c3;
Filt = c1*(HP + HP[1]) / 2 + c2*Filt[1] + c3 * Filt[2];

//John Ehlers then proceeds to calculate the dominant cycle with his method (not shown)

//Adaptive RSI
ClosesUp(0);
ClosesDn(0);
Denom(0);
MyRSI(0);
ClosesUp = 0;
ClosesDn = 0;

For Count = 0 to IntPortion(DominantCycle / 2 – 1) Begin
If (Filt[count] > Filt[count + 1])
Then ClosesUp = ClosesUp + (Filt[count] - Filt[count + 1]);

If (Filt[count] < Filt[count + 1])
Then ClosesDn = ClosesDn + (Filt[count + 1] - Filt[count]);

if (Denom[0] <> 0 && Denom[1] <> 0) Then
MyRSI = c1 * (ClosesUp[0] / Denom[0] + ClosesUp[1] / Denom[1]) / 2 + c2 * MyRSI[1] + c3 * MyRSI[2];

Plot1(MyRSI);


Below is my failed attempt at converting the script to zorro's language:

Quote:
//John Ehlers Adaptive RSI from "Cycle Analytics For Traders"

function run(){
var a1 = exp(-1.414*3.14159 / 10);
var b1 = 2*a1*cos(1.414*180 / 10);
var c2 = b1;
var c3 = -a1*a1;
var c1 = 1 - c2 - c3;

vars Price = series(price());
vars PriceSmooth = series(Smooth(Price, 10));

//Highpass Filter
vars HP = series(HighPass1(Price, 48));

//Smooth with SuperSmoother
vars Filt = series(Smooth(HP,10));

//Dominant Period
var Dominant = DominantPeriod(Price, 10);

//Adaptive RSI
var ClosesUp = 0;
var ClosesDn = 0;
int count = 0;

for(count = 0; count < (Dominant / 2); count++) {

if (Filt[count] > Filt[count + 1])
return ClosesUp = ClosesUp + (Filt[count] - Filt[count + 1]);

else if (Filt[count] < Filt[count + 1])
return ClosesDn = ClosesDn + (Filt[count + 1] - Filt[count]);
}

vars MyRSI;
vars Denom = ClosesUp + ClosesDn;

if (Denom[0] != 0 && Denom[1] != 0)
MyRSI = c1 * (ClosesUp[0] / Denom[0] + ClosesUp[1] / Denom[1]) / 2 + c2 * MyRSI[1] + c3 * MyRSI[2];


plot("MyRSI", Dominant, NEW, RED);
}


What I'm mainly not sure about is how to convert the easy language code to zorro that has the same variable one is defining in its equation. f.i. MyRSI = c1 * MyRSI[1] + MyRSI[2]. So I'm really not sure if my "Filt" variable is right and just really now sure how to define the "MyRSI" varaible in zorro. Honestly not sure if any of this is right. Any help would be super appreciated.
Posted By: jcl

Re: Ehler's Adaptive RSI - 06/02/16 10:52

As far as I can see at a glance, it looks mostly correct except for a few things. The "return" statements in the count loop are not in Ehler's code, and should also not be in the C code. And ClosesUp, Denom, MyRSI must be series, not single variables.
Posted By: yoki

Re: Ehler's Adaptive RSI - 06/04/16 01:34

Thanks a lot JCL. I think I got it to right now...maybe. I'll post the script I have here so anyone who wants to implement it into their strategy can. Going to focus on using this for stocks as I've heard that stocks are more mean reverting than forex. Feel free to post if anyone has any ideas on how to make a good strategy using this indicator/oscillator. I'll post here if I find anything interesting.

Quote:
function run(){

var a1 = exp(-1.414*3.14159 / 10);
var b1 = 2*a1*cos(1.414*180 / 10);
var c2 = b1;
var c3 = -a1*a1;
var c1 = 1 - c2 - c3;

vars Price = series(price());
vars PriceSmooth = series(Smooth(Price, 10));
vars SMA200 = series(SMA(Price,200));

//Highpass Filter
vars HP = series(HighPass1(Price, 48));

//Smooth with SuperSmoother
vars Filt = series(Smooth(HP,10));

//Dominant Period
vars Dominant = series(DominantPeriod(Price, 50));


//Adaptive RSI
vars ClosesUp = series(0);
vars ClosesDn = series(0);
vars MyRSI = series(0);
vars Denom = series(0);
int count = 0;

for(count = 0; count < (Dominant[0] / 2 - 1); count++) {

if (Filt[count] > Filt[count + 1])
ClosesUp[0] = ClosesUp[0] + (Filt[count] - Filt[count + 1]);

if (Filt[count] < Filt[count + 1])
ClosesDn[0] = ClosesDn[0] + (Filt[count + 1] - Filt[count]);
}

Denom[0] = ClosesUp[0] + ClosesDn[0];

if (Denom[0] != 0 && Denom[1] != 0)
MyRSI[0] = c1 * (ClosesUp[0] / Denom[0] + ClosesUp[1] / Denom[1]) / 2 + c2 * MyRSI[1] + c3 * MyRSI[2];

plot("MyRSI", MyRSI, NEW, RED);

}
© 2024 lite-C Forums