Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (1 invisible), 672 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Connors RSI implementation #467698
08/23/17 11:32
08/23/17 11:32
Joined: Feb 2017
Posts: 369
D
Dalla Offline OP
Senior Member
Dalla  Offline OP
Senior Member
D

Joined: Feb 2017
Posts: 369
I've implemented Connors RSI, sharing here in case some one is interesed

Code:
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
Code:
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: Dalla] #467702
08/23/17 15:42
08/23/17 15:42
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline
User
MatPed  Offline
User
M

Joined: Feb 2015
Posts: 652
Milano, Italy
Thank you for sharing!

Re: Connors RSI implementation [Re: MatPed] #467705
08/23/17 18:54
08/23/17 18:54
Joined: Mar 2017
Posts: 48
Bologna
K
kmerlo Offline
Newbie
kmerlo  Offline
Newbie
K

Joined: Mar 2017
Posts: 48
Bologna
me too I want to say thanks to Dalla.

Re: Connors RSI implementation [Re: kmerlo] #467745
08/26/17 07:26
08/26/17 07:26
Joined: Aug 2017
Posts: 40
J
johnnyp Offline
Newbie
johnnyp  Offline
Newbie
J

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.
Code:
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: johnnyp] #467746
08/26/17 07:38
08/26/17 07:38
Joined: Feb 2017
Posts: 369
D
Dalla Offline OP
Senior Member
Dalla  Offline OP
Senior Member
D

Joined: Feb 2017
Posts: 369
Thanks, clearly a bug. I updated the post to fix the issue

Re: Connors RSI implementation [Re: Dalla] #467753
08/27/17 13:56
08/27/17 13:56
Joined: Aug 2017
Posts: 40
J
johnnyp Offline
Newbie
johnnyp  Offline
Newbie
J

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.

Code:
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
M
Materz Offline
Newbie
Materz  Offline
Newbie
M

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: Materz] #471752
03/18/18 19:11
03/18/18 19:11
Joined: Aug 2017
Posts: 102
Spain
B
Brax Offline
Member
Brax  Offline
Member
B

Joined: Aug 2017
Posts: 102
Spain
You must add the function in another file, indicator.c is for educational purpose only.

Re: Connors RSI implementation [Re: Brax] #473235
06/22/18 18:53
06/22/18 18:53
Joined: Dec 2017
Posts: 19
M
Materz Offline
Newbie
Materz  Offline
Newbie
M

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
M
MatPed Offline
User
MatPed  Offline
User
M

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.
Page 1 of 2 1 2

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1