Site Meter The Lawyer Trader: Linear Regression
Showing posts with label Linear Regression. Show all posts
Showing posts with label Linear Regression. Show all posts

Wednesday, September 19, 2012

DT 2000 Gave a Buy Signal a Month Ago: Here's the Thinkscript Code for the Indicator

The DT 2000 is a trend following indicator that I came  up with about a year ago.  It uses linear regression and it's purpose is to determine the trend of the overall market.  It uses linear regression slope readings on 4 different symbols and its defaults are qqq, xlv, xlf, tlt.  The indicator tends to work well on the weekly time frame..which makes sense because the longer time frames smooth out the choppy price action of equities.

Here's a chart, the DT 2000 is at the bottom and it's coloring the bars on the chart as well:

This indicator is just one more tool in my collection that I look at to help gauge risk and market bias.  I don't necessarily trade this like a system in and of itself--such as buying the SPY or SSO on buy signals.  What this buy signal does for me is it gives me the confidence to put on more long positions, whether the positions are stocks or covered calls or options spreads.  As you can see from the chart, we've had 3 other buy signals in the last 4 years and the buy signals tend to last several months before petering out.  We'll see if this signal has any legs to it.

Here's the thinkscript code for you thinkorswimmers out there:

####DELETE THIS LINE WHEN PASTING INTO TOS####


declare lower;

input symbol1 = "qqq";
input symbol2 = "xlv";
input symbol3 = "xlf";
input symbol4Inverse = "tlt";
input lrlength = 20;

def data1 = close(symbol1);
def data2 = close(symbol2);
def data3 = close(symbol3);
def data4 = close(symbol4Inverse);

def trend1 = linearRegressionSlope(data1, lrlength);
def trend2 = linearRegressionSlope(data2, lrlength);
def trend3 = linearRegressionSlope(data3, lrlength);
def trend4 = linearRegressionSlope(data4, lrlength);

def score1 = if trend1 > 0 then 1 else -1;
def score2 = if trend2 > 0 then 1 else -1;
def score3 = if trend3 > 0 then 1 else -1;
def score4 = if trend4 < 0 then 1 else -1;

plot DT = score1 + score2 + score3 + score4;    

def buysignal = crosses(DT, 0, crossingDirection.ABOVE);
def sellsignal = crosses(DT, 0, crossingDirection.BELOW);  

assignPriceColor(if dt > 0 then color.green else if dt < 0 then color.red else color.blue);


####DELETE THIS LINE WHEN PASTING INTO TOS####


I hope everyone is having a great week so far.

TLT

Wednesday, November 11, 2009

The Rally Continues

Stocks gapped up this morning and then kind of petered out a little in afternoon trading, but the rally is still going. We all know that the weak dollar is influencing stock prices, in fact, the two markets are correlated pretty tightly right now. Stocks are trending to the point where I'm long and holding overnight positions again, even though everyone is suspect of this rally. The key is to trade the signals...not the opinions of others.

Here's an hourly chart of the S&P 500 index with the TLT Trender v2 and some annotations:Personally, I think that we'll see new highs by the end of the week and then probably a quick pop up as shorts have to cover, but take that for what it's worth as it's only an opinion that can change on a dime. Next up, here's the Eur/Usd hourly chart also with the TLT v2 indicator (green, red, blue bars) and some annotations:As always, the goal is to watch price action and let that dictate what the next move will be. I must admit, I've gotten quite bullish after seeing the market shrug off the unemployment numbers last Friday and then rally and hold those gains this week...smells like strength to me.

Happy Veteran's Day and I want to give a big THANK YOU to all those that have served and currently serve our country in the armed forces.

TLT

Thursday, May 7, 2009

Profit Taking?: A quick look at the S&P

Yes, as Charles Kirk mentioned recently, making money in stocks has been a little too easy lately. Given today's slight sell off, I thought it would be a good time to take a look at the S&P. Now remember, this is on the S&P and is not representative of the full market, just the big caps...note that the Nasdaq is selling off quite a bit more today. Here's an hourly chart that shows the S&P from April 23 until today. As you can see, yesterday was a good time to take a little off the table. The uptrend is still in place...now we'll just have to see if it remains that way. I'll exit most of my longs and even look to short if that linear regression trend channel doesn't provide support.

TLT

Tuesday, April 7, 2009

Follow Up On The Usd/Chf

Plan the trade and trade the plan...this trade didn't work out as planned. The dollar picked up strength yesterday and the Usd/Chf popped out of the linear regression channel and stayed out of it. I did take a small position yesterday and it was profitable for a couple of hours, but now I'm out with a small loss. Can't win em all.

Here's an updated chart:Game plan for today:

