All posts by admin

System Development Using Artificial Intelligence

The AIQ code based on Domenico D’Errico and Giovanni Trombetta’s article in August 2017 Stock & Commodities issue, “System Development Using Artificial Intelligence,” is shown here. You can also download the EDS file from here

Are humans or computers better at trading? This question has been around on many fronts since the era of punch cards, and as technology advances, you question whether machines have limits. It’s the same with trading, and here’s an algorithm that may shed some light on which performs better…

!ARTIFICAL INTELLIGENCE FOR SYSTEM DEVELOPMENT
!Authors: Domenico D'Errico & Giovanni Trombetta, TASC August 2017
!Coded by: Richard Denning, 6/08/2017
!www.TradersEdgeSystems.com

!INPUTS:
O is [open].
C is [close].
H is [high].
L is [low].
exitBars is 8.
exitBarsP is 6.
enterGap is -0.08.

!CODE:
AvgP is (O+C+H+L)/4.
MedP is (H+L)/2.
MedB is (O+C)/2.

AvgP1 is valresult(AvgP,1).
AvgP2 is valresult(AvgP,2).
AvgP3 is valresult(AvgP,3).

MedP1 is valresult(MedP,1).
MedP2 is valresult(MedP,2).
MedP3 is valresult(MedP,3).
MedP4 is valresult(MedP,4).

MedB1 is valresult(MedB,1).
MedB2 is valresult(MedB,2).
MedB3 is valresult(MedB,3).
MedB4 is valresult(MedB,4).

!ENTRY & EXIT RULESl
Gandalf if 
  (AvgP1exitBars-1)
 or ({position days}>=exitBars-1)
 or ({position days}>=exitBarsP-1 and (C-{position entry price}>0)).

EntryPr is min(val([low],1) + enterGap,[open]).

Buy if Gandalf and [low] <= EntryPr.

See Figure 10 for how to set up the pricing in a backtest.
Sample Chart

FIGURE 10: AIQ. This shows the EDS backtest settings for entry pricing.
—Richard Denning
info@TradersEdgeSystems.com
for AIQ Systems

A Simple Indicator for Traders

First the Bad News: There are no “magic bullets” when it comes to trading.  There are people in this industry who have literally tested somewhere in the range of six bazillion “indicators” – give or take (“Hi. My name is Jay”).  Every trend following indicator looks like a gold mine when it latches onto a huge trend and rides it (but not so much when it starts getting whipsawed).  And every overbought/oversold indicator looks like a gift from heaven from time to time when it somehow manages to peak (or valley) and then reverses right at a high (or low).  And then the next time the thing gets oversold the security in question just keeps plunging and the previously “amazingly accurate” indicator just gets more and more oversold.

Bottom line: what I am about to discuss is likely no better or worse than a lot of other indicators.  And it is no holy grail.  Still, I kinda like it – or whatever that is worth.

EDITORS NOTE an AIQ EDS file for this indicator with the 3 step rules outlined can be downloaded from here you will need to copy or save this file into your wintes32/eds strategies folder. Alternatively the code is available at the end of this article for copying and pasting into a new EDS file.

UpDays20

I call this indicator UpDays20 and I stole, er, learned it originally from Tom McClellan of McLellan Financial Publications.  My calculation may be slightly different because I wanted an indicator that can go both positive and negative.  For a given security look at its trading gains and losses over the latest 20 trading days.

UPDays20 = (Total # of Up days over the last 20 trading days) – 10

So if 10 of the last 20 trading days showed a gain then UpDays20 would read exactly 0.

If only 6 of the last 20 trading days showed a gain then UpDays20 would read -4

You get the idea (and proving once again that it “doesn’t have to be rocket science”).  As a “trading method” it is always advised that this indicator – like most all other indicators – NOT be used as a standalone approach to trading.  That being said, the way I follow this indicator is as follows.

Step 1) UpDays20 drops to at least -2

Step 2) UpDays20 rises 2 points from a low

Step 3) The security in question then rises above its high for the previous 2 trading days

It is preferable to follow this setup hen the security in question is above its 200-day moving average, but that is up to the trader to decide (the danger to using this with a security below its 200-day moving average is that it might just be in the middle of a freefall.  The upside is that counter trend rallies can be fast and furious – even if sometimes short-lived).

Again, there is nothing magic about these particular steps.  They are simply designed to do the following:

1) Identify an oversold condition

2) Wait for some of the selling pressure to abate

3) Wait for the security to show some sign of reversing to the upside

