Saturday, September 15, 2018

September 15 Swing Trade Indicator

.
If you are on the blog page in a web browser from a computer, please subscribe to this using the "Follow by Email" link to the left.  If you're on a mobile device you should see something in the frame that allows you to subscribe.  Having your email helps me to notify you when Google mucks up email distribution.

~~~~~~~~~~

It's been many months since I've paid attention to this blog -- I'm very active at Dr. Jeff Scott's HGSI Discord forum ( https://discord.gg/4QAUqyd ) and there are only so many hours in a day.  Managing multiple communication paths takes a considerable amount of time, as I'm sure you are aware.

All that being said, I recently released an indicator for public testing in the Discord forum that is related to swing trading, and I wanted to document a basic understanding of how to use the indicator.  Right now the code version is SwingStop 2.1, and I reserve the right to update it without notification here.

The figure below shows a recent screen grab for the SPY:


Click on the image to enlarge.

The graphic shows two plot windows.  The top is a weekly window, and the bottom is the daily.  The indicator is adaptive and works on both time scales.  I have not tested it on longer (e.g. monthly) or intraday scales, so beware if you venture off the reservation.

For now, keep the settings to daily and weekly.

There are two indicators in each window, and you can see red/magenta crosses are on the top of the price series, typically when the series is heading downward or moving horizontally, and cyan and blue on the bottom, typically when the series is moving upward or horizontally.  The blue/cyan combination gives us an indication that the series is in an uptrend for the given interval, and the red/magenta combination tells us when the series is in a downtrend.

If you look closely, you also see periods where red is on top and cyan is on the bottom.  This is a mixed indicator, and when this occurs, it signals that a potential trend change may be in the works.  Specifically, look at the last few weeks of April (top plot) for the weekly SPY, and look at the beginning of this last week for the daily SPY.  You can see areas where red is on top and cyan is on the bottom.

Note that I suppress magenta and dark blue when this transition is occuring, as there is no additional information to be gleaned.

In the normal course of movement, the following will be apparent, independent of the window being daily or weekly:

  1. If in an uptrend (blue/cyan on the bottom), as the price series moves upward, the stop also ratchets upward as gains are made.  The cyan stop is more aggressive than the blue stop (e.g. the blue stop is tighter), and both are tied to average true range and fast/slow stochastic calculations.
  2. If in an uptrend and the low of the bar cuts through one of the blue/cyan stops, the system will toggle to an intermediate or mixed condition (cyan on bottom, red on top) or will flip to a downtrend condition (both red and magenta on top).
  3. If in a mixed condition with red on top and cyan on the bottom and the price cuts through the red stop (e.g. a bullish move), the system will indicate a full uptrend (cyan and blue on the bottom).
  4. If in a downtrend and the high of the bar cuts through one of the red/magenta stops we'll enter the intermediate or mixed state (red on top and cyan on the bottom), and potentially a new uptrend state (cyan and blue on the bottom).  
  5. The indicator uses intraday data, so it is possible to start the day in one state and transition to another state by the end of the day.  This can impact your entry/exit plans.
Knowing this, take a look at various symbols in uptrends, downtrends, and range bound so that you can get a feel for what you are seeing.  It should make sense - no real rocket science here.

~~~~~~~~~~

Intuitively, if the longer-termed weekly indicator has blue/cyan on the bottom it would make sense that we're enabling entry on the daily chart (somewhere), so that we can participate in the uptrend.  It also goes to reason that if the longer-termed weekly indicator has red/magenta on the top of the price series that we probably are in a downtrend and we do not want to be long the equity.

If this is your intuition about the indicator then you have a basic understanding of what is going on.


The primary challenge is determining the best entry/exit points for the indicator.  I'm not talking about optimization -- there is nothing to optimize here, per se -- I'm simply stating that there are conditions that are favorable for entry and exit of a position, and because there are known states to the indicator, we should be able to get a sense of what works best.

The remainder of this blog entry discusses how you should be thinking about entries and exits.

~~~~~~~~~

There are four indicators across the daily and weekly presentations:  two are associated with the daily bar interval, and two are associated with the weekly bar interval.

As previously discussed, we can be in an uptrend on the daily and weekly charts, a downtrend, or mixed/intermediate trend.  Behind the scenes we can either have cyan/bottom red/top or blue/bottom and magenta/top, but I suppress the blue/magenta intermediate signal as it doesn't add any more visual information to the plot.  It *does* add information though to the evaluation.

There are two actions we need to evaluate:  entry ("buy to open") and exiting ("sell to close").   This throws in two more states.

When you mix all of this together, there are a considerable number of possibilities to consider -- 256 to be exact.  I had to devise a way of uniquely identifying each of the states.

What I came up with is straightforward:  
  1. Let a downtrend be indicated by -1, and let an uptrend be indicated by +1.
  2. There are are a total of 4 indicators, two for the weekly, and two for the daily.  Let the daily indicators be p1 and p2 and the weekly indicators be q1 and q2.
  3. You can buy, and you can sell. So, we have p1b, p2b, q1b, q2b, p1s, p2s, q1s, and q2s.
When you create the table you'll see that it is 8 columns by 256 rows.  I'll save you the details, but a row of that table represents any arbitrary state of a complete buy/sell transaction.  You name a given buy state and a corresponding sell state and I can point to it on the table.

When you "sum" a row -- add up all of the individual "-1" or "+1" values, you get a range of values that span even numbers from -8 to +8.  Again, I'll save you the details -- just push the "I believe" button.

~~~~~~~~~~~

I created a 12-year backtest with the SPY, 12 years so that it includes the 2007 - 2009 time frame.  What I wanted to see what various returns were over this period of time given all of the different combinations of buying and selling.

The initial conditions were as follows:
  • $100K starting portfolio
  • Only trade the SPY
  • Buy the next morning open on a given entry condition, and sell the next morning open on a given exit condition
  • Do not exceed equity of 1.0 (use no margin)
The results are as follows:


The x-axis is the "summation" of the states of a row.  For example, the entry/exit summation state that corresponds to 

p1b=1,p2b=-1,q1b=1,q2b=-1,p1s=-1,p2s=1,q1s=-1,q2s=1
sums to 0.

This row that I presented above, in fact, is the top dot on the x=0 line (Total Return = $183K).

You get the idea.  If not, ask.


If you take a closer look at the graphic above, you see that equity is below zero for many of the combinations.  This isn't good.  It basically is stating that those entry/exit combinations, repeated over and over for 12 years with the SPY, produced a negative return to the portfolio.

We want to avoid those sequences.  Let's ponder:

It should be readily apparent that if the entry conditions are the same as exit conditions, we'll immediately churn the account, as the same signal that indicated to enter will be the same signal that causes us to exit.  We want to avoid situations where the buy-side state is the same as the sell-side state.

Reducing the set of conditions where buy-side equals sell-side produces the following graphic:


Each of those dots represents a losing portfolio where the buy-side conditions were the same as the sell-side conditions.  In fact, every single row is a losing row.  Out of the 256 possible states, there are 16 that are duplicates and those will be removed from evaluation.  

There were more negative values than 16 though, so we need to keep digging.

I'll save you the details of the progression to reject the negative portfolio returns, and present you with the results.  The high-level summary is this:
  • p1b = p2b, that is, during a buy sequence, we want the daily indicators to both be the same.
  • q1b = q2b, that is, during a buy sequence, we want the weekly indicators to both be the same.
  • p1s <> p2s, that is, during a sell sequence, we want the daily indicators to BE DIFFERENT.
  • we don't care about the state of q1s or q2s, per se.
The return graph for the set of conditions looks like the following:



So, a few comments about this set of results.
  1. "Confirm" does not mean uptrend or downtrend, it means that p1b=p2b and q1b=q2b. The state of these indicators could be +1 (uptrend) or -1 (downtrend), so both states apply.  What is important is that they are the same on the daily or weekly.
  2. "Different" for the sell side daily indicators is that p1s <> p2s.  p1 could be in an uptrend, which would force p2 to be in a downtrend, or visa versa.  If they are different after you enter, sell.
  3. None of the remaining entry/exit setups produce a negative total return for the SPY taken across 12 years of data.
We could stop right here and most likely have a positive edge using the SwingStop indicator, simply applying the following:
  • p1b = p2b, that is, during a buy sequence, we want the daily indicators to both be the same.
  • q1b = q2b, that is, during a buy sequence, we want the weekly indicators to both be the same.
  • p1s <> p2s, that is, during a sell sequence, we want the daily indicators to BE DIFFERENT.
  • we don't care about the state of q1s or q2s, per se.
The reason I think this works is that we are waiting for a confirmation in either direction to buy on both the weekly and daily time scales, and then we exit once we see the deviation on the daily time scales.   

~~~~~~~~

If you want further refinements, read on.

Extra Credit for The Geeks Amongst Us

For the geeks amongst us, the state table that produced the previous graphic is as follows, with highest portfolio gains at the top and lowest gains at the bottom:

p1b=(-1),p2b=(-1),q1b=(-1),q2b=(-1),p1s=(-1),p2s=1,q1s=(-1),q2s=(-1)
p1b=1,p2b=1,q1b=(-1),q2b=(-1),p1s=1,p2s=(-1),q1s=1,q2s=(-1)
p1b=(-1),p2b=(-1),q1b=(-1),q2b=(-1),p1s=(-1),p2s=1,q1s=1,q2s=1
p1b=1,p2b=1,q1b=(-1),q2b=(-1),p1s=(-1),p2s=1,q1s=1,q2s=(-1)
p1b=(-1),p2b=(-1),q1b=(-1),q2b=(-1),p1s=1,p2s=(-1),q1s=(-1),q2s=(-1)
p1b=1,p2b=1,q1b=1,q2b=1,p1s=(-1),p2s=1,q1s=1,q2s=1
p1b=1,p2b=1,q1b=1,q2b=1,p1s=(-1),p2s=1,q1s=(-1),q2s=(-1)
p1b=(-1),p2b=(-1),q1b=(-1),q2b=(-1),p1s=1,p2s=(-1),q1s=(-1),q2s=1
p1b=1,p2b=1,q1b=(-1),q2b=(-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2s=(-1),q1s=(-1),q2s=(-1)
p1b=(-1),p2b=(-1),q1b=1,q2b=1,p1s=1,p2s=(-1),q1s=(-1),q2s=(-1)
p1b=(-1),p2b=(-1),q1b=1,q2b=1,p1s=(-1),p2s=1,q1s=1,q2s=1
p1b=1,p2b=1,q1b=1,q2b=1,p1s=1,p2s=(-1),q1s=1,q2s=1
p1b=(-1),p2b=(-1),q1b=1,q2b=1,p1s=1,p2s=(-1),q1s=1,q2s=1
p1b=1,p2b=1,q1b=(-1),q2b=(-1),p1s=1,p2s=(-1),q1s=1,q2s=1


There are 32 rows, or separate entry/exit conditions out of 256 total that produces positive returns using the SPY over a 12-year period.

I've colored the entry conditions where some form of downtrend exists at entry time.  The color coding is as follows:
  • Magenta, or the purple looking color, reflects just the daily being in a confirmed downtrend (p1b = p2b = -1) and the weekly being in a confirmed uptrend (yellow, q1b = q2b = +1).
  • Red, or the red looking color (!), showing that both the daily and weekly are in a downtrend (p1b = p2b = q1b = q2b = -1)
  • Dark Red, or the brownish looking red, showing that just the weekly is in a downtrend (q1b = q2b = -1) but the daily is in an confirmed uptrend (cyan, p1b = p2b = +1)
There are also instances where the entry conditions are in some form of uptrend at entry time.  This is the green coded entry.

The tally:
  • There are 8 instances where the daily and weekly are confirming a downtrend for entry (red)The average portfolio gain for these runs is $106K.
  • There are 8 instances where the daily is in an uptrend (cyan) and the weekly is in a downtrend (dark red).  The average portfolio gain for these runs is $90K.
  • There are 8 instances where the daily and weekly are confirming an uptrend for entry (green).  The average portfolio gain for these runs is $77K.
  • There are 8 instances where the daily confirms a downtrend for entry (magentabut the weekly is an in uptrend (yellow).  The average portfolio gain for these runs is $58K.

From this I conclude that: 
  1. the most psychologically difficult time, when both the weekly and daily are in a downtrend, is the best time to buy with this indicator (red).
  2. the next most advantageous time to buy is when the weekly is still bearish yet we see some confirmation of a new uptrend on the daily (dark red/bearish and cyan/new uptrend).
  3. the next, but not last advantageous setup is where both the daily and weekly are in an uptrend (green).
  4. the least advantageous, but still with a positive expectation period, is when we are in an uptrend and we have a confirmed pullback (yellow & magenta).
I'm somewhat surprised that the daily downtrend in the midst of a weekly uptrend is last in performance on the list (last of the good performance, that is).  I suspect this is because much of the gains have been attained, but I am unsure to the exact cause.

Now, from a practical viewpoint, I simply do not know how I can do 1. (entry when both daily and weekly are in a confirmed downtrend).  I note that the SPY has been in an uptrend for a long time so ensuring that the underlying stock is in a long-term uptrend most likely is a valid criteria.  I do think I can start with 2. (entry on the daily but longer-termed downtrend), with limited capital committed up front.  

Obviously, food for thought.

~~~~~

That's all for now.  If you have questions -- ask.

~~~~~~~~~

As with all my ramblings, you are responsible for your own actions and I am not.  Nothing I've written here is advice to buy or sell any security, so don't do it unless you absolutely take ownership for your actions.

Regards,

Paul


No comments:

Post a Comment