Select Best Strategies by Entry Indicators Group with Arguments
Aquí el artículo actualizado con el tercer argumento:
Select Best Strategies by Entry Indicators Group with Arguments
Description
This custom analysis snippet processes a databank and automatically selects the best N strategies from each group of strategies that share the same Entry Indicators combination.
It is useful when you have a large databank with many strategies built from similar building blocks. Instead of manually comparing them, this snippet groups them by their entry conditions and keeps only the top N strategies from each group, ranked by a configurable scoring criterion.
How it works
The snippet uses the built-in Entry Indicators databank column to identify which indicators each strategy uses in its entry conditions. Strategies that share exactly the same entry indicators are considered part of the same group. Within each group, strategies are ranked by the selected criterion and the top N are selected as winners.
All winning strategies are copied to the Target databank. The Source databank remains untouched.
Requirements
No additional snippets are required. All dependencies are available in the standard SQX installation.
Setup instructions
- Copy the code below into a new Custom Analysis snippet in CodeEditor and name it SelectBestByEntryGroupArgs
- Compile the snippet
- Create a new Custom Project
- Add a new task of type Custom Analysis
- In the task configuration, set Full databank analysis to SelectBestByEntryGroupArgs
- Set your Source databank (the one containing all your strategies)
- Set your Target databank (where the winners will be copied)
- Make sure the toggle Filter by results of custom analysis is disabled
- Optionally configure the Input args field (see below)
- Run the project
Input args
The snippet accepts three optional parameters separated by commas: the scoring criterion, the number of top strategies to select per group (minimum 1, maximum 10), and the sample type to use for calculations.
Format: Criterion,N,Sample
Examples:
- (empty) — 1 best strategy per group, Ret/DD Ratio, Full Sample (all defaults)
- RetDD — 1 best per group by Ret/DD Ratio, Full Sample
- RetDD,3 — 3 best per group by Ret/DD Ratio, Full Sample
- RetDD,3,IS — 3 best per group by Ret/DD Ratio, In Sample
- Sharpe,5,OOS — 5 best per group by Sharpe Ratio, Out of Sample
- Calmar,10,Full — 10 best per group by Calmar Ratio, Full Sample
Available criteria:
- RetDD — Ret/DD Ratio (default)
- Sharpe — Sharpe Ratio
- ProfitFactor — Profit Factor
- NetProfit — Net Profit (absolute)
- Calmar — Calmar Ratio
- WinRate — Percentage of winning trades
- Drawdown — Lowest absolute drawdown (lower is better)
Available sample types:
- Full — Full Sample (default if omitted)
- IS — In Sample
- OOS — Out of Sample
Example
If your Source databank contains 42 strategies distributed across 17 different Entry Indicators combinations, and you set the Input args to RetDD,2,OOS, after running the snippet your Target databank will contain up to 34 strategies — the 2 best by Ret/DD Ratio calculated on Out of Sample data from each group. Groups with only one strategy will contribute just one.
Code
Code in the header of the article.
Disclaimer
This snippet is provided for educational and research purposes only. It does not constitute financial advice or a recommendation to trade any financial instrument. Past performance of any strategy selected by this tool is not indicative of future results. Use at your own risk. Always validate results independently before using any strategy in live trading.
Thanks for following along. See you in the next build.
José Carlos
Very interesting ! Thank you Pepe
You’re welcome! Enjoy!