How to select automatically the top 10 performers every 3 months for a strategy ?
Author: abegy
Creation Date: 12/15/2012 6:00 AM
profile picture

abegy

#1
I would like to have the possibility to create a trading list of symbols based on the last 12 month results but updated every 3 month. The logic is to select only the 10 first performers on this list and trade it during the next 3 months.

I can do that manually but I would like to automate it. I don’t know how I can script it to be able to backtest automatically.
Can you help me Eugene ?
profile picture

Cone

#2
If you're only selecting 10 stocks from the first list, why do you need the first list at all? It sounds to me you just want to identify the top 10 performers from a DataSet, like the S&P 500, and trade those 10 for the next 3 months? Are these used in some other trading strategy or just buy and hold for the next 3 months?
profile picture

abegy

#3
Yes, you are right : the top 10 performers must be selected from a dataset and are linked to a strategy.
profile picture

Cone

#4
The easiest way I can think of is to create the list in your strategy.

1. Every 3 months, create a list of symbols that is sorted by some performance measure. See RSI Rotation for an example.
2. If your list contains Bars.Symbol, then you trade it. If it's not, you don't.
3. You'll have to manage the active positions when the list is refreshed every 3 months.
profile picture

abegy

#5
Thanks for your reply.
But what I would like to do is to have the possibility to backtest the logic and to optimize it (for example to find if the best parameter is 20 performers instead of 10...).
Do you see a way to script it ?
profile picture

Cone

#6
I just explained how to script it. You create a list that refreshes every 3 (or whatever) months. If the current symbol is in the list, then you trade it, otherwise you don't. It's a condition to add to the entry logic.

Here's an example. The logic allows you to continue to process the exit logic even if the symbol falls out of the list.

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

abegy

#7
Thanks a lot
profile picture

Cone

#8
By the way, this condition - if (bar % 63 == 0) - is not a very good one since it depends on the bar number, which means your results will change depending on the start date. You should create your own condition that serves the purpose.
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).