Like just about every other indicator/method, sometimes it is uncannily accurate and sometimes it is embarrassingly wrong (hence the reason experienced traders understand that capital allocation and risk management are far more important than the actually method you use to enter trades).

In this previous article (in Figures 3 and 4) I wrote about using this indicator with ticker TLT.  Figure 1 and 2 display the “buy” signals generated using the rules above for tickers IYT and GLD.

1Figure 1 – UpDays20 “Buy” Alerts for ticker IYT (Courtesy AIQ TradingExpert)

2Figure 2 – UpDays20 “Buy” Alerts for ticker GLD (Courtesy AIQ TradingExpert)

Are these signals good or bad?  That is in the eye of the beholder and not for me to say.  One big unanswered question is “when do you exit”?  That is beyond the scope of this “idea” article – however, “sell some at the first good profit and then use a trailing stop” looks like a decent approach to consider) but would have a profound effect on any actual trading results.

Some of the signals displayed in Figures 1 and 2 are obviously great, others are maybe not so hot.  Interestingly, some of the signals in Figure 1 and 2 that don’t look to timely at first blush actually offered a profitable opportunity to a trader who was inclined to take a quick profit. Again, how you allocate capital and when you exit with a profit and when you exit with a loss would likely have as much impact on results as the raw “buy” signals themselves.

Summary

No one should go out and start trying to trade tomorrow based on UpDays20.  No claim is being made that the steps detailed herein will result in profits nor even that this is a good way to trade.

But, hey, it’s one way.

Jay Kaeppel Chief Market Analyst at JayOnTheMarkets.com and AIQ TradingExpert Pro client.

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.

EDITORS NOTE an AIQ EDS file for this indicator with the 3 step rules outlined can be downloaded from here you will need to copy or save this file into your wintes32/eds strategies folder. Alternatively the code is available at the end of this article for copying and pasting into a new EDS file.

! UpDays20 – I call this indicator UpDays20. For a given security look at its trading gains and losses over the latest 20 trading days.

! UPDays20 = (Total # of Up days over the last 20 trading days) – 10

! So if 10 of the last 20 trading days showed a gain then UpDays20 would read exactly 0.

! If only 6 of the last 20 trading days showed a gain then UpDays20 would read -4

Upday if [close]&gt;val([close],1).

totalupdayslast20days is CountOf(upday,20).

updayindicator is totalupdayslast20days – 10.

! How to follow this indicator

! Step 1) UpDays20 drops to at least -2

! Step 2) UpDays20 rises 2 points from a low

! Step 3) The security in question then rises above its high for the previous 2 trading days

UpDays20rises2points if updayindicator&gt;valresult(updayindicator,1) and valresult(updayindicator,1)&gt;valresult(updayindicator,2).

updays20atminus2orlower if valresult(updayindicator,2)&lt;=-2.

closesabovehighof2priordays if [close]&gt;val([high],1) and [close]&gt;val([high],2).

Upsignal if UpDays20rises2points and updays20atminus2orlower and closesabovehighof2priordays.

The Gathering Storm