Watch the Eur/Jpy--it's currently falling within in it's own trend channel and might offer up a nice buying opportunity;

Watch the Usd/Yen--this pair is still very strong but it needs to work of some overbought levels;

Watch the Eur/Usd--seems to be at a pivotal level..will go long if it holds the 1.3230 level at the end of today's session.

You can follow me on Twitter here for more updates throughout the day. Good luck trading!

TLT

Monday, April 6, 2009

By Request: USD/CHF Analysis

The Dollar has been weak over the past few sessions and the USD/CHF is no exception. I was asked to review the 4 hour chart for this pair and here it is:As you can see, I laid out a trade plan with some notes on the chart. Basically, the plan is to sell the pair if it reaches the top of the linear regression trend channel. It would also be nice to see the Stoch and RSIs both overbought (or near overbought) when the trade is executed. I also put down two profit targets on the chart. I'll sell half the position at the first target and then dump the rest at the second target or when the stoch gets oversold and then rises out of the oversold level--whichever occurs first.

Hope everyone's having a good start to the trading week.

TLT

Thursday, March 5, 2009

Golden Opportnity?

Excuse the pun. Take a look at the chart...it speaks for itself.

Tuesday, February 3, 2009

Eur/Usd Approaching a Good Selling Point and a Word on Running Stops

It's almost time to add to the Eur/Usd shorts, or enter a position if you are not in it yet. The pair has been rallying strongly for 2 days now, but the overall trend is still down and that is the direction I want to enter my trades. The best entry points are generally located at resistance points during a counter-trend rally (i.e. the pair has been going down for some time and then rallies).

The Eur/Usd is approaching the upper linear regression channel line, which might serve as a good low risk entry point. Here's the 4 hour chart:
Based on the above chart, I'll be looking to add to my short around the 1.3115 area. Notice that the RSI and Stochastic are both entering oversold levels as the pair gets closer to resistance. The major risk with this trade (and any trade where you counter a short-term trend) is that the pair will continue to advance and an all out breakout will occur. This is why you must have your uncle point...a point where you know your wrong and you must get out of the trade. I'm going to set a wide stop (100-150 pips above the upper channel line) because dealers and professional traders know that lots of retail traders will be jumping in around this level and if they see a cluster of stop loss orders near the resistance level (which they can because they watch the order books), they may very well gun for the stops. I'll manually close out the trade if the pair breaks through the channel and then remains bullish by not falling back below the line.

It's usually easy to tell when a false breakout was merely the dealers and pros gunning for stops because they will spike through a pretty well known support/resistance point and then sharply reverse. You can see several of these on the above chart...notice that the last 4 times the pair hit the upper channel line, the pair broke through the resistance but then closed much lower. The reversals are usually sharp because the dealers and pros are taking quick profits from hitting the stops and then entering in the opposite direction...the direction they believe that the pair will go.

All that being said, just remember that just because the pair is heading towards a resistance point does not mean that the market will respect it. This happen back in December with the same pair, as noted in this post. That was one situation where having a stopping point and respecting that stopping paid off. We'll see what happens this time.

Good luck out there.

TLT

Friday, December 19, 2008

NIce Price Action in Gold

For the past year, gold has been trending downward in a textbook linear regression trend channel. Take a look:

Notice how the price keeps hitting the top of the channel and then quickly falls back down. It might be a good time to short gold given that it recently bounced off the top channel again. I'm tempted to short here and set an exit target around $725...there seems to be a congestion area at that level.

Good luck out there.

TLT

Wednesday, December 10, 2008

Dollar Update

The dollar has been trading in a range bound congestion pattern lately, which is frustrating because that type of action sends out a bunch false signals on my trend following system (like this post). That's just the name of the game when you're attempting to catch and ride trends...a bunch of small losses while waiting for the big gain. Here's an updated 4-hour chart of the Eur/Usd pair.As you can see from the chart, the pair is still approaching the upper regression line. I will be paying close attention over the next couple of days to see how it reacts to that level. There's a little bit of bearish chatter out there about how the dollar is heading lower and it might be completing a head and shoulders pattern and blah, blah, blah. I say that we have to take a wait and see approach and try to hold off on getting too bearish. Remember, the trend has been down and we don't want to go against the prevailing trend until a new trend is established.

