Pyramiding (Position Scaling)

14. Pyramiding (Position Scaling)

Inp_Pyramid_Multiplier     = 3.0   // Scale multiplier (probe → main)
Inp_Pyramid_Max_Lots       = 2.0   // Hard cap: max lots for any single position
Inp_Pyramid_OnlyProfitable = true  // Pyramid only if last position is in profit

Logic:

  • No open positions: lots = target_lots / 3.0 — a small probe is opened (1/3 of normal)
  • Position exists: lots = last_volume × 3.0 — scaling up to full size
  • If OnlyProfitable = true and the last position is in loss → pyramid is blocked

Log: "Pyramid blocked: last position not in profit." / "LOT CAP: 4.50 -> 2.00"

Capital Management & Position Sizing

13. Capital Management & Position Sizing

Capital Modes (ENUM_CAPITAL_MODE)

ModeDescription
CAPITAL_COMPOUND_AUTOBase = account balance (automatic)
CAPITAL_FIXED_MANUALBase = Inp_Fixed_Capital_Amount (fixed)
CAPITAL_COMPOUND_AUTO + Inp_Compound_Enable=trueBase = 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.

Zarządzanie kapitałem i wielkością pozycji

13. Zarządzanie kapitałem i wielkością pozycji

Tryby kapitału (ENUM_CAPITAL_MODE)

TrybOpis
CAPITAL_COMPOUND_AUTOBaza = saldo konta (auto)
CAPITAL_FIXED_MANUALBaza = Inp_Fixed_Capital_Amount (stała)
CAPITAL_COMPOUND_AUTO + Inp_Compound_Enable=trueBaza = Fixed + g_CompoundBuffer (plik TXT)

Algorytm kalkulacji wielkości pozycji (CalculatePositionSize)

1. base_capital = [zależnie od trybu]
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

→ Pierwsza pozycja: target_lots / Pyramid_Multiplier  (sonda, mniejsza)
→ Kolejna pozycja:  last_volume × Pyramid_Multiplier  (główna, większa)

7. Zaokrąglenie do kroku wolumenu brokera
8. Wymuszenie min/max wolumenu brokera
9. Sprawdzenie hard cap: Max_Lots
10. Sprawdzenie marginu: OrderCalcMargin → jeśli przekracza budżet → abort

Compound Buffer

g_CompoundBuffer jest odczytywany z zewnętrznego pliku TXT. Pozwala na procentowy przyrost bazy kapitałowej z interwałem: Dziennym / Tygodniowym / Miesięcznym. Umożliwia efekt procentu składanego na zablokowanej bazie bez zmiany ustawień EA.