Here's a formula I run in Amibroker 6.40.4 64-bit. When I run it, the following error comes up. The output report is all NaN and doesn't contain real numbers. Please let me know the fix for this.
// Set some parameter values
minHV = 0.07;
maxPositions = 30;
useRSI = True;
// We optionally use a threshold for trade entry. Set to 100 if you don't want it.
threshold = 100;
function ConnorsRSI(lenRSI, lenUD, lenROC) {
upDays = BarsSince(C <= Ref(C,-1));
downDays = BarsSince(C >= Ref(C,-1));
updownDays = IIf(upDays > 0, upDays, IIf(downDays > 0, -downDays, 0));
crsiT = ( PercentRank(ROC(C,1), lenROC) + RSIa(updownDays,lenUD) + RSI(lenRSI))/3;
return crsiT;
}
// We set our trading settings
SetTradeDelays(0, 0, 0, 0);
SetOption("InitialEquity", 100000);
SetOption("AllowSameBarExit", True);
SetOption("DisableRuinStop", True);
// These settings are necessary for rotational backtesting
SetBacktestMode(backtestRotational);
SetOption("MaxOpenPositions", maxPositions);
SetOption("WorstRankHeld", maxPositions);
SetPositionSize(100/maxPositions, spsPercentOfEquity);
SetBarsRequired(100);
// Calculate base requirements
pctChanges = Nz(ROC(Close, 1, False));
hv = Nz(StDev(pctChanges, 100, True)) * sqrt(252);
if (useRSI) {
indicator = Nz(RSI(2));
}
else {
indicator = Nz(ConnorsRSI(3, 2, 100));
}
baseRequirementsMet = hv >= minHV && (indicator <= threshold);
// The position score is simply 100 - indicator if the base requirements are met and zero otherwise.
PositionScore = (100 - indicator) * baseRequirementsMet; // Note that this can never be negative. No short trades.
// Plotting these items can help with visual debugging.
// Plot(PositionScore, "Position Score", colorRed);
// Plot(indicator, "Indicator", colorRed);
