Connors TPS Strategy
Author: barney
Creation Date: 7/2/2020 9:50 PM
profile picture

barney

#1
I'm new to Wealth Lab and have very limited programming experience.

I was hoping to use the Drag-and-Drop Build capability to create a strategy I'd like to test.

Unfortunately, it doesn't appear that Build will allow me to create it, although it did allow for some of it.

As a result, I looked at the code Build created and found I had some understanding of it, however, I don't have the ability to write code to do what I want.

Anyway, what I'm trying to create is the Connors TPS Strategy, which he described in one of his books. Here's the TPS Long strategy:

1) Above 200MA
2) The 2-period RSI is below 25 for 2 days in a row. Buy 10% of position on the close.
3) If prices are lower on the close than previous entry price, any day in position, buy 20% more of the position.
4) If prices are lower on the close than previous entry price, any day in position, buy 30% more of the position.
5) If prices are lower on the close than previous entry price, any day in position, buy 40% more of the position.
6) Exit on close when RSI(2) closes above 70.

What I was able to create using Build was:
1) Above 200MA
2) The 2 period RSI is below 25.
3) Exit on close when RSI(2) closes above 70.

I don't think the TPS Strategy is difficult coding for someone who's experienced, though maybe I'm wrong.

Would anyone be interested in providing me the code for a reasonable flat fee?
profile picture

Eugene

#2
Welcome to the forums Barney.

I just coded the strategy and uploaded it for all Wealth-Lab users:

Larry Connors TPS strategy (Long)

Follow instructions for script download (make sure to check "Download public strategies" and uncheck "Published since"). Once downloaded, you should find the strategy under the "Dip Buyers" folder in WLP.
profile picture

barney

#3
Wow! Thanks Eugene. I really appreciate it.

I was able to download and run the program with no problem.

I then checked AAPL (Apple) trades for Jan and Feb 2020 and found a few discrepancies.

In general, here's what I found.
1) The Entry and Exit are being done at Open price, rather than Close.
2) Trades triggered that shouldn't have triggered.
3) Incorrect buy and sell dates.

I didn't check the scale in (10%,20%,30%,40%) numbers yet, but I'll do that soon.

Thanks again Eugene. I really appreciate your help!

Here's the Trade Details for AAPL in Jan and Feb 2020. Sorry for the formatting problems.

Pos Symbol Qty Entry Date EntPrc Exit Date ExitPrc Prft% Prfit$ BrsHeld Profit per Bar
1)Long AAPL 16 1/16/2020 313.59 1/17/2020 316.27 0.66 $32.98 2 $16.49
**** Problems: Trade should not have triggered.
1/16/2020. Initial Entry at Open when RSI(2) is 74.25 . Problem: Entries should be at Close. RSI(2) is not below 25 for 2nd day.
1/172020. Exit is at Open. RSI(2) is 87.27. Problem: Exit should be at Close.

2)Long AAPL 16 1/28/2020 312.60 1/30/2020 320.54 2.34 $117.20 3 $39.07
***** Problems: Trade should not have triggered.
1/28/2020 Problem: Entry should be at Close. RSI(2) is not below 25 for 2nd day.
1/30/2020 Problem: Exit should be at Close.

3)Long AAPL 16 2/3/2020 304.30 2/5/2020 323.52 6.11 $297.62 3 $99.21
***** Problems: Wrong exit date.
2/3/2020 Problem: Entry should be at Close.
2/5/2020 Problem: Exit should be at Close. Exit should have been on 2/4.

4)Long AAPL 15 2/24/2020 297.26 3/3/2020 303.67 1.93 $86.25 7 $12.32 -13.87 2.22
Long AAPL 17 2/26/2020 286.53 3/3/2020 303.67 5.78 $281.48 5 $56.30 -10.63 5.88
Long AAPL 18 2/28/2020 257.26 3/3/2020 303.67 17.83 $825.48 3 $275.16 -0.45 17.93
***** Problems: Two incorrect entry dates. Incorrect exit date.
Entries and Exit should be at Close.
The Buy on 2/24 is correct. However, other buys should be on 2/25 and 2/27.
The Sell should be on 3/2.
profile picture

barney

#4
Just a quick correction to 4) above. I said the buy dates should be 2/24, 2/25 and 2/27. The correction is that there should be a fourth buy date at 2/28.

Also, I just took a quick look at the scale-in numbers for 4) above, which I show again here:

4)Long AAPL 15 2/24/2020 297.26 3/3/2020 303.67 1.93 $86.25 7 $12.32 -13.87 2.22
Long AAPL 17 2/26/2020 286.53 3/3/2020 303.67 5.78 $281.48 5 $56.30 -10.63 5.88
Long AAPL 18 2/28/2020 257.26 3/3/2020 303.67 17.83 $825.48 3 $275.16 -0.45 17.93

The shares shown for the 3 position scale-in trade above are: 15 shares, 17 shares and 18 shares. Based on the scale-in % rule, the % should be 10%, 20%, and 30%.

Just doing a rough calculation based on shares, I believe the share totals should be something closer to 15sh, 30sh, and 45sh.

Thanks Eugene.
profile picture

Eugene

#5
QUOTE:
1) The Entry and Exit are being done at Open price, rather than Close.

As AtClose entries cannot generate Alerts in WL, I think it makes better sense for you to avoid them from the start and use bar+1. See the FAQ, please:

FAQ | Strategies and WealthScript > Alerts are not triggered

You can replace *AtMarket(bar + 1) with *AtClose(bar) in the code if you like.

QUOTE:
The shares shown for the 3 position scale-in trade above are: ...

