# Advanced Risk Management

## Intelligent Position Sizing

BananaEA includes sophisticated **multi-method risk management** systems that automatically calculate optimal lot sizes based on your chosen risk profile.

***

## Risk Calculation Methods

### **Method 1: Risk by Percentage**

**Concept:** Risk a fixed percentage of account balance per trade

```
Example:
Account Balance = $10,000
Risk Percentage = 2%
Stop Loss = 50 pips

Calculation:
Risk Amount = $10,000 × 2% = $200
Lot Size = $200 ÷ (50 pips × pip value) = Auto-calculated
```

**Benefits:**

* Proportional risk management
* Account growth scales position sizes automatically
* Professional money management standard

**Best For:** Most traders, long-term growth strategies

### **Method 2: Risk by Fixed Amount**

**Concept:** Risk the same dollar amount per trade regardless of account size

```
Example:
Account Balance = $10,000
Risk Amount = $100
Stop Loss = 50 pips

Calculation:
Lot Size = $100 ÷ (50 pips × pip value) = Auto-calculated
```

**Benefits:**

* Predictable risk per trade
* Simple to understand
* Controlled drawdown progression

**Best For:** Conservative traders, small account protection

### **Method 3: Fixed Lot Size**

**Concept:** Trade the same lot size every time

```
Example:
Fixed Lot Size = 0.10
(No calculations, uses specified lot size)
```

**Benefits:**

* Maximum control
* Consistent position sizing
* Simplified backtesting

**Best For:** Experienced traders with specific strategies

***

## Spread Protection System

### **The Spread Problem**

**Traditional EAs:**

```
Signal detected at price X
Place order at price X
❌ Order rejected: spread not accounted for
```

**BananaEA Smart System:**

```
Signal detected at price X
Calculate current spread
Adjust entry price for spread
✅ Order accepted successfully
```

### **Technical Implementation**

```mql4
// Automatic spread calculation
double currentSpread = (Ask - Bid);

// BUY orders: Add spread to entry price
double entryPriceBuy = signalHigh + BuyBuffer + currentSpread;

// SELL orders: No spread adjustment needed
double entryPriceSell = signalLow - SellBuffer;
```

**Result:** **95-99% order acceptance rate** vs 60-80% without spread protection

***

## Multi-Trade Coordination

### **Position Limits**

BananaEA intelligently manages multiple simultaneous positions:

**MaxOpenTrades Parameter:**

```
MaxOpenTrades = 1   // Conservative (single position)
MaxOpenTrades = 3   // Balanced (moderate exposure)
MaxOpenTrades = 5   // Aggressive (higher diversification)
MaxOpenTrades = 10  // Very aggressive (maximum opportunities)
```

### **Scaling Control**

**AllowMultipleTrades Parameter:**

```
AllowMultipleTrades = false
→ Max 1 trade per direction (BUY or SELL)
→ Simple position management
→ Clear risk profile

AllowMultipleTrades = true
→ Multiple trades per direction up to MaxOpenTrades
→ Scaling-in capability
→ Diversified entry points
```

### **Smart Trade Counting**

**Critical Implementation:**

The EA counts **ALL open trades (BUY + SELL combined)** toward the MaxOpenTrades limit:

```mql4
int totalTrades = 0;
for(int i = OrdersTotal() - 1; i >= 0; i--) {
    if(OrderSelect(i, SELECT_BY_POS) && OrderMagicNumber() == Magic)
        totalTrades++;  // Count both BUY and SELL
}

if(totalTrades >= MaxOpenTrades) {
    // No new trades allowed
    return;
}
```

**Example:**

```
MaxOpenTrades = 3
Current: 2 BUY trades + 1 SELL trade = 3 total
New signal: Rejected (limit reached) ✅
```

***

## Dynamic Stop Loss Methods

BananaEA supports **three intelligent SL calculation methods**:

### **Method 1: Candle Range SL**

**Concept:** Base stop loss on the range of recent candles

```
Configuration:
SLMethod = CandleRange
CandleRangeSL = 10  // Look back 10 candles

Calculation:
Highest High (10 candles) - Lowest Low (10 candles) = Range
Stop Loss = Range (in pips)
```

**Benefits:**

* Adapts to market volatility
* Wider stops in volatile markets
* Tighter stops in calm markets

### **Method 2: ATR-Based SL**

**Concept:** Use Average True Range indicator for dynamic stops

```
Configuration:
SLMethod = ATR
ATR_SL_Multiplier = 2.0

Calculation:
ATR(14) = Current volatility measure
Stop Loss = ATR × 2.0 multiplier
```

**Benefits:**

* Professional volatility-adjusted stops
* Accounts for current market conditions
* Reduces stop-out frequency

### **Method 3: Fixed Pips SL**

**Concept:** Use the same stop loss distance every trade

```
Configuration:
SLMethod = Fixed
FixedSL = 50.0  // 50 pips

Calculation:
Stop Loss = 50 pips (always)
```

**Benefits:**

* Predictable risk per trade
* Simple backtesting
* Consistent R:R ratios

***

## Dynamic Take Profit Methods

**Mirrors stop loss flexibility** with three intelligent TP calculation methods:

### **Method 1: Candle Range TP**

