Category Archives: EDS

Exponential Deviation Bands

The importable AIQ EDS file based on Vitali Apirine’s article in July 2019 Stocks & Commodities issue, “Exponential Deviation Bands,”

and a recreated Excel spreadsheet similar to the one shown in the article can be obtained on request via email to info@TradersEdgeSystems.com. The code is also shown here:

Exponential deviation (ED) bands are plotted above and below a moving average (MA) from which the bands are calculated. An exponential deviation from the moving average is used to set the bands. ED bands can be used with either a simple moving average (SMA) or an exponential moving average (EMA). The moving average dictates direction, and the exponential deviation sets band width. Breakouts from the band and changes in the band’s direction can help identify price trends and price reversals. These bands can be used on a variety of securities with its standard settings.

!EXPONENTIAL DEVIATION BANDS
!Author: Vitali Apirine, TASC July 2019
!Coded by: Richard Denning, 5/15/2019
!www.TradersEdgeSystems.com

C is [close].
Periods is 20. 

MA20 is simpleavg(C,Periods).   !expavg(C,Periods).  !or simpleavg(C,Periods). 
MDev20 is (Abs(MA20-C)+Abs(MA20-valresult(C,1))+Abs(MA20-valresult(C,2))+Abs(MA20-valresult(C,3))
      +Abs(MA20-valresult(C,4))+Abs(MA20-valresult(C,5))+Abs(MA20-valresult(C,6))+Abs(MA20-valresult(C,7))
     +Abs(MA20-valresult(C,8))+Abs(MA20- valresult(C,9))+Abs(MA20- valresult(C,10))+Abs(MA20- valresult(C,11))
     +Abs(MA20- valresult(C,12))+Abs(MA20- valresult(C,13))+Abs(MA20- valresult(C,14))+Abs(MA20- valresult(C,15))
      +Abs(MA20- valresult(C,16)) +Abs(MA20- valresult(C,17))+Abs(MA20- valresult(C,18))+Abs(MA20- valresult(C,19)))/20.

Dev is Abs(MA20-C).  
Rate is 2/( Periods +1).  

DaysInto is ReportDate() - RuleDate().
Stop if DaysInto >= 200.
stopEXD is iff(Stop,Mdev20, EXD).
EXD is Dev*Rate + valresult(stopEXD,1)*(1-Rate).

UpperExp is MA20+2*EXD.  
MidExp is MA20.  
LowerExp is MA20-2*EXD. 

ShowValues if 1.

Figure 9 shows the exponential deviation bands centered on a 20-bar simple moving average on a chart of the New York Composite Index (NYA).

Sample Chart

FIGURE 9: AIQ. Here are exponential deviation bands centered on a 20-bar simple moving average on a chart of the New York Composite Index (NYA).

—Richard Denning
info@TradersEdgeSystems.com
for AIQ Systems

Backtesting A Mean-Reversion Strategy In Python

The importable AIQ EDS file based on Anthony Garner’s article in May 2019 Stocks & Commodities “Backtesting A Mean-Reversion Strategy In Python,” can be obtained on request via email to info@TradersEdgeSystems.com. The code is also shown below.

I backtested the author’s mean-reversion system (MeanRev.eds) using both the EDS module, which tests every trade on a one-share basis, and also via the Portfolio Manager, which performs a trading simulation.

The short side strategy showed a loss overall in the EDS test so I tested only the long side in the Portfolio Manager. I selected trades using the z-score, taking the lowest values.

For capitalization, I used max of three trades per day with a max total of 10 open trades at one time, 10% allocated to each position. I did not deduct slippage but did deduct commissions. I used a recent list of the NASDAQ 100 stocks to run the test. The equity curve and account statistics report are shown in Figure 7.

Sample Chart

FIGURE 7: AIQ. This shows the equity curve (blue line) from long-only trading the NASDAQ 100 list of stocks from 1999 to March 15, 2019. The red line is the NDX index.

!Backtesting a Mean-Reversion Strategy In Python !Author: Anthony Garner, TASC May 2019 !Coded by: Richard Denning 3/14/19 !www.TradersEdgeSystems.com 

!ABBREVIATIONS:
C is [close].

!INPUTS:
meanLen is 10.
longZmult is -1.
shortZmult is 1.
meanMult is 10.

!FORMULAS:

SMA is simpleavg(C,meanLen).
LMA is simpleavg(C,meanLen*meanMult).
STD is sqrt(variance(C,meanLen)).
zScore is (C - SMA) / STD.

!TRADING SIGNALS & EXITS:

buyLong if zScore < longZmult and SMA > LMA.
sellShort if zScore > shortZmult and SMA < LMA.
exitLong if valresult(zScore,1) < -0.5 and zScore > 0.5.
exitShort if valresult(zScore,1) > 0.5 and zScore < -0.5.

showValues if 1.

—Richard Denning
info@TradersEdgeSystems.com
for AIQ Systems

What the Hal?

Some industries are cyclical in nature.  And there is not a darned thing you – or they – can do about it.  Within those industries there are individual companies that are “leaders”, i.e., well run companies that tend to out earn other companies in that given industry and whose stock tends to outperform other companies in that industry.

Unfortunately for them, even they cannot avoid the cyclical nature of the business they are in.  Take Halliburton (ticker HAL) for example.  Halliburton is one of the world’s largest providers of products and services to the energy industry.  And they do a good job of it. Which is nice.  It does not however, release them from the binds of being a leader in a cyclical industry.

A Turning Point at Hand?

1

A quick glance at Figure 1 clearly illustrates the boom/bust nature of the performance of HAL stock.Figure 1 – Halliburton (HAL) (Courtesy AIQ TradingExpert)

Which raises an interesting question: is there a way to time any of these massive swings?  Well here is where things get a little murky.  If you are talking about “picking timing tops and bottoms with uncanny accuracy”, well, while there are plenty of ads out there claiming to be able to do just that, in reality that is not really “a thing”.  Still, there may be a way to highlight a point in time where:

*Things are really over done to the downside, and

*For a person who is not going to get crazy and “bet the ranch”, and who understands how a stop-loss order works and is willing to use one…

..there is at least one interesting possibility.

It’s involves a little-known indicator that is based on a more well-known another indicator that was developed by legendary trader Larry Williams roughly 15 or more years ago.  William’s indicator is referred to as “VixFix” and attempts to replicate a VIX-like indicator for any market.  The formula is pretty simple, as follows  (the code is from AIQ Expert Design Studio):

*hivalclose is hival([close],22).

*vixfix is (((hivalclose-[low])/hivalclose)*100)+50.

In English, it is the highest close in the last 22-periods minus the current period low, which is then divided by the highest close in the last 22-periods. The result then gets multiplied by 100 and 50 is added.

Figure 2 displays a monthly chart of HAL with William’s VixFix in the lower clip.  In a nutshell, when price declines VixFix rises and vice versa.

2

Figure 2 – HAL Monthly with William’s VixFix (Courtesy AIQ TradingExpert)

Now let’s go one more step as follows by creating an exponentially smoothed version as follows (the code is from AIQ Expert Design Studio):

*hivalclose is hival([close],22).

*vixfix is (((hivalclose-[low])/hivalclose)*100)+50. <<<Vixfix from above

*vixfixaverage is Expavg(vixfix,3).  <<<3-period exponential MA of Vixfix

*Vixfixaverageave is Expavg(vixfixaverage,7). <<<7-period exp. MA

I refer to this as Vixfixaverageave (Note to myself: get a better name) because it essentially takes an average of an average.  In English (OK, sort of), first Vixfix is calculated, then a 3-period exponential average of Vixfix is calculated (vixfixaverage) and then a 7-period exponential average of vixfixaverage is calculated to arrive at Vixfixaverageave (got that?)

3

Anyway, this indicator appears on the monthly chart for HAL that appears in Figure 3.Figure 3 – HAL with Vixaverageave (Courtesy AIQ TradingExpert)

So here is the idea:

*When Vixfixaverageave for HAL exceeds 96 it is time to start looking for a buying opportunity.

OK, that last sentence is not nearly as satisfying as one that reads “the instant the indicator reaches 96 it is an automatic buy signal and you can’t lose”.  But it is more accurate.  Previous instances of a 96+ reading for Vixfixaverageave for HAL appear in Figure 4.

4

Figure 4 – HAL with previous “buy zone” readings from Vixfixaverageave (Courtesy  AIQ TradingExpert)

Note that in previous instances, the actual bottom in price action occurred somewhere between the time the indicator first broke above 96 and the time the indicator topped out.  So, to reiterate, Vixfixaverageave is NOT a “precision timing tool”, per se.  But it may be useful in highlighting extremes.

This is potentially relevant because with one week left in May, the monthly Vixfixaverageave value is presently above 96.  This is NOT a “call to action”.  If price rallies in the next week Vixfixaverageave may still drop back below 96 by month-end.  Likewise, even if it is above 96 at the end of May – as discussed above and as highlighted in Figure 4, when the actual bottom might occur is impossible to know.

5

