Getting Started
This guide introduces the algorithm builder and the workflow for creating a first trading algorithm.
What is the Algorithm Builder?​
The x3Algo Algorithm Builder organizes strategy rules, backtesting, risk settings, and execution settings into a structured configuration workflow.
The 5-Step Algorithm Creation Process​
Creating a trading algorithm in x3Algo follows a simple 5-step process:
graph LR
A[1. Basic Info] --> B[2. Position Sizing]
B --> C[3. Entry Conditions]
C --> D[4. Exit Conditions]
D --> E[5. Risk Parameters]
E --> F[Complete & Deploy]
Step 1: Basic Information​
Define your strategy's foundation:
- Strategy Type: Choose from scalping, swing, position, momentum, mean reversion, arbitrage, or market making
- Timeframe: Select execution frequency (1m, 5m, 15m, 30m, 1h, 4h, 1d, 1w)
- Trading Symbols: Specify which instruments to trade (e.g., NSE:RELIANCE, MCX:CRUDEOIL)
- Name & Description: Give your algorithm a meaningful name
Step 2: Position Sizing​
Determine how much capital to allocate per trade:
- Percentage-based: Risk a fixed percentage of your capital (1-5% recommended)
- Fixed quantity: Trade a consistent number of shares/contracts
- Risk-based: Calculate position size based on stop loss distance
- Volatility-adjusted: Use ATR to adapt to market conditions
- Kelly Criterion: Optimize position size based on win rate and profit factor
Step 3: Entry Conditions​
Define when to open positions:
- Indicator comparisons: Use technical indicators (SMA, EMA, RSI, MACD, Bollinger Bands)
- Price patterns: Detect candlestick patterns (hammer, engulfing, doji)
- Logical operators: Combine multiple conditions with AND/OR logic
- Confirmation candles: Wait for signal confirmation (0-10 candles)
- Time filters: Trade only during specific hours or days
Step 4: Exit Conditions​
Protect profits and limit losses:
- Stop Loss: Fixed, percentage, ATR-based, or indicator-based
- Take Profit: Fixed, percentage, risk-reward ratio, or multiple targets
- Trailing Stops: Lock in profits as price moves in your favor
- Partial Exits: Scale out at different profit levels
- Time-based exits: Close positions after a maximum hold time
Step 5: Risk Parameters​
Set portfolio-level risk controls:
- Maximum position size: Limit exposure per trade (2-10% of capital)
- Daily loss limit: Circuit breaker to pause trading after losses (1-5% of account)
- Maximum open positions: Control how many trades run simultaneously (3-10)
- Risk-reward ratio: Ensure favorable profit potential (minimum 1:2)
Algorithm Lifecycle States​
Your algorithm moves through different states during its lifecycle:
stateDiagram-v2
[*] --> Draft: Create
Draft --> Stopped: Complete
Stopped --> Active: Start
Active --> Paused: Pause
Paused --> Active: Resume
Active --> Stopped: Stop
Stopped --> Archived: Archive
Active --> Error: Error
Error --> Stopped: Fix & Restart
State Descriptions​
- Draft: Algorithm is being configured, validation is relaxed
- Stopped: Configuration is complete but algorithm is not running
- Active: Algorithm is running and can generate signals
- Paused: Temporarily suspended, can be resumed quickly
- Error: Encountered an issue, requires attention
- Archived: Soft-deleted, preserved for historical reference
Complete Working Example​
Here's a simple moving average crossover strategy you can copy and test immediately:
{
"name": "Simple MA Crossover",
"description": "Buy when fast MA crosses above slow MA, sell on opposite",
"strategyType": "momentum",
"timeframe": "15m",
"symbols": ["NSE:RELIANCE"],
"positionSizing": {
"method": "percentage",
"percentage": 2
},
"entryConditions": {
"positionType": "both",
"logicalOperator": "AND",
"conditions": [
{
"type": "indicator_indicator",
"indicator1": "SMA",
"period1": 20,
"indicator2": "SMA",
"period2": 50,
"operator": "crosses_above"
}
]
},
"exitConditions": {
"stopLoss": {
"type": "percentage",
"percentage": 2
},
"takeProfit": {
"type": "risk_reward",
"ratio": 2
}
},
"riskParameters": {
"maxPositionSize": 10,
"maxDailyLoss": 5,
"maxOpenPositions": 3
}
}
Glossary of Key Terms​
- Algorithm: A set of rules that automatically executes trades based on market conditions
- Backtesting: Testing a strategy against historical data to evaluate performance
- Paper Trading: Simulated trading with real market data but no real money
- Live Trading: Executing real trades with actual capital through broker integration
- Position Sizing: Method for determining how much capital to allocate per trade
- Entry Condition: Rule that must be satisfied to open a new position
- Exit Condition: Rule that triggers closing an open position
- Stop Loss: Automatic exit to limit losses if price moves against you
- Take Profit: Automatic exit to lock in gains at a target price
- Trailing Stop: Stop loss that moves with price to protect profits
- Risk-Reward Ratio: Relationship between potential profit and potential loss (e.g., 1:2 means risk $1 to make $2)
- Drawdown: Peak-to-trough decline in account value
- Win Rate: Percentage of profitable trades
- Profit Factor: Ratio of gross profit to gross loss (>1.5 is good)
Next Steps​
Now that you understand the basics, choose your learning path:
For Beginners​
- Build Your First Algorithm in 10 Minutes - Step-by-step guide for complete beginners
- Backtesting Basics - Learn to validate your strategy
- Paper to Live Trading Transition - Go live safely
For Intermediate Traders​
- EMA Crossover Strategy - Build a trend-following system
- RSI Divergence Strategy - Implement reversal detection
- Multi-Timeframe Strategy - Add higher timeframe confirmation
For Advanced Users​
- Strategy Optimization Walkthrough - Optimize parameters and avoid overfitting
- How-To Guides - Task-oriented guides for specific features
- API Reference - Programmatic algorithm management
Getting Help​
- Documentation: Browse How-To Guides for specific tasks
- Troubleshooting: Check common issues and solutions
- Support: Email contact@x3algo.com for assistance
Ready to build your first algorithm? Let's get started with the 10-minute tutorial!