First the Good News:
*The market averages are still in an up trend
*The Fed has yet to “remove the punch bowl”
1
Figure 1 – Major Averages still in Up Trends (Courtesy AIQ TradingExpert)
Fed Balance Sheet
Figure 2 – Fed Quantitative Easing propels the stock market (Courtesy RealInvestmentAdvice.com)
Now the bad news
Market Bellwethers Flashing Warnings
In this article I wrote about four tickers I follow for signs of early warnings of trouble.  At the moment, all four are flashing warnings.
bellwether 4
Figure 3 – Bellwethers flashing potential warnings (Courtesy AIQ TradingExpert)
Stocks are Extremely Overvalued
Something important to note: valuation indicators are NOT good timing indicators.  The overall market can be over or undervalued for years. However, overvalued valuation readings are extremely reliable at telling us what will come next once the top is in (whenever that may be).  Figure 4 displays the Schiller CAPE model which measures adjusted P/E ratio.schiller cape w datesFigure 4 – Schiller Adjusted PE (Courtesy: Schiller Data Library)
1901: Dow -37% in 32 months
1929: Dow -89% in 3 years
1932: Dow -49% in 13 months
1965: Dow sideways to 40% lower for 17 years
2000: Nasdaq 100 -87%
2007: Dow -55% in 17 months
2017: ??
When will the exact top form?  Don’t know
What will likely follow?  Don’t Ask
The Decennial Pattern
As I wrote about here and as you can see in Figures 5 and 6, the Year 7 into Year 8 period has historically witnesses significant market weakness.  That does not mean that that is what will happen this time around.  But it is reason for caution.
decennial
Figure 5 – Stock Market Decennial Pattern (Courtesy: OptionStrategist.com)
Year 7 2
Figure 6 – Trouble in Late Year “7”  (Courtesy: OptionStrategist.com)
Figure 7 from Tom McLellan illustrates this phenomenon even more clearly.
Year 7 3
Figure 7 – Trouble in Late Year “7”  (Courtesy: www.mclellanoscillator.com)
September
What a crummy time for September to roll around.  Figure 8 displays the fact that the Dow has lost -80% during the month of September since 1897.sep
Figure 8 – Dow has lost -80% during September since 1897
Figure 9 displays the fact that since 1955 most of the “September Nasty” has occurred in that last 10 trading days of the month (after the close on 9/15 this year)
sep x
Figure 9 – Dow in September; 1st 3 days (blue); Last 10 days (green); in between (red); 1955-2016
Investor Complacency
Despite the fact that:
*We have experienced one of the longest bull markets in history
*Stock prices are extremely overvalued on an objective historical basis
*A number of warning signs are flashing
The investment world seems relatively untroubled (in the interest of full disclosure I have done only limited selling so far myself – more on this in a moment).
Figure 10 displays the AAII investor cash allocation reading from earlier this year.   Low cash levels tend to signal complacency (and impending market trouble) while high cash levels tend to occur near market bottoms.
AAII Cash
Figure 10 – AAII Investor Cash % is low (Courtesy: American Association of Individual Investors)
Figure 11 displays the amount of assets in the Rydex suite of “bearish” funds from earlier this year.  As you can see, investors were not too concerned about the prospects for a bear market – a potential contrarian signal.
rydex bear assets
Figure 11 – Rydex Bearish Funds Assets low (Courtesy: The Lyons Share)
Figure 12 shows the level of margin debt versus stock prices.  Historically when margin debt peaks and begins to decline the stock market suffers significantly.  There is no way to predict  when margin debt will top out and roll over but it did recently reach a new all-time high.  Could it go higher? Absolutely.  But if it rolls over – then look out below.
margin debt x
Figure 12 – If Margin Debt peaks trouble may follow (Courtesy: dshort.com)
Figure 13 displays the stock market versus the number of “Hindenburg Omens” (a measure of “churning” in the stock market) that have occurred in the most recent 6-month period.  Another warning sign is flashing.
Hindenburg Omen 6
Figure 13 – Hindenburg Omen flashing a warning (Courtesy: SentimentTrader.com)
Summary
Does any of the above guarantee that a significant stock market decline is imminent?  The correct answer is “No.”  The major market indexes all remain above their long-term moving averages. This can be considered the very definition of a bull market.
I personally have seen lots of warning signs flash along the way over the years.  And I have found that it is important to pay attention to these and to “prepare for the worst” – i.e., to plan an exit/hedging strategy “just in case.”  But trying to pick the exact top is an excellent way to end up looking stupid.  Trust me on this one.
So here is my summary:
*I do not possess the ability to “call the top” nor to “predict what will happen next” in the stock market
*I do possess a reasonably good ability to identify the trend “right now”
*I also possess the ability to recognize gathering storms clouds (and, yes, they are forming) and the ability to formulate an “emergency plan” as well as the wherewithal to follow the plan “should this be an actual (market) emergency.”
The current level of market valuation – and the history of the stock market following previous similar such readings – suggests that the next bear market will surprise many investors by its severity.
The clouds are gathering.  Please plan accordingly.
Jay Kaeppel Chief Market Analyst at JayOnTheMarkets.com and AIQ TradingExpert Pro client. 
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.

One More Cry of ‘Wolf’