Let me be clear: this article is NOT purporting to say that now is the time to buy HAL.  Figure 5 displays the largest gain, the largest drawdown and the 12-month gain or loss following months when Vixfixaverageave for HAL first topped 96.  As you can see there is alot of variation and volatility.  

Figure 5 – Previous 1st reading above 96 for HAL Vixfixaverageave

So HAL may be months and/or many % points away from an actual bottom.  But the main point is that the current action of Vixfixaverageave suggests that now is the time to start paying attention.

Jay Kaeppel

Disclaimer:  The data presented herein were obtained from various third-party sources.  While I believe the data to be reliable, no representation is made as to, and no responsibility, warranty or liability is accepted for the accuracy or completeness of such information.  The information, opinions and ideas expressed herein are for informational and educational purposes only and do not constitute and should not be construed as investment advice, an advertisement or offering of investment advisory services, or an offer to sell or a solicitation to buy any security.

An Obscure but Potentially Useful Oversold Indicator

Trend-following is essentially a “tried and true’ approach to investing.  But overbought/oversold (i.e., attempting to buy low/sell high) – that’s where the “excitement” is.  Of course, when it comes to trading and investing, “excitement” can be highly overrated.  Nevertheless, in this piece I want to talk about a relatively obscure indicator that may be useful in identifying vastly oversold situations.

EDITORS NOTE: The AIQ EDS file for Jay Kaeppel’s indicator is available to download at

The VixRSI14 Indicator

Part of the reason this indicator is obscure is because I think I “invented” it – but only by mashing together an indicator from Larry Williams and an indicator from Welles Wilder.  The first part is the standard Welles Wilder 14-day Relative Strength Index, more commonly referred to as “RSI”.

The 2nd part of VixRSI14 is an indicator created by famed trader Larry Williams which he dubbed “VixFix”.  This indicator is an effort to create a “Vix Index-like” indicator for any security.

AIQ TradingExpert code for these indicators appears at the end of the article.

A Few Notes

*For the record, VixRSI14 is calculated by taking a 3-day exponential average of VixFix and dividing that by a 3-day exponential average of RSI14 (are we having fun yet?).  Please see code at the end of the article.

*I prefer to use VixRSI14 using weekly data rather than daily data

*(Unfortunately) There are no “magic numbers” that indicate that a completely risk-free, you can’t lose, just buy now and watch the money roll in” buying opportunity is at hand (Disclaimer: If there was, I would probably just keep it to myself and not bother writing the article – sorry, it’s just my nature).  That being said, a decent “rule of thumb” is to look for a reading above 3.5 followed by a downside reversal.

(Click any chart below to enlarge)

With those thoughts in mind, Figure 1 displays a weekly chart of Wynn Resorts (WYNN) with the two indicators plotted separately below the bar chart.1

Figure 1 – WYNN with William’s VixFix and Wilder’s RSI 14-day (Courtesy AIQ TradingExpert)

Note that as price declines, VixFix tends to rise and RSI14 tends to fall.  VIXRSI14 essentially identifies “extremes” in the difference between these two.  Figure 2 displays WYNN with VixRSI14 plotted below the bar chart.

2

Figure 2 – WYNN with VixRSI14 (Courtesy AIQ TradingExpert)

More “examples” appear in Figures 3 through 8 below.

3

Figure 3 – AMD (Courtesy AIQ TradingExpert)

4

Figure 4 – BAC (Courtesy AIQ TradingExpert)

5

Figure 5 – DISH (Courtesy AIQ TradingExpert)

6

Figure 6 – GRMN (Courtesy AIQ TradingExpert)

7

Figure 7 – NTAP (Courtesy AIQ TradingExpert)

8

Figure 8 – YHOO (Courtesy AIQ TradingExpert)

Summary

As always, I merely present “ideas” here at JOTM.  So, do not assume from the charts above that you have found the “keys to the kingdom”.  But if used in conjunction with other confirming indicators – and remembering to employ some sort of risk control for those instances when a stock price decline fails to arrest itself even after VixRSI4 peaks above 3.5 – VixRSI14 may hold some value.

Indicator Code

EDITORS NOTE: The AIQ EDS file for Jay Kaeppel’s indicator is available to download at

Below is the code for VixFix, RSI14 and VixRSI14 from AIQ Expert Design Studio.

!#######################################

!VixFix indicator code

hivalclose is hival([close],22).

vixfix is (((hivalclose-[low])/hivalclose)*100)+50.

!#######################################

!#######################################

!RSI14 code

Define days14 27.

U14 is [close]-val([close],1).

D14 is val([close],1)-[close].

AvgU14 is ExpAvg(iff(U14&gt;0,U14,0),days14).

