The Code for a QQQ Trading Strategy

Here's a new QQQ trading strategy if you want to swing trade the NASDAQ instead of the S&P 500.

Previously, I laid out a simple SPY swing trading strategy requiring only basic counting, but now, we're going to dive deeper into some math.

Let's check out this new strategy together.

More...

Do You Want to Be Right or Do You Want to Make Money?

As you may already know, I'm all about relaxation.

Life is way too complicated to add more anxiety or drama.

Life should be a drama free zone.

And what's the number one way to add anxiety to your trading life?

Trading against the trend!

Seems like every new trader I meet is all about conspiracy theories, how the "fix is in" and how the stock market is going to crash to zero.

These people LOVE to "call tops" and short stocks in bull markets.  I know because I was once one of these fools.

When I first started trading, I thought I was smarter than the average bear and just couldn't stop shorting.  Looking back, I have no idea why.  

I guess it was just to prove "I was right" to my friends.

But it never worked, I lost money hand over fist, again and again and again, never learning my lesson.  

Then, out of nowhere, it hit me...

Do I want to be right? Or do I want to make money?

Sounds so simple, doesn't it?

It was a life changing moment.

I immediately flipped my thinking and my trading, no longer fighting against the trend, but using the trend in my favor.

And life got so much easier!

The Trend Is Your Friend Till The End

I harp so much on trading with the trend because it really is that important. 

If you want to make money, you HAVE to trade WITH the trend, i.e. buy dips when the market is going up, short rallies when the market is going down.

But how do we determine trend? Good question, glad you asked. 

Most traders use a simple moving average to determine trends.

If price is above say, the 200-day moving average, QQQ is moving up and in an uptrend.  

If it's under, QQQ is moving down and in a downtrend.

Axiomatic.

But here's the rub, EVERYONE on Wall St. uses the 200-day moving average.  

We want to do things a little differently, so our trading strategy is a bit more robust and not mined to death like the 200-day average is.

But before we get into that, let's recap, what have we learned?

  • Only Buy DIPS in up-trending markets
  • Only Short RALLIES in down-trending markets

QQQ Trading Strategy With a Twist

Here's where it's going to get a little weird for a second.

If the 200-day moving average is mined out what do we do?

How about an average, of an average of an average? Woah! Mind blow.

Not many people will have thought to do that, trust me, and it will keep our QQQ trading strategy away from over optimization because the idea is so strange.

But what does that even look like?  Well in code (which you know is how I test all my trading ideas) it would look like this:

moving_average_1 = average( close , variable_1 );
moving_average_2 = average( moving_average_1, variable_1);
moving_average_3 = average( moving_average_2, variable_1);

Notice how we are passing the first average as an input to the second average which then feeds the third average?

The variable in all this is the number of days we want to average over, and we keep that constant throughout the equations.

This now gives us three different moving averages, but all controlled by ONE variable that we can play with.

Now, using these three averages, we can determine trend in a new and novel way.

Prices are going up if:

moving_average_1 > moving_average_2 and
moving_average_2 > moving_average_3 and
close > moving_average_3 

And prices are going down if flipped backwards.

More QQQ Trading Strategy Secret Sauce

OK, we've got a novel way to define trend, but how do we know exactly when to buy or short?

Cue my favorite friend, mean reversion.

You've got to study up on mean reversion if you want to trade SPY, QQQ or most stocks.

I've written previously how mean reversion has been the defining force in the stock market since 1982, when index futures were introduce, effectively killing "technical analysis".

Keeping it simple, markets, like the NASDAQ and S&P 500, mean revert around, you guessed it, a "mean".

Making it even more simple, the markets now move up and down around this mean price (which changes from day to day).

You know what a mean is already, it's just an average over some period or number of samples.

And on certain time frames, these markets will move around their mean prices.

A great way to measure the mean of QQQ or SPY is just by using the 5-day moving average.

Now we have a new way to define a "dip" in prices, it will just be when QQQ is below its mean, by a certain amount.

Let's recap again, for up-trends (rules would be reversed for down-trends):

Only buy when QQQ is above all three moving averages AND when QQQ is below its mean by a certain amount.

Finding the Sweet Spot to Buy QQQ

Phew! If you made it this far, good job, it's almost over, I swear.

Next we're going to define a dip for a computer to understand.

It looks something like this:

close < average( close, 5 ) - variable_2 * atr

Average true range, or ATR, is something I've written about before, you might want to grab a refresher.

Basically, ATR gives us a standard way to measure current price fluctuations.

Variable_2 gives us a knob, if you will, to fine tune where we place our buy orders.

Put in a small number and the buy zone gets closer to the mean, put in a large number and it gets farther away.

This really is "secret sauce".  

It might seem straight forward now, but it took me YEARS to figure this part out.

Before I was using dumb indicators like RSI, MACD and Stochastics to tell me when prices had dropped enough to be a buyer.

But all those indicators do is take in price and massage it into pretty graphs, they don't tell you anything you don't already know by looking at price.

So why not use price itself!?  

Stay away from "indicators", they don't work.

I previously wrote how the MACD indicator is completely backwards... but I digress.

So now, how do we know when to sell when QQQ mean reverts to the upside? 

Well, we just sell when price gets above the mean, by a certain amount, using atr again.

qqq trading strategy examples

QQQ Trading Strategy Examples

Pseudo Code for a QQQ Trading Strategy

Let's tie a big bow on this whole QQQ trading strategy, shall we?

Let's write down the basic rules in pseudo code and I'll post the full code below for you to review: 

Buy If
      moving_average_1 > moving_average_2 and
      moving_average_2 > moving_average_3 and
      close > moving_average_3 and
      close < average of 5 days - x * atr

Sell If
      close > average of 5 days + y * atr

Bam! 

There we have it folks, a more intricate way to swing trade QQQ, and SPY if you are interested.

Now let's finish up this post by looking at the performance charts and statistics for this QQQ trading strategy. 

Happy trading!

QQQ Trading Strategy

Equity Curve of the QQQ Swing Trading Strategy

QQQ Statistics

Trade Statistics of the QQQ Swing Trading Strategy

QQQ Trading Strategy Code:

QQQ Trading Strategy Code

QQQ Swing Trading Strategy Code

About the Author

Hello! I'm Kurt the "Relaxed Trader" writing the stuff on this website. Feel free to ask me questions. I love talking to fellow traders that want to use computers to beat the stock market. Shoot me an email: Kurt@relaxedtrader.com

Leave a Reply 2 comments