Site Meter The Lawyer Trader: DT 2000 Gave a Buy Signal a Month Ago: Here's the Thinkscript Code for the Indicator

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

1 comment:

john said...

I'm new to coding (like 3 months old) thinkorswim, but is there anyway you could shed a little of light on this indicator ? I can't seem to make it function