Strategy Parameters Template

Learn how to define TradeStaq strategy parameters using JSON and import them into the UI.

Overview

TradeStaq allows you to define parameters in two ways:

  1. UI-Based: Define parameters through the web interface
  2. JSON File: Create a JSON file with parameter definitions and import it

The JSON approach is ideal for:

  • Developing parameters locally in your favorite editor
  • Version controlling your configurations with Git
  • Sharing parameter presets as files
  • Quick batch parameter setup

JSON Schema

Define parameters using a simple JSON structure:

{
  "parameterName": {
    "type": "number" | "boolean" | "string" | "select",
    "default": value,
    "min": number,
    "max": number,
    "step": number,
    "options": ["a", "b"],
    "label": "Display Name",
    "description": "What this parameter controls"
  }
}

Parameter Types

TypeDescriptionExample
numberNumeric input with optional min/max/stepRSI period, percentage values
booleanTrue/false toggleEnable/disable features
stringText inputCustom identifiers
selectDropdown with predefined optionsTrade direction, mode selection

Example Parameters

{
  "rsiPeriod": {
    "type": "number",
    "default": 14,
    "min": 2,
    "max": 100,
    "step": 1,
    "label": "RSI Period",
    "description": "Number of periods for RSI calculation"
  },
  "useStopLoss": {
    "type": "boolean",
    "default": true,
    "label": "Use Stop Loss",
    "description": "Enable automatic stop-loss orders"
  },
  "tradeDirection": {
    "type": "select",
    "default": "both",
    "options": ["both", "long", "short"],
    "label": "Trade Direction",
    "description": "Which direction(s) to trade"
  },
  "customTag": {
    "type": "string",
    "default": "my-strategy",
    "label": "Custom Tag",
    "description": "Tag for logging and identification"
  }
}

Downloading the Template

Click Download Template in the Parameters step of the strategy wizard to get a complete example JSON file.

// Download programmatically
fetch('/api/strategy-template')
  .then(res => res.blob())
  .then(blob => {
    const url = URL.createObjectURL(blob);
    const a = document.createElement('a');
    a.href = url;
    a.download = 'tradedroid-parameters.json';
    a.click();
  });

Importing Parameters

Method 1: Upload File

  1. Go to Configure Parameters step in the strategy wizard
  2. Click Import JSON
  3. Click Upload .json File
  4. Select your parameters file
  5. Review extracted parameters
  6. Click Apply Parameters

Method 2: Paste JSON

  1. Go to Configure Parameters step
  2. Click Import JSON
  3. Paste your JSON content
  4. Click Parse JSON
  5. Review and apply

What Gets Extracted

The parser extracts from each parameter:

  • name: The parameter identifier (e.g., rsiPeriod)
  • type: number, boolean, string, or select
  • default: The default value
  • min/max/step: Numeric constraints
  • options: Select dropdown options
  • label: Display name
  • description: Help text

Accessing Parameters in Code

After importing parameters, access them in your strategy via td.config:

// Access parameter values
const period = td.config.rsiPeriod;
const oversold = td.config.rsiOversold;
const useFeature = td.config.useStopLoss;
const direction = td.config.tradeDirection;

Export Parameters as JSON

If you have defined parameters in the UI and want to export them:

  1. Go to Configure Parameters step
  2. Click Copy as JSON
  3. Save the copied JSON to a file

Complete Template

{
  "rsiPeriod": {
    "type": "number",
    "default": 14,
    "min": 2,
    "max": 100,
    "step": 1,
    "label": "RSI Period",
    "description": "Number of periods for RSI calculation"
  },
  "rsiOversold": {
    "type": "number",
    "default": 30,
    "min": 0,
    "max": 50,
    "step": 1,
    "label": "RSI Oversold Level",
    "description": "RSI level considered oversold (buy signal)"
  },
  "rsiOverbought": {
    "type": "number",
    "default": 70,
    "min": 50,
    "max": 100,
    "step": 1,
    "label": "RSI Overbought Level",
    "description": "RSI level considered overbought (sell signal)"
  },
  "emaFastPeriod": {
    "type": "number",
    "default": 9,
    "min": 2,
    "max": 50,
    "label": "Fast EMA Period",
    "description": "Period for the fast exponential moving average"
  },
  "emaSlowPeriod": {
    "type": "number",
    "default": 21,
    "min": 5,
    "max": 200,
    "label": "Slow EMA Period",
    "description": "Period for the slow exponential moving average"
  },
  "tradeDirection": {
    "type": "select",
    "default": "both",
    "options": ["both", "long", "short"],
    "label": "Trade Direction",
    "description": "Which direction(s) to trade"
  },
  "useStopLoss": {
    "type": "boolean",
    "default": true,
    "label": "Use Stop Loss",
    "description": "Enable automatic stop-loss orders"
  },
  "stopLossPercent": {
    "type": "number",
    "default": 2,
    "min": 0.5,
    "max": 20,
    "step": 0.5,
    "label": "Stop Loss %",
    "description": "Stop loss distance as percentage from entry"
  },
  "takeProfitPercent": {
    "type": "number",
    "default": 4,
    "min": 1,
    "max": 50,
    "step": 0.5,
    "label": "Take Profit %",
    "description": "Take profit distance as percentage from entry"
  },
  "positionSizePercent": {
    "type": "number",
    "default": 10,
    "min": 1,
    "max": 100,
    "step": 1,
    "label": "Position Size %",
    "description": "Percentage of available balance to use per trade"
  }
}

Best Practices

Naming Conventions

{
  "rsiPeriod": { },
  "emaFastLength": { },
  "useTrailingStop": { }
}

Use camelCase for parameter names. Avoid SCREAMING_CASE or snake_case.

Sensible Defaults

{
  "rsiPeriod": {
    "type": "number",
    "default": 14,
    "min": 2,
    "max": 100,
    "step": 1,
    "label": "RSI Period"
  }
}

Always include min/max constraints for numbers to prevent invalid values.

Descriptive Labels

{
  "stopLossPercent": {
    "type": "number",
    "default": 2,
    "label": "Stop Loss %",
    "description": "Distance from entry price as percentage"
  }
}

Use clear labels and helpful descriptions.

Troubleshooting

Invalid JSON Error

Issue: "Invalid JSON" error when parsing

Solution: Validate your JSON at jsonlint.com. Common mistakes:

  • Trailing commas after the last item
  • Single quotes instead of double quotes
  • Missing quotes around keys

Parameters Not Appearing

Issue: Some parameters are missing after import

Solution: Check that each parameter has at least:

  • type (number, boolean, string, or select)
  • default value
  • label

Select Options Not Working

Issue: Dropdown shows no options

Solution: Ensure options is an array of strings:

{
  "mode": {
    "type": "select",
    "default": "auto",
    "options": ["auto", "long", "short"]
  }
}

Related Documentation