One interesting thing that I've noticed is that the dollar has not reacted very negatively to some bearish readings on a couple of indicators. The article that I linked to above states that the Dollar Index looks "sickly" and the author points out a couple of indicator readings to back up the opinion. Here is my own chart of the Dollar Index:As you can see, both the RSI and the MACD are very bearish right now...the RSI is sloping down and the signal line on the MACD is below the red line, which indicates a sell. While these are bearish, the price action has not confirmed the readings...at least not confirming that a new trend is developing. In my experience, it is generally a bullish (or at least neutral) signal when the MACD is falling after a bearish cross (the blue circle) but the price stays bound in a range like it has over the last month. I believe that it's jumping the gun a little to proclaim that the dollar down trend is beginning...it might just be some healthy consolidation and possibly a good opportunity to buy the pullback. Of course, I could be wrong and if the price action signals a new trend by breaking out of the range to the downside, then I'll be looking to short. Like always, only time will tell.

Good luck out there.

TLT

Sunday, November 30, 2008

Maybe time to buy the dollar now...right now?

In a recent post, I outlined a trade idea that had to do with buying the dollar when it touched the upper linear regression trend line. If you haven't/didn't read the post, here it is. Coming up with ideas for trades can be a very helpful exercise but being flexible and nimble in your forecasting is a prerequisite for successful trading. Unfortunately, the Eur/Usd pair has not rallied back to my entry target but that's okay because I can tell when I'm wrong and I was wrong...at least for the time being.

Here's an updated 4 hour chart of the Eur/Usd pair:As you can see from the above chart, the Eur/Usd did not hit it's upper regression trend line. Although that would have been an excellent entry, it's not mandatory for a good short entry into the pair (short being long the dollar). Actually, my trend following system just flashed a sell signal and I've taken a small position with the intention of adding to it if it starts making money.

Below is the same chart as above but, it's zoomed in so that you can easily see the sell signal. Here it is:The red circle outlines the sell signal from my system. Notice that both lines around the price are red (this is the multiple trend following systems signals) and the bottom histogram (BB width) is above it's break out zone (the purple line). These signals tell me that it's probably time to sell the pair (buy the dollar) because it's the path of least resistance. We'll see how it plays out...because nothing is even close to a sure thing and my trend following signals are certainly not an exception.

On a different note, here's my weekly ranking with the CNBC portfolio challenge. Like I said, I'm not actively managing my portfolio anymore, I'm just going to let it play out. As you can see, I finished the week in the top 0.2% of the challenge but I've actually fallen back to the 961st position...apparently lots of participants had huge gains on Friday because I actually had considerable gains but still fell back position wise. Here's a screen shot of my ranking:
Next week should be really interesting, both with currencies and stocks, and I look forward to posting some opinions on the price action. Be careful trading because we seem to be at a potential turning point...especially with stocks.

Good luck out there.

TLT

Tuesday, November 25, 2008

Almost time to buy the dollar again?

Although the dollar has been very strong over the last several months, it has taken a slide recently. A pullback is generally expected when an instrument has run up as much as the dollar has and the inevitable pullback can present an excellent opportunity for a longer time frame trade (like holding a trade for several days and maybe even a week as opposed to several minutes to hours). The trick is finding a good point to start fading the move and to have your "uncle point" designated before the trade. Entering a trade on a big pullback can be nerve racking...that's why you really need to have a detailed game plan that you can follow to the T.

I like to use a linear regression channel when I attempt to enter a trade like this. Below is a good 4-hour chart (as in each bar is 4 hours) of the Eur/Usd pair. The light blue lines are the linear regression lines. Linear regression is a concept that says that prices will eventually revert back to an average (reversion to the mean). I've found that this tends to especially work in a trending market with a trending average. Here's the chart:
The yellow circle is the area that I'll be looking to sell the pair, preferably close to the top line. I'll probably take half the position on the initial touch and then wait for the trend following indicators to confirm the sell for the other half.

One other thing that I like to look at to get a feel for how the dollar is doing is the broad dollar index. This index portrays the dollar against a broad selection of currencies to give you a more complete picture. I like that the index is going down and that there seems to be some potential support at the 50 day moving average. I would not be surprised if the dollar index finds support at about the same time that the Eur/Usd pair hits the top of the linear regression channel. The index provides some insight into the breadth of the dollar, which will help to determine if the move is potentially sustainable. It is always nice to see the dollar rallying against several currencies as opposed to the one currency that you're trading it against.

We'll see how the dollar plays out and I'll be sure to post and update soon.

Good luck out there.

TLT

*****
Update*****

Several hours after I made this post I was doing my nightly scan through various blogs and I pulled up Moaxian's site. He could not be more bearish on the dollar and he thinks that it will give up all of its gains and fall below 70 on the dollar index. This view obviously goes against my plan to fade the move or "buy the dip" in the dollar but his reasoning is for fundamental reasons.

I'm not saying that he's right or that I'm right, I just think that our different perceptions are interesting. I will still take the trade because fundamental views tend to work against my bottom line, but it is good to note potential macro shifts of this nature and be alert to new trends that may develop.