I am trying to mimic a version of the NASDAQ/NYSE relative strength indicator that Gerald Appel wrote about in Chapter 2 of his book, "Technical Analysis - Power Tools for Active Investors". I have used a version of this for a long time, with the difference being that I use the SPX instead of the NYSE composite index.
The idea behind the indicator is that when the NASDAQ is leading, that is a bullish state for the market.
To determine the lead/lag you simply take a ratio of the NADSAQ:SPX at the end of each week.Then starting in week 10, you calculate the 10-week moving average. If the current ratio is above the average, the NASDAQ is leading. If it is below the average, the NASDAQ is lagging the SPX.
I tried program it in AFL, and am struggling. I believe my issue is likely that I am not using the "timeframe" calcs properly. (I have not used them to this point.) Below is a screenshot of recent readings in an excel spreadsheet I use. Please note that the indicator should not "flip" during the week. If it is labeled "Lead" on Friday at the close, then it should stay that way until at least next Friday at the close (assuming you are looking at a daily or intraday exploration or chart).
Here is my latest attempt at the code:
SPX = Foreign("$SPX","Close");
COMP = Foreign("$COMP","Close");
TimeFrameSet(inWeekly);
SPXW = SPX;
COMPW = COMP;
TimeFrameRestore();
SPXweekly = TimeFrameExpand(SPXW,inWeekly);
COMPweekly = TimeFrameExpand(COMPW,inWeekly);
Ratio = COMPweekly / SPXweekly;
AvgRatio = MA(Ratio,10);
COMPleading = AvgRatio > Ratio;
//Explore
Filter = 1;
AddColumn(close,"close",1.2);
AddColumn(SPX,"SPX",1.2);
AddColumn(SPXW,"SPXW",1.2);
AddColumn(SPXweekly,"SPX Weekly",1.2);
AddColumn(COMPleading,"AppelRS",1.0);
Here is what my explore results are:
In this case SPX is the security I ran the exploration on, but I use $SPX as a foreign because I want to be able to refer to this indicator even if I am looking at MSFT or GOOG or $RUT or anything.
Thanks for any suggestions...