13. Capital Management & Position Sizing
Capital Modes (ENUM_CAPITAL_MODE)
| Mode | Description |
|---|---|
CAPITAL_COMPOUND_AUTO | Base = account balance (automatic) |
CAPITAL_FIXED_MANUAL | Base = Inp_Fixed_Capital_Amount (fixed) |
CAPITAL_COMPOUND_AUTO + Inp_Compound_Enable=true | Base = Fixed + g_CompoundBuffer (from TXT file) |
Position Sizing Algorithm (CalculatePositionSize)
1. base_capital = [depending on mode]
2. budget = base_capital × MaxTotalMarginPercent / 100
3. risk_money = budget × Risk_Percent_Per_Trade / 100
4. sl_ticks = (Hard_SL_Points × _Point) / tick_size
5. loss_for_one_lot = sl_ticks × tick_value
6. target_lots = risk_money / loss_for_one_lot
→ First position: target_lots / Pyramid_Multiplier (probe — smaller)
→ Subsequent position: last_volume × Pyramid_Multiplier (main — larger)
7. Round to broker's volume step
8. Enforce broker's min/max volume
9. Check hard cap: Max_Lots
10. Margin check: OrderCalcMargin → if budget exceeded → abort
Compound Buffer
g_CompoundBuffer is read from an external TXT file. Allows percentage-based growth of the capital base at configurable intervals: Daily / Weekly / Monthly. Enables a compound interest effect on a locked base without changing EA settings.
