Skip to main content
Skip to main content
Version: 1.0 (Current)

Clone Algorithm

Create a copy of an existing trading algorithm with all configuration but no performance data.

Endpoint

POST /api/trading/algorithms/:id/clone

Authentication

Requires authentication via Bearer token.

Authorization: Bearer <access_token>

Request

Path Parameters

ParameterTypeRequiredDescription
idstringYesAlgorithm ID to clone

Body

{
"name": "Cloned Strategy Name"
}

Parameters:

FieldTypeRequiredDescription
namestringNoName for cloned algorithm (auto-generated if not provided)

Response

Success (201 Created)

{
"id": "507f1f77bcf86cd799439012",
"userId": "507f191e810c19729de860ea",
"name": "Cloned Strategy Name",
"status": "draft",
"active": false,
"clonedFrom": "507f1f77bcf86cd799439011",

"strategyType": "momentum",
"timeframe": "15m",
"symbols": ["NSE:RELIANCE", "NSE:TCS"],

"positionSizing": {
"method": "risk_based",
"riskPercentage": 1,
"stopLossPercentage": 2
},

"entryConditions": {
"positionType": "long",
"logicalOperator": "AND",
"conditions": [...]
},

"exitConditions": {
"stopLoss": {...},
"takeProfit": {...}
},

"riskParameters": {
"maxPositionSize": 10,
"stopLoss": 2,
"takeProfit": 6,
"maxDailyLoss": 5,
"maxOpenPositions": 3,
"riskRewardRatio": 3
},

"executionSettings": {
"mode": "paper",
"exchange": "NSE",
"orderType": "limit"
},

"performance": {
"totalTrades": 0,
"winningTrades": 0,
"losingTrades": 0,
"totalProfit": 0,
"totalLoss": 0,
"winRate": 0,
"profitFactor": 0,
"sharpeRatio": 0,
"maxDrawdown": 0,
"averageWin": 0,
"averageLoss": 0
},

"createdAt": "2024-01-15T11:00:00Z",
"updatedAt": "2024-01-15T11:00:00Z"
}

Errors

StatusCodeMessage
401UNAUTHORIZEDAuthentication required
404NOT_FOUNDAlgorithm not found
403FORBIDDENAccess denied (not your algorithm)

Examples

Clone with Custom Name

cURL:

curl -X POST https://api.x3algo.com/api/trading/algorithms/507f1f77bcf86cd799439011/clone \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "RSI Strategy - Variation 2"
}'

JavaScript:

const algorithmId = '507f1f77bcf86cd799439011'

const response = await fetch(
`https://api.x3algo.com/api/trading/algorithms/${algorithmId}/clone`,
{
method: 'POST',
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'RSI Strategy - Variation 2'
})
}
)

const cloned = await response.json()
console.log('Cloned Algorithm ID:', cloned.id)

Python:

algorithm_id = '507f1f77bcf86cd799439011'

response = requests.post(
f'https://api.x3algo.com/api/trading/algorithms/{algorithm_id}/clone',
headers={'Authorization': f'Bearer {access_token}'},
json={'name': 'RSI Strategy - Variation 2'}
)

cloned = response.json()
print('Cloned Algorithm ID:', cloned['id'])

Clone Without Name (Auto-Generated)

JavaScript:

const response = await fetch(
`https://api.x3algo.com/api/trading/algorithms/${algorithmId}/clone`,
{
method: 'POST',
headers: {
'Authorization': `Bearer ${accessToken}`
}
}
)

const cloned = await response.json()
// Name will be: "Copy of [Original Name]"
console.log('Cloned as:', cloned.name)

What Gets Cloned

Copied

  • All configuration settings
  • Strategy type and timeframe
  • Symbols
  • Position sizing configuration
  • Entry conditions
  • Exit conditions
  • Risk parameters
  • Execution settings

Not Copied

  • Performance metrics (reset to zero)
  • Trade history
  • Status (always starts as draft)
  • Active flag (always false)
  • Created/updated timestamps (new timestamps)

Use Cases

Strategy Variations

Clone an algorithm to test variations:

// Clone base strategy
const base = await getAlgorithm(baseId)
const variation1 = await cloneAlgorithm(baseId, 'RSI 30/70')
const variation2 = await cloneAlgorithm(baseId, 'RSI 20/80')

// Modify RSI thresholds
await updateAlgorithm(variation1.id, {
entryConditions: {
...base.entryConditions,
conditions: [{
...base.entryConditions.conditions[0],
value: 30
}]
}
})

await updateAlgorithm(variation2.id, {
entryConditions: {
...base.entryConditions,
conditions: [{
...base.entryConditions.conditions[0],
value: 20
}]
}
})

Multi-Symbol Testing

Clone to test same strategy on different symbols:

const symbols = [
['NSE:RELIANCE'],
['NSE:TCS'],
['NSE:INFY']
]

for (const symbolSet of symbols) {
const cloned = await cloneAlgorithm(baseId, `Strategy - ${symbolSet[0]}`)
await updateAlgorithm(cloned.id, { symbols: symbolSet })
}

Timeframe Comparison

Clone to test across different timeframes:

const timeframes = ['5m', '15m', '30m', '1h']

for (const tf of timeframes) {
const cloned = await cloneAlgorithm(baseId, `Strategy - ${tf}`)
await updateAlgorithm(cloned.id, { timeframe: tf })
}

Notes

  • Cloned algorithms start in draft status
  • You can modify the clone immediately after creation
  • The clonedFrom field tracks the original algorithm
  • Clones are independent - changes don't affect the original
  • No limit on number of clones