```
Configuration:
TPMethod = CandleRange
CandleRangeTP = 20  // Look back 20 candles

Calculation:
Range = Highest High - Lowest Low (20 candles)
Take Profit = Range × multiplier
```

### **Method 2: ATR-Based TP**

```
Configuration:
TPMethod = ATR
ATR_TP_Multiplier = 3.0

Calculation:
Take Profit = ATR(14) × 3.0
```

**Example Risk-Reward:**

```
ATR_SL_Multiplier = 2.0  (Stop Loss)
ATR_TP_Multiplier = 6.0  (Take Profit)
→ Risk-Reward Ratio = 1:3 ✅
```

### **Method 3: Fixed Pips TP**

```
Configuration:
TPMethod = Fixed
FixedTP = 100.0  // 100 pips

Calculation:
Take Profit = 100 pips (always)
```

***

## Break-Even Protection

### **Automatic Break-Even Trigger**

**Configuration:**

```
UseBreakEven = true
BreakEvenPips = 20.0     // Trigger at +20 pips profit
BreakEvenPlusPips = 5.0  // Move SL to entry + 5 pips
```

**How It Works:**

```
Trade Entry: 1.1000
Initial Stop Loss: 1.0950 (-50 pips)

Price reaches 1.1020 (+20 pips profit)
→ Break-even triggers
→ Move Stop Loss to 1.1005 (entry + 5 pips)
→ Guaranteed minimum profit if price reverses ✅
```

**Benefits:**

* Protects profits
* Eliminates losing trades after breakeven
* Psychological comfort for traders

***

## Partial Close Strategy

### **Lock in Profits Early**

**Configuration:**

```
UsePartialClose = true
PartialClosePips = 30.0       // Close portion at +30 pips
PartialClosePercent = 50.0    // Close 50% of position
```

**Example:**

```
Position: 0.10 lots BUY at 1.1000
Initial TP: 1.1100 (+100 pips)

Price reaches 1.1030 (+30 pips)
→ Partial close triggers
→ Close 0.05 lots at 1.1030 (50% profit locked)
→ Remaining 0.05 lots run to 1.1100 TP
```

**Benefits:**

* Guaranteed profits
* Reduces emotional trading
* Balances risk and reward

***

## Risk Management Best Practices

### **1. Start Conservative**

```
RiskPercent = 1.0 - 2.0       // Conservative risk
MaxOpenTrades = 1 - 3         // Limited exposure
AllowMultipleTrades = false   // Simple management
```

### **2. Use Dynamic Methods**

```
SLMethod = ATR                 // Volatility-adjusted
TPMethod = ATR                 // Matching method
ATR_SL_Multiplier = 2.0       // 2x ATR stop
ATR_TP_Multiplier = 4.0       // 1:2 R:R ratio
```

### **3. Enable Protection Features**

```
UseBreakEven = true           // Protect profits
BreakEvenPips = 15.0         // Early trigger
UsePartialClose = true        // Lock gains
PartialClosePercent = 50.0    // Half position
```

### **4. Match Risk to Account Size**

```
Small Account ($500 - $2,000):
→ RiskAmount = $10 - $50 (fixed amount safer)

Medium Account ($2,000 - $10,000):
→ RiskPercent = 1.0 - 2.0%

Large Account ($10,000+):
→ RiskPercent = 0.5 - 2.0%
```

***

## Advanced Risk Scenarios

### **Portfolio Management**

Running multiple instances:

```
Instance 1 (Conservative):
Magic = 12345
RiskPercent = 1.0
MaxOpenTrades = 1

Instance 2 (Aggressive):
Magic = 12346
RiskPercent = 2.0
MaxOpenTrades = 5

Total Portfolio Risk: 3% maximum ✅
```

### **Prop Firm Compliance**

GetFunded challenge rules:

```
Daily Loss Limit = 5%
→ RiskPercent = 1.0 - 1.5%
→ MaxOpenTrades = 3 - 5
→ MaxDailyTrades = 10

Max Trailing Drawdown = 10%
→ Monitor cumulative risk
→ Reduce RiskPercent if approaching limit
```

***

## Common Questions

### **"What's the optimal risk percentage?"**

**Standard recommendation:**

* **Conservative:** 0.5 - 1.0% per trade
* **Balanced:** 1.0 - 2.0% per trade
* **Aggressive:** 2.0 - 3.0% per trade

### **"Should I use ATR or Fixed SL/TP?"**

**ATR Methods:** Better for adapting to changing market conditions\
**Fixed Methods:** Better for consistent backtesting and predictable risk

**Recommendation:** Start with ATR, switch to Fixed if results are inconsistent

### **"How do I calculate pip value for my broker?"**

The EA automatically calculates pip value based on:

* Symbol specification
* Lot size
* Account currency

**No manual calculation needed** ✅

***

**Advanced Risk Management ensures your trading capital is protected** while maximizing profit potential through intelligent automation.

**Next:**

* [Enhanced Signal Processing →](https://itradeaims.gitbook.io/banana-ea/smart-features/overview/signal-processing)
* [Smart Trailing Stop →](https://itradeaims.gitbook.io/banana-ea/smart-features/overview/smart-trailing-stop)
* [Complete Settings Guide →](https://github.com/itradeaims/bananaEA-dev/blob/dev/gitbook/smart-features/broken-reference/README.md)
