1 registered members (AndrewAMD),
177
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Connors RSI implementation
#467698
08/23/17 11:32
08/23/17 11:32
|
Joined: Feb 2017
Posts: 369
Dalla
OP
Senior Member
|
OP
Senior Member
Joined: Feb 2017
Posts: 369
|
I've implemented Connors RSI, sharing here in case some one is interesed
vars CRSI(vars close, int rsiPeriod, int streakRsiPeriod, int percentRankPeriod) {
static int streak = 0;
if (close[0] > close[1]) {
if (streak >= 0) {
streak += 1;
} else {
streak = 1;
}
} else if (close[0] < close[1]) {
if (streak <= 0) {
streak -= 1;
} else {
streak = -1;
}
} else if (close[0] == close[1]) {
streak = 0;
}
vars streakSeries = series(streak);
vars rsi = series(RSI(close,rsiPeriod));
vars streakRsi = series(RSI(streakSeries,streakRsiPeriod));
vars returns = series((close[0]-close[1])/close[1]);
vars rank = series(PercentRank(returns,percentRankPeriod,returns[0]));
return series((rsi[0] + streakRsi[0] + rank[0])/3);
}
Call by doing something like
vars close = series(priceClose());
vars crsiSeries = CRSI(close,3,2,100);
Please note that this requires the 1.61 Beta since it uses the new PercentRank function
Last edited by Dalla; 08/26/17 07:37.
|
|
|
Re: Connors RSI implementation
[Re: kmerlo]
#467745
08/26/17 07:26
08/26/17 07:26
|
Joined: Aug 2017
Posts: 40
johnnyp
Newbie
|
Newbie
Joined: Aug 2017
Posts: 40
|
This code sets streak to 1 if the price hasn't moved. Setting streak to 0 would seem more logical in that case. For those not yet using the beta version. I think this should do the trick.
var PercentRank(var* Data,int Period,var Value)
{
int i,n;
for(i=0,n=0; i<Period; i++)
if(Data[i] <= Value) n++;
return ((var)n)/Period;
}
|
|
|
Re: Connors RSI implementation
[Re: Dalla]
#467753
08/27/17 13:56
08/27/17 13:56
|
Joined: Aug 2017
Posts: 40
johnnyp
Newbie
|
Newbie
Joined: Aug 2017
Posts: 40
|
This indicator returns a series unlike most other indicators. I also notice that the code uses lots of series where they aren't strictly necessary. So in the interest of learning here is my version that returns a single value, uses fewer series, and limits the length of the series used (except for the streak series). I didn't limit the length of the streak series because that changes the indicator output, probably because the RSI calculation uses EMAs.
var CRSI(vars close, int rsiPeriod, int streakRsiPeriod, int percentRankPeriod)
{
vars streak = series(0);
vars returns = series((close[0]-close[1])/close[1], percentRankPeriod);
if (close[0] > close[1])
streak[0] = max(1, streak[1] + 1);
else if (close[0] < close[1])
streak[0] = min(-1, streak[1] - 1);
else // (close[0] == close[1])
streak[0] = 0;
var rsi = RSI(close,rsiPeriod);
var streakRsi = RSI(streak,streakRsiPeriod);
var rank = PercentRank(returns,percentRankPeriod,returns[0]);
return (rsi + streakRsi + rank)/3;
}
|
|
|
Re: Connors RSI implementation
[Re: johnnyp]
#471737
03/17/18 18:51
03/17/18 18:51
|
Joined: Dec 2017
Posts: 19
Materz
Newbie
|
Newbie
Joined: Dec 2017
Posts: 19
|
Hi ,
I have added your ConnorsRSI to indicator.c , i am unable to use or call the indicator in my strategy .
Kindly assist.
Last edited by Materz; 03/17/18 19:28.
|
|
|
Re: Connors RSI implementation
[Re: Brax]
#473235
06/22/18 18:53
06/22/18 18:53
|
Joined: Dec 2017
Posts: 19
Materz
Newbie
|
Newbie
Joined: Dec 2017
Posts: 19
|
Hi all,
I need assistance on the below Connors RSI Script, it opens Position wrongly. //**** ConnorsRSI Short Term Trading Strategy ** // function run() { set(PARAMETERS); // generate and use optimized parameters BarPeriod = 60; // 1 hour bars LookBack = 500; StartDate = 2015;
vars Price = series(priceClose()); vars Close = series(priceClose()); vars SMAFast = series(SMA(Close,5)); // Fast SMA for Position trigger vars SMASlow = series(SMA(Close,200)); // Slow SMA for Trend Direction vars cRSI = series(ConnorsRSI(Close,2,3,100)); // ConnorsRSI int Threshold1=65; int Threshold2= 25; Capital= 5000; Stop=2*ATR(10);
// ** set up max trades ** // MaxLong = MaxShort = 1; // ** Type ** // while(asset(loop("EUR/USD","USD/JPY"))) Margin = 0.5 * OptimalF * Capital/2 ; // *** Condition for Buy *** // if(crossUnder(cRSI,Threshold2) && (Price > SMASlow && Price < SMAFast)) enterLong(); // ** Exit Long Position ** // if( NumOpenLong >0 && Price > SMAFast) exitLong(); // *** Condition for Sell *** // if(crossOver(cRSI,Threshold1) && (Price < SMASlow && Price > SMAFast)) enterShort(); // ** Exit Short Position ** // if(NumOpenShort >0 && Price < SMAFast) exitShort(); }
|
|
|
Re: Connors RSI implementation
[Re: Materz]
#473238
06/22/18 22:37
06/22/18 22:37
|
Joined: Feb 2015
Posts: 652 Milano, Italy
MatPed
User
|
User
Joined: Feb 2015
Posts: 652
Milano, Italy
|
do not use set(PARAMETERS);
you are not optimizing any parameters.
CiaO
Last edited by MatPed; 06/23/18 15:30.
|
|
|
|