MagicTradeBot 5.2+ Position Sizing Engine – Complete User Guide

  • Home
  • Documentation
  • 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)

  1. Remove:
    • CalculateAmountDynamically
    • TradeAmountPer
  2. Move:
    • initial_trade_amountposition_sizing.yaml
  3. Move:
    • balance
    • auto_calculate_initial_amount
    • total_percent_investment_per_trade
    • mode
    • kelly_fraction
    • target_risk_of_ruin_percent
    • max_drawdown_threshold
  4. Verify:
    • DCA settings remain inside dca.yaml
    • Trading execution remains inside trading.yaml

📌 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.

📎 Related Topics