To not complicate the code, pyramiding is not included into the system logic. It can be controlled with the Pyramiding PosSizer from the MS123 PosSizers library (here's an overview). To install the Extension you have to be a customer, though.

QUOTE:
1/16/2020. Initial Entry at Open when RSI(2) is 74.25.

My bad. Thanks for spotting this. Fixed (see below).

QUOTE:
Problem: Entries should be at Close. RSI(2) is not below 25 for 2nd day.

From a programmer's standpoint, there is no such requirement for the RSI to stay below 25 for additional entries in your own description of the system:

3) If prices are lower on the close than previous entry price, any day in position, buy 20% more of the position.
4) If prices are lower on the close than previous entry price, any day in position, buy 30% more of the position.
5) If prices are lower on the close than previous entry price, any day in position, buy 40% more of the position.


Now it turns out that it might've been ambiguous. A little cross check and from what I gather in other sources, they have it neither:

https://www.stockfetcher.com/forums/Filter-Exchange/Connors-TPS/146101/0
https://www.turingtrader.com/connors-tps/

However, if I delve into the open source code from the 2nd link (right at the bottom) clearly it's there:

https://github.com/fbertram/TuringTrader/blob/develop/BooksAndPubs/Connors_HighProbEtfTrading.cs

As the requirement makes sense, I've uploaded an updated revision of the strategy: Larry Connors TPS strategy (Long) Rev.A. To run it you will have to install Community Indicators library and restart WLP. As it's available to WL customers, please create a support ticket to verify your Fidelity WLP entitlement before you're able to download the extension and run the system.

profile picture

barney

#6
Thanks Eugene. I'll be delving into this, hopefully later today.
profile picture

barney

#7
Hi Eugene:

I've requested access to the Community Indicators library.

I see that you've made the following change in Rev A.

"The 2-period RSI is below 25 for 2 days in a row. Applies to all entries (Rev.A)"

(A)Based on my interpretation, can you change that as follows:

1) Concerning the RSI(2) buy condition, my reading is that RSI(2) only applies to the Initial buy and not subsequent buys, as follows:

"The 2-period RSI is below 25 for 2 days in a row. Buy 10% of position on the close."

2) Subsequent buys are based solely on a lower price, for example:

"If prices are lower on the close than previous entry price, any day in position, buy 20% more of the position."

3) Finally, the exit is again based on RSI(2).

"Exit on close when RSI(2) closes above 70."

(B) I looked into the code at TuringTrader that you provided the link to. (Thanks for that, by the way). I'm not a programmer by any stretch, but I have some limited experience.

From my reading of the code, only the Initial buy (and the Exit) uses RSI(2) as a condition. Subsequent buys are based on a lower price condition, without RSI consideration.

Here's the relevant code. The "subsequent" buys are shown in the section called:

CODE:
Please log in to see this code.
profile picture

Eugene

#8
QUOTE:
2) Subsequent buys are based solely on a lower price, for example:

Good catch Barney. It's a moot point why the logic is like that, allowing the buys to be triggered by the RSI jumping to say 65 yet while the price gets lower. But I'll adhere to the system rules so meet Revision B:

Larry Connors TPS strategy (Long) Rev.B.

P.S.
QUOTE:
"Exit on close when RSI(2) closes above 70."

Exit is done at open next bar (as explained in post #5 above).
profile picture

fred9999

#9
I am not a programmer, but once upon a time coded this system. But only for longs. The truth is not sure if this is correct in terms of the multiplicity of "BuyAtMarket". Although the transactions are executed correctly.

CODE:
Please log in to see this code.
profile picture

Eugene

#10
Nice try Jury but it does not completely match author's idea. For the additional entries you're always comparing the Close price with the previous Close. However, system's rules imply that the Close price should be lower than previous entry price which could have happened on any bar before - not necessarily the adjacent bar:

3) If prices are lower on the close than previous entry price, any day in position, buy 20% more of the position.

P.S. Although multiple entries is a simple workaround for not having to deal with the Pyramiding PosSizer, this approach isn't universal. Generally, "if (IsLastPositionActive)" construct should not be used with multi-position systems.
profile picture

fred9999

#11
Yes, indeed, I was mistaken. Then so, but only for BuyAtClose(bar):

CODE:
Please log in to see this code.
profile picture

barney

#12
Hi Eugene:

I installed the MS123 PosSizer Library 2012.12 and the Community Indicators library 2020.06. I rebooted WLP after each install. The Extension Manager shows they are installed.

I then ran Larry Connors TPS strategy (Long) Rev.B, which ran fine. I briefly checked the generated signals and they look correct. I'll be checking them more thoroughly later.

No pyramiding is shown in the trade output, so I'm now trying to use the PosSizer, but I can't find it. I looked thru what I believe are the various relevant docs, but I still couldn't figure it out how to invoke it.

How do I access PosSizer to use in a backtest?

Thanks.
profile picture

barney

#13
Hey Eugene. I just found it. Sorry about that ! I'll be checking it out. Thanks.
profile picture

Eugene

#14
Barney,

It's the Pyramiding PosSizer that is used to apply the pyramiding rules to a system. It requires a signal name to recognize the initial signal which starts the pyramid (not necessary the first entry). The strategy code isn't pyramiding enabled since entries aren't marked. You can easily fill the gap with a little change to apply to the code:

CODE:
Please log in to see this code.


Then in the Pyramiding PosSizer's GUI, make sure "initial" is entered in the "Initial entry signal" field. Choose "Reverse pyramid" or a shape of your choice.

If this seems complicated then @fred9999 has provided a quick solution that doesn't require the PosSizer. Good luck!
profile picture

barney

#15
Thanks Eugene!

Your code change, adding "initial" to enable the pyramiding, did the trick! I really appreciate your help!

Also, thanks @fred9999 for providing your code. It helped give me a better understanding of the code used here.
profile picture

Eugene

#16
Glad you got it working!
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).