29. 9. 2025

5 1

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

  1. Code Editor → New → Custom Analysis, name the file CARenameFindReplace
  2. Paste the code (below) and Compile.
  3. If needed, restart SQX.

How to use

  1. Custom Project → Task → Custom Analysis.
  2. In Full databank analysis, select CARenameFindReplace and choose your Source databank.
  3. In Input args enter one of:
    -
    Replace: old=>new
    Remove: old
    -
  4. Run. All strategy names in the Source databank are updated.
  5. 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");
    }
}

 

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Related posts