Rename Strategies with Batch Find & Replace – Custom Analysis
Ideal if you want to quickly create clean, informative names across a whole databank – this Custom Analysis snippet lets you batch rename strategies in StrategyQuant X using simple find → replace (or just find → remove).
— What it does
-
Runs as a Custom Analysis (Full databank analysis).
-
Input args accepts
find=>replace or just
find to remove.
-
Renames in place in the selected Source databank.
-
Literal, case-sensitive match. Supports
\n,
\t,
\r.
-
Great for mass cleaning: trim prefixes/suffixes, remove words, standardize symbols/timeframes/directions.
— How to install
- Code Editor → New → Custom Analysis, name the file
CARenameFindReplace
- Paste the code (below) and Compile.
- If needed, restart SQX.
— How to use
- Custom Project → Task → Custom Analysis.
- In Full databank analysis, select CARenameFindReplace and choose your Source databank.
- In Input args enter one of:
-
Replace: old=>new
Remove: old
- - Run. All strategy names in the Source databank are updated.
- Reload the databank to see the change.
— Examples
- Remove the word “Strategy ” (with trailing space):
Strategy =>
- Convert SQX auto-name to a formatted label:
Strategy =>XAUUSD_H1_L_
- Strip dots after a prefix pass:
.=>
Tip: Run multiple passes for multi-step formatting (e.g., add a prefix, then strip characters, then add a suffix). Consider duplicating the databank first if you want an easy rollback.
Code:
package SQ.CustomAnalysis; import com.strategyquant.tradinglib.CustomAnalysisMethod; import com.strategyquant.tradinglib.ResultsGroup; import java.util.ArrayList; public class CARenameFindReplace extends CustomAnalysisMethod { public CARenameFindReplace() { super("CARenameFindReplace", TYPE_PROCESS_DATABANK); } @Override public boolean filterStrategy(String project, String task, String databankName, ResultsGroup rg) throws Exception { return true; // keep all strategies } @Override public ArrayList<ResultsGroup> processDatabank( String project, String task, String databankName, ArrayList<ResultsGroup> databankRG) throws Exception { String raw = getInputArgs(); if (raw == null) raw = ""; // Support "find=>replace" OR just "find" (remove) String find, repl; int arrow = raw.indexOf("=>"); if (arrow >= 0) { find = raw.substring(0, arrow); repl = raw.substring(arrow + 2); } else { find = raw; repl = ""; } find = unescape(find); repl = unescape(repl); if (!find.isEmpty()) { for (ResultsGroup rg : databankRG) { String oldName = rg.getName(); if (oldName == null) continue; String newName = oldName.replace(find, repl); if (!newName.equals(oldName)) { rg.setName(newName); try { rg.trySaveToFile(); } catch (Throwable ignored) {} } } } return databankRG; // no filtering, just rename in place } private static String unescape(String s) { if (s == null) return ""; return s.replace("\\n", "\n").replace("\\t", "\t").replace("\\r", "\r"); } }
Warning! Do not use this code. I cannot delete the article. It renames the strategies inside the SQX UI, but it somehow deletes the strategy file in Windows explorer! If anyone knows how to fix it, please share so I can update it.