The AIQ code based on Ron McEwan’s article in February issue of Stocks & Commodities, “The Volatility (Regime) Switch Indicator,” is provided at the website www.TradersEdgeSystems.com/traderstips.htm.
To test the author’s volatility switch indicator, I used the NASDAQ 100 list of stocks and AIQ’s Portfolio Manager. A long-only trading simulation was run with the following capitalization, cost, and exit settings:
- Maximum of 10 open positions
- Size each position at 10% of mark-to-market total capital
- Take no more than three new positions per day
- Compute the mark-to-market capital each day
- Three cents per share was deducted for each round-turn trade
- Select trades based on the lowest three-bar RSI reading
- Exit trades only with a system exit; no stop-loss or profit target stop used.
I coded four similar test systems. All systems enter & exit on the next bar at open after the respective entry or exit rule becomes true at the close of the bar:
System 1: A basic trend-following system that buys when the close of a stock is above its moving average and the moving average is higher than it was 10 bars ago. Exit when the close is below the moving average.
System 2: The same as System 1 with the volatility switch filter added to the entry and exit rules for the stock.
System 3: The same as System 2 with System 2 rules also added to the market using the NASDAQ 100 index (NDX) to represent the market conditions.
System 4: The same as System 1 but with the volatility switch filter and the trend-following rules added to the market index (NDX).
I used the author’s parameters of 21 days for the volatility length and 50 for the volatility switch level. Note that my coding of the indicator is multiplied by 100. To determine the trend, I used a 50-bar moving average. For the period 12/30/1994 to 12/12/2012, the systems returned the results shown in the table in Figure 7.
The code and EDS file can be downloaded from www.TradersEdgeSystems.com/traderstips.htm. The code is also shown below.
!THE VOLATILITY (REGIME) SWITCH INDICATOR !Author: Ron McEwan !Coded by: Richard Denning 12/7/12 !www.TradersEdgeSystems.com !INPUTS: volaLen is 21. maLen is 50. volaLvl is 50. rsiExitLvl is 90. !ABREVIATIONS: C is [close]. C1 is valresult(C,1). !INDICATOR FUNCTIONS: MA is simpleavg(C,maLen). RC1 is (C-C1)/((C+C1)/2). SD is sqrt(variance(RC1,volaLen)). Count is countof(SD <= ∧SD,volaLen). VolaSwitch is Count / volaLen * 100. !TRADING SYSTEM RULES: !SYSTEM 1: TREND FOLLOWING WITHOUT VOLASWITCH FILTER: Buy if C > MA and MA > valresult(MA,10). ExitBuy if C < MA. !SYSTEM 2: TREND FOLLOWING WITH VOLASWITCH FILTER: BuyVS if VolaSwitch < volaLvl and C > MA and MA > valresult(MA,10). ExitBuyVS if (VolaSwitch > volaLvl and C < MA) or (VolaSwitch > volaLvl and rsi3 > rsiExitLvl). !SYSTEM 3: TREND FOLLOWING WITH VOLASWITCH & MARKET TIMING: BuyVSM if BuyVS and TickerRule("NDX",BuyVS). ExitBuyVSM if ExitBuyVS or TickerRule("NDX",ExitBuyVS). !SYSTEM 4: TREND FOLLOWING WITH VOLASWITCH MARKET TIMING APPLIED ONLY TO NDX: BuyMvs if Buy and TickerRule("NDX",BuyVS). ExitBuyMvs if ExitBuy or TickerRule("NDX",ExitBuyVS). !RSI WILDER (FOR SYSTEM 2 EXIT): U is [close]-val([close],1). D is val([close],1)-[close]. W1 is 3. rsiLen1 is 2 * W1 - 1. AvgU is ExpAvg(iff(U>0,U,0),rsiLen1). AvgD is ExpAvg(iff(D>=0,D,0),rsiLen1). rsi3 is 100-(100/(1+(AvgU/AvgD))).