LR Bands for Think Or Swim

I've been reading some of the discussions lately on the TTM forum about different types of reversion to the mean stock strategies. One strategy I've been playing around with a bit was suggested by John Carter and expanded upon by Gary_P on the forum. The basic idea is that you buy on pullbacks to the +/- 1 or 2 Std Deviations from the linear regression curve . He was kind enough to provide some Tradestation snippets and I have gone ahead and translated them to TOS for your charting pleasure. Enjoy.

So in the example above, You would have entered on 11/29 at 1168 ~ 1175. Your target would have been 1230 with a stop at 1120 or so. Did I make this trade? No. I had my entry a couple of points too low. C'est La Vive.

#hint:atbLR Bands\nThis script plots the historical values of the Linear Regression channel. A big thanks to the TS code written by Garp_P\n

#hint Length: Length of Channel
#hint NumDevs: Width of Channel in Stdevs.

input Length = 38;
input NumDevs = 2.0;

def SDev = stdev(close,Length) * NumDevs;
plot LR = Inertia(close, Length);


plot UpperBand = LR + SDev;

plot LowerBand = LR - SDev;


Trung said...

Your code for the reversion bands, where you do copy and paste the code so it can be seen on the underlying chart?

Thanks =)

Andy Brown said...

Here is a link that will help you get started:
From that screen, click NEW and then cut and paste the code.

Henry Goh said...

Andy, thanks so much for this posting. I'm not a code person so this was so helpful. I wonder if there is a similar code for Metastock that is available? Thanks again.

Andrew Brown said...

@Henry, I'm not sure about Metastock. I haven't used that product.