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 Type | Capabilities |
|---|---|
| All Users | Create and use custom strategies; use marketplace strategies |
| Trader & Whale | Also publish strategies to the marketplace |
| Whale | Highest limits — unlimited builder strategies & AI |
| Admins | Full create/edit access to all strategies |
Strategy Execution Model
Your strategy runs automatically at regular intervals. Each execution:
- Receives the latest market data and indicators
- Runs your strategy code
- Processes any trading signals you generate
- Saves state for the next execution
Execution Frequency by Plan
| Plan | Minimum Interval |
|---|---|
| Free | 2 minutes |
| Pro | 2 minutes |
| Trader | 30 seconds |
| Whale | 10 seconds |
Security & Limits
For security and fair resource usage, strategies run with these constraints:
| Constraint | Description |
|---|---|
| Memory | Limited per execution |
| Execution Time | Must complete within time limit |
| Signals | Limited number of trades per execution |
| Logging | Limited log entries per execution |
| Code Size | Maximum 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
- Getting Started - Create your first strategy
- TD API Reference - Complete API documentation
- Indicators Guide - Available technical indicators
- Examples - Sample strategy implementations
Related Guides
- AI Strategy Builder — create strategies with natural language
- Backtesting — validate your strategy before deploying
- TD API Reference — full indicator and trading API
- Strategy Examples — learn from working examples
- Publishing Strategies — share your strategy on the marketplace