Connors RSI Code (Amibroker code)
The original article can be found here.
Amibroker code:
The code below can be saved as an indicator.
PeriodRSI = Param(“PeriodRSI”, 3);
PeriodUD = Param(“PeriodUD”, 3);
PeriodROC = Param(“PeriodROC”, 3);
function ConnorsRSI(array, lenRSI, lenUD, lenROC) {
upDays = BarsSince(array <= Ref(array, -1));
downDays = BarsSince(array >= Ref(array, -1));
updownDays = IIf(upDays > 0, upDays, IIf(downDays > 0, -downDays, 0));
return (RSI(lenRSI) + RSIa(updownDays, lenUD) + PercentRank(ROC(array, 1), lenROC)) / 3;
}
SetChartOptions(0, 0, chartGrid30 | chartGrid70);
Plot(ConnorsRSI(Close, PeriodRSI, PeriodUD, PeriodROC), _DEFAULT_NAME(), ParamColor(“Color”, colorCycle), ParamStyle(“Style”));
A backtest can look like this (with optimization):
oddis=Optimize(“Days in RSI”,2,2,15,1);
rsiValue = ConnorsRSI(Close, oddis, oddis, oddis);
oddis1=Optimize(“Thresholds”,10,5,40,5);
Buy =rsivalue<oddis1 ;
BuyPrice = Close;
Sell = rsivalue>100-oddis1 ;
SellPrice = Close ;