AvgD14 is ExpAvg(iff(D14&gt;=0,D14,0),days14).

RSI14 is 100-(100/(1+(AvgU14/AvgD14))).

!#######################################

!#######################################

!VixRSI14 code

VixRSI14 is expavg(vixfix,3)/expavg(RSI14,3).

!#######################################

Jay Kaeppel

Disclaimer:  The data presented herein were obtained from various third-party sources.  While I believe the data to be reliable, no representation is made as to, and no responsibility, warranty or liability is accepted for the accuracy or completeness of such information.  The information, opinions and ideas expressed herein are for informational and educational purposes only and do not constitute and should not be construed as investment advice, an advertisement or offering of investment advisory services, or an offer to sell or a solicitation to buy any security.

Watch This Indicator

So, the big question on every investor’s mind is “What Comes Next?”  Since this is not an advisory service (and given the fact that I am not too good at predicting the future anyway) I have avoided commenting on “the state of the markets” lately.  That being said, I do have a few “thoughts”:

*The major averages (as of this exact moment) are still mostly above their longer-term moving averages (200-day, 10-month, 40-week, and so on and so forth).  So, on a trend-following basis the trend is still “up”.

0Figure 1 – The Major Index (Courtesy AIQ TradingExpert)

*We are in the most favorable 15 months of the 48-month election cycle (though off to a pretty awful start obviously) which beings Oct.1 of the mid-term year and ends Dec. 31st of the pre-election year.

*Investors should be prepared for some volatility as bottoms following sharp drops usually take at least a little while to form and typically are choppy affairs.  One day the market is up big and everyone breathes a sigh of relief and then the next day the market tanks.  And so on and so forth.

An Indicator to Watch

At the outset let me state that there are no “magical” indicators.  Still, there are some that typically are pretty useful.  One that I follow I refer to as Nasdaq HiLoMA.  It works as follows:

A = Nasdaq daily new highs

B = Nasdaq daily new lows

C = (A / (A+B)) * 100

D = 10-day moving average of C

C can range from 0% to 100%.  D is simply a 10-day average of C.

Nasdaq HiLoMA = D

Interpretation: When Nasdaq HiLoMA drops below 20 the market is “oversold”.

Note that the sentence above says “the market is oversold” and NOT “BUY NOW AGGRESSIVELY WITH EVERY PENNY YOU HAVE.”  This is an important distinction because – like most indicators – while this one may often give useful signals, it will occasionally give a completely false signal (i.e., the market will continue to decline significantly).

A couple of “finer points”:

*Look for the indicator to bottom out before considering it to be “bullish”.

*A rise back above 20 is often a sign that the decline is over (but, importantly, not always).  Sometimes there may be another retest of recent lows and sometimes a bear market just re-exerts itself)

*If the 200-day moving average for the Dow or S&amp;P 500 is currently trending lower be careful about using these signals.  Signals are typically more useful if the 200-day moving average for these indexes is rising or at least drifting sideways rather than clearly trending lower (ala 2008).

Figures 2 through 8 displays the S&amp;P 500 Index with the Nasdaq HiLoMA indicator.  Click to enlarge any chart.

1Figure 2 – SPX with Jay’s Nasdaq HiLoMA ending 2006 (Courtesy AIQ TradingExpert)

2Figure 3 – SPX with Jay’s Nasdaq HiLoMA ending 2008 (Courtesy AIQ TradingExpert)

3Figure 4 – SPX with Jay’s Nasdaq HiLoMA ending 2010 (Courtesy AIQ TradingExpert)

4Figure 5 – SPX with Jay’s Nasdaq HiLoMA ending 2012 (Courtesy AIQ TradingExpert)

5Figure 6 – SPX with Jay’s Nasdaq HiLoMA ending 2014 (Courtesy AIQ TradingExpert)

6Figure 7 – SPX with Jay’s Nasdaq HiLoMA ending 2016 (Courtesy AIQ TradingExpert)

7Figure 8 – SPX with Jay’s Nasdaq HiLoMA ending 2018 (Courtesy AIQ TradingExpert)

Summary

The stock market is in a favorable seasonal period and is oversold.  As long as the former remains true, react accordingly (with proper risk controls in place of course).

Jay Kaeppel

Disclaimer:  The data presented herein were obtained from various third-party sources.  While I believe the data to be reliable, no representation is made as to, and no responsibility, warranty or liability is accepted for the accuracy or completeness of such information.  The information, opinions and ideas expressed herein are for informational and educational purposes only and do not constitute and should not be construed as investment advice, an advertisement or offering of investment advisory services, or an offer to sell or a solicitation to buy any security.