| name | strategy |
| description | Build and manage custom trading strategies with natural language |
| emoji | 🎯 |
Strategy - Complete API Reference
Create custom trading strategies using natural language or templates, then deploy to live trading.
Chat Commands
Create Strategy
/strategy create "Buy when price drops 5% in 1 hour"
/strategy create momentum --lookback 14 --threshold 2%
/strategy from-template mean-reversion
Manage Strategies
/strategies List all strategies
/strategy <name> View strategy details
/strategy edit <name> Modify strategy
/strategy delete <name> Remove strategy
Activate/Deactivate
/strategy activate <name> Start running strategy
/strategy deactivate <name> Stop strategy
/strategy pause <name> Pause temporarily
/strategy resume <name> Resume paused strategy
Test & Validate
/strategy test <name> --dry-run Test without real trades
/strategy backtest <name> Run backtest
/strategy validate <name> Check for errors
TypeScript API Reference
Create Strategy Builder
import { createStrategyBuilder } from 'clodds/strategy';
const builder = createStrategyBuilder({
requireDryRun: true,
validateParameters: true,
storage: 'sqlite',
dbPath: './strategies.db',
});
Natural Language Strategy
const strategy = await builder.fromNaturalLanguage({
description: `
Buy YES on any market when:
- Price drops more than 5% in the last hour
- Volume is above average
- Spread is less than 2%
Sell when:
- Price recovers 3% from entry
- Or after 24 hours (timeout)
Risk: Max 5% of portfolio per trade
`,
name: 'dip-buyer',
});
console.log(`Created: ${strategy.name}`);
console.log(`Conditions: ${strategy.conditions.length}`);
Template-Based Strategy
const momentum = await builder.fromTemplate('momentum', {
lookbackPeriod: 14,
entryThreshold: 0.02,
exitThreshold: 0.01,
stopLoss: 0.05,
takeProfit: 0.10,
maxPositionPct: 10,
});
const meanReversion = await builder.fromTemplate('mean-reversion', {
lookbackPeriod: 20,
deviationThreshold: 2,
exitOnMean: true,
stopLoss: 0.08,
});
const arbitrage = await builder.fromTemplate('arbitrage', {
minSpread: 0.02,
platforms: ['polymarket', 'kalshi'],
maxSlippage: 0.01,
});
const breakout = await builder.fromTemplate('breakout', {
rangePeriod: '7d',
breakoutThreshold: 0.05,
: ,
});
Custom Strategy Code
const custom = await builder.create({
name: 'my-custom-strategy',
description: 'Buy low-priced markets with high volume',
entryConditions: [
{ type: 'price', operator: '<', value: 0.30 },
{ type: 'volume24h', operator: '>', value: 50000 },
{ type: 'spread', operator: '<', value: 0.02 },
],
exitConditions: [
{ type: 'profit', operator: '>=', value: 0.15 },
{ type: 'loss', operator: '>=', value: 0.10 },
{ type: 'holdTime', operator: '>=', value: '48h' },
],
risk: {
maxPositionPct: 5,
stopLoss: 0.10,
: ,
: ,
},
: {
: ,
: ,
: ,
},
});
Validate Strategy
const validation = await builder.validate(strategy);
if (validation.valid) {
console.log('✅ Strategy is valid');
} else {
console.log('❌ Validation errors:');
for (const error of validation.errors) {
console.log(` - ${error}`);
}
}
for (const warning of validation.warnings) {
console.log(`⚠️ ${warning}`);
}
Activate Strategy
await builder.activate(strategy.name, {
dryRun: true,
notifyOnTrade: true,
});
await builder.activate(strategy.name, {
dryRun: false,
capital: 5000,
});
Monitor Strategy
const status = await builder.getStatus(strategy.name);
console.log(`Status: ${status.status}`);
console.log(`Trades: ${status.trades}`);
console.log(`P&L: $${status.pnl}`);
console.log(`Win Rate: ${status.winRate}%`);
console.log(`Active Positions: ${status.activePositions}`);
console.log(`Last Signal: ${status.lastSignal}`);
List Strategies
const strategies = await builder.list();
for (const s of strategies) {
console.log(`${s.name}: ${s.status}`);
console.log(` Type: ${s.template || 'custom'}`);
console.log(` P&L: $${s.pnl}`);
console.log(` Trades: ${s.trades}`);
}
Built-in Templates
| Template | Description |
|---|
momentum | Follow price trends |
mean-reversion | Buy dips, sell rallies |
arbitrage | Cross-platform spreads |
breakout | Range breakout entries |
pairs | Correlated market pairs |
news-reactive | React to news events |
volume-spike | Trade on volume surges |
Condition Types
| Type | Description | Example |
|---|
price | Current price | < 0.30 |
volume24h | 24h volume | > 50000 |
spread | Bid-ask spread | < 0.02 |
profit | Unrealized profit | >= 0.15 |
loss | Unrealized loss | >= 0.10 |
holdTime | Time in position | >= 48h |
priceChange | Price change % | < -0.05 (5% drop) |
Best Practices
- Always dry-run first — Test before real money
- Start small — Low capital until proven
- Set stop-losses — Protect against bad trades
- Monitor actively — Check strategy performance
- Iterate — Improve based on results