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 ?
Size:
Color:
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?
Size:
Color:
Yes, you are right : the top 10 performers must be selected from a dataset and are linked to a strategy.
Size:
Color:
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.
Size:
Color:
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 ?
Size:
Color:
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.
Size:
Color:
Thanks a lot
Size:
Color:
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.
Size:
Color: