MagicTradeBot 5.2+ Position Sizing Engine – Complete User Guide
MagicTradeBot 5.2+ introduces a fully redesigned Position Sizing Engine, separating capital allocation from trading and DCA logic for improved clarity, flexibility, and risk control.
This update centralizes all trade size calculations into:
position_sizing.yaml ๐ What Changed in Version 5.2+
โ 1. New Dedicated Configuration File
All trade amount and exposure logic has been moved to:
position_sizing.yaml This ensures:
- Cleaner architecture
- No overlap between DCA and capital logic
- Better simulation accuracy
- Future support for advanced sizing models (Kelly, risk-of-ruin, volatility-based, etc.)
โ 2. Replaced Old Settings
The following settings are now deprecated:
| Old Setting | Status |
|---|---|
CalculateAmountDynamically | โ Removed |
TradeAmountPer | โ Removed |
These are now fully replaced by:
auto_calculate_initial_amount: true โ
3. initial_trade_amount Moved
Previously located in trading.yaml, it has now been moved to:
position_sizing.yaml This ensures all position size logic lives in one place.
๐ New Configuration Structure
# --------------------------------------------------------------------------
# Trade Amount & Capital Allocation
# --------------------------------------------------------------------------
initial_trade_amount: 10.0
# --------------------------------------------------------------------------
# Position Size Calculation
# --------------------------------------------------------------------------
auto_calculate_initial_amount: true
balance: 5000
total_percent_investment_per_trade: 2.0
# --------------------------------------------------------------------------
# Advanced Sizing Features
# --------------------------------------------------------------------------
mode: percent
kelly_fraction: 0.5
target_risk_of_ruin_percent: 1.0
max_drawdown_threshold: 40.0
โ๏ธ How Position Sizing Works (Logic Flow)
1๏ธโฃ Fixed Mode
If:
auto_calculate_initial_amount: false Then the bot:
- Uses
initial_trade_amount - Performs no exposure calculation
- Skips DCA math
- Skips percentage logic
โ Ideal for fixed-lot traders
โ Simple & predictable
2๏ธโฃ Auto Calculation Mode
If:
auto_calculate_initial_amount: true Then:
- Initial amount is calculated dynamically from balance
- Total exposure (Initial + All DCA + Grid DCA) is capped by:
total_percent_investment_per_trade 3๏ธโฃ Advanced Modes
Kelly Criterion
- Uses historical win rate and average PnL per trade
- Fraction of Kelly can be applied via kelly_fraction
- Reduces volatility while maintaining growth potential
Risk-of-Ruin
- Calculates maximum position size to maintain a safe probability of account ruin
- Controlled by target_risk_of_ruin_percent
- Enforces max_drawdown_threshold to prevent catastrophic losses
- Ideal for long-term risk management
๐งฎ Exposure Calculation Rules
Case A โ DCA Disabled + Grid Disabled
If both are disabled, the bot simply uses:
10% of balance (No geometric math applied.)
Case B โ DCA Enabled
The system calculates:
- Geometric series for all DCA orders
- Multiplier-based exposure
- Total units
Capital is then distributed proportionally.
Case C โ Grid DCA Enabled
Grid exposure is added as additional units:
grid_orders ร order_percent These units are included in total exposure calculation.
Case D โ DCA + Grid Combined
Both exposure models are merged into a single total exposure cap:
Total Exposure โค total_percent_investment_per_trade % of balance The initial amount is derived from:
target_total_investment / total_units ๐ฐ Balance Behavior
Live Mode
If:
balance: 0 The bot uses the real exchange balance.
Demo Mode
If:
balance: 5000 The bot uses:
balance ยฑ total_pnl This ensures accurate compounding simulation.
๐ฏ total_percent_investment_per_trade Explained
This defines the maximum total capital exposure per trade, including:
- Initial entry
- All DCA orders
- All Grid DCA orders
Examples
| Value | Behavior |
|---|---|
| 2.0 | Conservative |
| 5.0 | Balanced |
| 10.0 | Aggressive |
๐ฅ Example Scenario
Balance = 5000
total_percent_investment_per_trade = 2%
Maximum allowed exposure:
5000 ร 2% = 100 USDT The bot will calculate initial order size such that:
Initial + All DCA + Grid Orders = 100 USDT Never exceeding that limit.
๐๏ธ Why This Architecture Is Better
- โ Cleaner separation of concerns
- โ No capital logic inside DCA module
- โ Deterministic risk control
- โ Compatible with AI optimization
- โ Simulation matches live behavior
- โ Future-proof for Kelly / Risk-of-Ruin sizing
โ ๏ธ Migration Checklist (From 5.1.x)
- Remove:
CalculateAmountDynamicallyTradeAmountPer
- Move:
initial_trade_amountโposition_sizing.yaml
- Move:
balanceauto_calculate_initial_amounttotal_percent_investment_per_trademodekelly_fractiontarget_risk_of_ruin_percentmax_drawdown_threshold
- Verify:
- DCA settings remain inside
dca.yaml - Trading execution remains inside
trading.yaml
- DCA settings remain inside
๐ Recommended Setup Profiles
๐ก Conservative
auto_calculate_initial_amount: true
total_percent_investment_per_trade: 2.0
mode: percent โ Balanced
auto_calculate_initial_amount: true
total_percent_investment_per_trade: 5.0
mode: percent ๐ Aggressive
auto_calculate_initial_amount: true
total_percent_investment_per_trade: 10.0
mode: percent ๐ง Advanced Users
Version 5.2+ lays the foundation for:
- Kelly Criterion sizing
- Risk-of-Ruin targeting
- Volatility-based sizing
- Strategy-level capital buckets
- AI-optimized exposure
All future models will integrate into position_sizing.yaml.
โ Summary
MagicTradeBot 5.2+ introduces:
- A dedicated Position Sizing Engine
- Removal of legacy dynamic sizing options
- Centralized capital control
- Deterministic total exposure cap
- Advanced sizing modes: Kelly & Risk-of-Ruin
- Automatic Money Management module disable in auto mode
This upgrade significantly improves risk control, clarity, and long-term scalability.