Custom Strategies Overview

Custom strategies allow you to write JavaScript-based trading algorithms that execute automatically on the TradeStaq platform using the TradeStaq engine.

What are Custom Strategies?

Custom strategies are JavaScript code snippets that:

  • Execute in a secure, isolated sandbox environment
  • Have access to market data, technical indicators, and trade execution
  • Run periodically based on your configured interval
  • Maintain state across executions

Who Can Create Strategies?

User TypeCapabilities
All UsersCreate and use custom strategies; use marketplace strategies
Trader & WhaleAlso publish strategies to the marketplace
WhaleHighest limits — unlimited builder strategies & AI
AdminsFull create/edit access to all strategies

Strategy Execution Model

Your strategy runs automatically at regular intervals. Each execution:

  1. Receives the latest market data and indicators
  2. Runs your strategy code
  3. Processes any trading signals you generate
  4. Saves state for the next execution

Execution Frequency by Plan

PlanMinimum Interval
Free2 minutes
Pro2 minutes
Trader30 seconds
Whale10 seconds

Security & Limits

For security and fair resource usage, strategies run with these constraints:

ConstraintDescription
MemoryLimited per execution
Execution TimeMust complete within time limit
SignalsLimited number of trades per execution
LoggingLimited log entries per execution
Code SizeMaximum strategy file size

For security, strategies cannot:

  • Make external network requests
  • Access the file system
  • Use eval() or dynamic code
  • Access system APIs

The td Object

All strategies interact with the platform through the global td object:

td.market      // Current market data
td.indicators  // Technical indicators
td.position    // Current position info
td.account     // Account information
td.orders      // Order history
td.trade       // Trade execution functions
td.state       // Persistent state storage
td.config      // Strategy configuration
td.utils       // Utility functions
td.meta        // Metadata about the bot/strategy

Basic Strategy Example

// Simple RSI Strategy
const rsi = td.indicators.rsi;

// Buy when RSI is oversold
if (rsi < 30 && !td.position.hasPosition) {
    td.trade.buy({
        amountPercent: 100,
        stopLoss: td.market.price * 0.98,
        reason: 'RSI oversold'
    });
}

// Sell when RSI is overbought
if (rsi > 70 && td.position.hasPosition) {
    td.trade.close('RSI overbought');
}

// Log current state
td.utils.log('Strategy tick', {
    rsi: rsi.toFixed(2),
    price: td.market.price,
    hasPosition: td.position.hasPosition
});

Strategy Categories

Official Strategies

Built and maintained by the TradeStaq team. Thoroughly tested and optimized for various market conditions.

Community Strategies

Created by users and shared on the marketplace. Quality varies - always backtest before using.

Premium Strategies

Paid strategies with advanced features. May offer better performance or unique approaches.

Next Steps

Related Guides