If I were the type to make bold proclamations I would probably consider “taking my shot” right here and shout “This is the Top” and/or “The Market May Crash.”  Unfortunately, on those occasions (well) in the past when I would make bold public predictions of what was about to happen in the financial markets I would almost invariably end up looking pretty stupid. So even if I did make a “bold proclamation” it wouldn’t necessarily mean that anyone should pay any attention.
Besides all that the last thing I want is for “the party to end”.  Even if you do think the market is about to tank it’s a pretty crummy thing to have to root for.  Even if you did manage to “call the top”, the ripple effect of the ramifications associated with a serious stock market decline can have pretty negative effect on just about everyone’s life.
So let’s put it this way: I am concerned – and prepared to act defensively if necessary – but still have money in the market and am still hoping for the best.
Reasons for Caution (Indexes)
Figure 1 displays four major indexes. The Dow keeps hitting new highs day after day while the others – at the moment – are failing to confirm.  That doesn’t mean that they won’t in the days ahead.  But the longer this trend persists the more negative the potential implications.
1
Figure 1 – Dow at new highs, small-caps, Nasdaq and S&P 500 not quite (Courtesy AIQ TradingExpert)
Reasons for Caution (Bellwethers)
Figure 2 displays 4 “bellwethers” that I follow which may give some early warning signs.
2
Figure 2 – Market Bellwethers possibly flashing some warning signs (Courtesy AIQ TradingExpert)
*SMH soared to a high in early June and has been floundering a bit since.
*Dow Transports tried to break out to the upside in July but failed miserably.
*XIV is comfortably in new high territory.
*BID tried to break out in July and then collapsed.  It is presently about 12% off of its high.
In a nutshell – 3 of the 4 are presently flashing warning signs.
Reasons for Caution (Market Churn)
In this article I wrote about an indicator that I follow that can be useful in identify market “churn” – which can often be a precursor to market declines.  Spikes above 100 by the blue line often signify impending market trouble
It should be noted that the indicators signals are often early and occasionally flat out wrong.  Still, a churning market with the Dow making new highs has often served as a “classic” warning sign.
3
Figure 3 – JK HiLo Index (blue) versus Nasdaq Compsite / 20 (red); 12/31/2006-present
Summary
Again, and for the record, I do not possess the ability to “predict” the markets.  But I have seen a few “warning signs” flash bright red at times in the past.  As a general rule, it is best to at least pay attention – and maybe make a few “contingency plans” – you know,  just in case.
Here’s hoping my gut is wrong – again.
Jay Kaeppel Chief Market Analyst at JayOnTheMarkets.com and AIQ TradingExpert Pro (http://www.aiqsystems.com) client. 
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.

Detecting Swings

The AIQ code based on Domenico D’Errico’s article in the May 2017 issue of Stocks & Commodities issue, “Detecting Swings,” is provided here.

I tested the author’s four systems using the NASDAQ 100 list of stocks on weekly bars, as did the author, from 3/16/2005 through 3/14/2017. Figure 7 shows the comparative metrics of the four systems using the four-week exit. The results were quite different than the author’s, probably due to a different test portfolio and also a 10-year test period rather than the author’s 20-year period. In addition, my test results show longs only, whereas the author’s results are the average of both the longs and shorts.

Sample Chart

FIGURE 7: AIQ. As coded in EDS, this shows the metrics for the author’s four systems run on NASDAQ 100 stocks (weekly bar data) over the period 3/16/2005 to 3/14/2007.

The Bollinger Band (Buy2) system showed the worst results, whereas the author’s results showed the Bollinger Band system as the best. The pivot system (Buy1) showed the best results, whereas the author’s results showed the pivot system as the worst. I am not showing here the comparative test results for the Sell1 thru Sell4 rules, as all showed an average loss over this test period.

!DECTECTING SWINGS
!Author: Domenico D'Errico, TASC May 2017
!Coded by: Richard Denning, 3/15/17
!www.TradersEdgeSystems.com

!Set to WEEKLY in properties

Low is  [low].
Low1  is valresult(Low,1).
Low2  is valresult(Low,2). 
High is [high].
High1  is valresult(High,1).
High2  is valresult(High,2). 
PivotLow if Low1 &lt; Low2  and Low1 &lt; Low.
PivotHigh if High1 &gt; High2  and High1 &gt; High.

Buy1 if  PivotLow.  
Sell1 if  PivotHigh.    

!Set parameter for bollinger bands to 12 with 2 sigma (weekly) in charts:
Buy2 if [close] &gt; [Lower BB] and valrule([close] &lt;= [Lower BB],1).
Sell2 if [close] &lt; [Upper BB] and valrule([close] &gt;= [Upper BB],1).

!Set parameter for Wilder RSI to 5 (weekly) in charts:
Buy3 if [RSI Wilder] &gt; 40 and valrule([RSI Wilder] &lt;= 40,1).
Sell3 if [RSI Wilder] &lt; 60 and valrule([RSI Wilder] &gt;= 60,1).

Buy4 if [RSI Wilder] &lt; 40  And Low &gt; Low1.
Sell4 if [RSI Wilder] &gt; 60  And High &lt; High1.    

Exit if {position days} &gt;= 4.

The code and EDS file can be downloaded from http://aiqsystems.com/detectingswings.EDS

—Richard Denning

info@TradersEdgeSystems.com

for AIQ Systems