# Order Management & Validation Guide

### 📋 Overview

RedFox Copier Pro includes sophisticated order management to prevent duplicates, validate orders before execution, and enforce risk limits. This ensures clean, controlled trading without manual intervention.

**Key Features:**

* Duplicate order prevention (same symbol/direction)
* Order validation (SL/TP/lot size checks)
* Position limits (max orders per symbol/total)
* Pending order management
* Risk exposure limits

***

### 🔒 Duplicate Prevention

#### **1. AllowDuplicateOrders**

```
AllowDuplicateOrders = true | false
```

**Controls whether multiple orders on same symbol/direction are allowed.**

***

#### **false** (Recommended - Default)

**Behavior:** Blocks new orders if existing order on same symbol + direction exists.

**Example:**

```
Current Orders:
- EURUSD BUY @ 1.0850 (open)

New Signal: EURUSD BUY @ 1.0860
Result: ⚠️ Blocked
EA Logs: "Duplicate order detected - EURUSD BUY already exists"
```

**When to use:**

* Signal provider sends same signal multiple times
* Prevent over-exposure on one symbol/direction
* Clean trading with one position per direction

**Pros:**

* ✅ Prevents accidental duplicate positions
* ✅ Controls risk exposure
* ✅ Cleaner order management

**Cons:**

* ❌ Can't add to winning positions (pyramiding)
* ❌ Misses additional signals on same direction

***

#### **true** (Allow Duplicates)

**Behavior:** Opens every signal regardless of existing orders.

**Example:**

```
Current Orders:
- EURUSD BUY @ 1.0850 (open)

New Signal: EURUSD BUY @ 1.0860
Result: ✅ Opens new order
Now have: 2 EURUSD BUY orders
```

**When to use:**

* Pyramiding strategy (add to winners)
* Layer orders feature enabled
* Signal provider rarely duplicates

**Warning:** Can lead to over-exposure if not controlled with position limits!

***

### 📊 Position Limits

#### **2. MaxOrdersPerSymbol**

```
MaxOrdersPerSymbol = 0  // 0 = unlimited, >0 = max orders per symbol
```

**Controls maximum orders on each symbol (both directions combined).**

**Example with MaxOrdersPerSymbol = 2:**

```
Current Orders:
- GBPUSD BUY @ 1.2700
- GBPUSD SELL @ 1.2750

New Signal: GBPUSD BUY @ 1.2680
Result: ⚠️ Blocked
EA Logs: "Max orders per symbol reached (2/2) - GBPUSD"
```

**Configuration Examples:**

**Conservative (1 order):**

```
MaxOrdersPerSymbol = 1
AllowDuplicateOrders = false
// Result: Only 1 position per symbol (BUY or SELL)
```

**Moderate (3 orders):**

```
MaxOrdersPerSymbol = 3
AllowDuplicateOrders = true
// Result: Up to 3 orders per symbol
```

**Aggressive (10 orders):**

```
MaxOrdersPerSymbol = 10
// Result: Multiple positions, pyramiding allowed
```

**Unlimited:**

```
MaxOrdersPerSymbol = 0
// Result: No limit (use with caution!)
```

**When to use:**

* Prevent over-concentration on one symbol
* Limit risk per instrument
* Professional risk management

***

#### **3. MaxTotalOrders**

```
MaxTotalOrders = 0  // 0 = unlimited, >0 = max total orders across all symbols
```

**Controls maximum total orders across entire account.**

**Example with MaxTotalOrders = 10:**

```
Current Orders:
- EURUSD BUY
- GBPUSD SELL
- XAUUSD BUY
... (total: 10 orders)

New Signal: USDJPY BUY
Result: ⚠️ Blocked
EA Logs: "Max total orders reached (10/10)"
```

**Configuration by Account Size:**

**Small Account ($500-$2,000):**

```
MaxTotalOrders = 5
// Reason: Limited margin, focus on quality
```

**Medium Account ($2,000-$10,000):**

```
MaxTotalOrders = 15
// Reason: More capacity, diversification
```

**Large Account ($10,000+):**

```
MaxTotalOrders = 30
// Reason: Professional diversification
```

**Why use this?**

* Margin management (prevent margin call)
* Focus on best signals only
* Reduce complexity
* Server performance (too many orders = lag)

***

#### **4. MaxOrdersPerDirection**

```
MaxOrdersPerDirection = 0  // Max orders per direction (BUY or SELL) per symbol
```

**Controls maximum orders per symbol AND direction.**

**Example with MaxOrdersPerDirection = 2:**

```
MaxOrdersPerDirection = 2
AllowDuplicateOrders = true

Current: EURUSD BUY (2 orders)
New Signal: EURUSD BUY
Result: ⚠️ Blocked ("Max orders per direction reached - EURUSD BUY")

New Signal: EURUSD SELL
Result: ✅ Allowed (different direction)
```

**Strategy Example (Hedging):**

```
MaxOrdersPerSymbol = 6
MaxOrdersPerDirection = 3
AllowDuplicateOrders = true

// Can have: 3 BUY + 3 SELL on same symbol = 6 total
```

***

### ✅ Order Validation

#### **5. MinLot / MaxLot**

```
MinLot = 0.01  // Minimum lot size
MaxLot = 10.0  // Maximum lot size (per order)
```

**Purpose:** Validate calculated lot size before opening order.

**Example:**

```
MinLot = 0.01
MaxLot = 0.50

Scenario 1: Calculated lot = 0.005
Result: ⚠️ Adjusted to 0.01 (minimum)

Scenario 2: Calculated lot = 0.25
Result: ✅ Accepted

Scenario 3: Calculated lot = 1.50
Result: ⚠️ Adjusted to 0.50 (maximum)
```

**When to adjust:**

**Broker Limits:**

```
ECN Broker: MinLot = 0.01, MaxLot = 100
Standard Broker: MinLot = 0.10, MaxLot = 50
Cent Account: MinLot = 0.01, MaxLot = 1000
```

**Risk Management:**

```
Conservative: MaxLot = 0.20
Moderate: MaxLot = 0.50
Aggressive: MaxLot = 2.0
```

**Note:** This limit is **per order**. If you open 3 orders per signal (3 TP levels), each can be up to MaxLot.

***

#### **6. MinSLPips / MaxSLPips**

```
MinSLPips = 5    // Minimum SL distance
MaxSLPips = 500  // Maximum SL distance
```

**(Covered in SL/TP Configuration doc - see 03\_SL\_TP\_CONFIGURATION.md)**

**Purpose:** Reject orders with SL outside acceptable range.

**Example:**

```
MinSLPips = 10
MaxSLPips = 200

Signal: GBPUSD BUY, SL = 5 pips
Result: ⚠️ Rejected ("SL too tight - 5 pips < minimum 10 pips")

Signal: EURUSD BUY, SL = 300 pips
Result: ⚠️ Rejected ("SL too wide - 300 pips > maximum 200 pips")
```

***

#### **7. SkipOrderWithoutTP**

```
SkipOrderWithoutTP = true | false
```

**Purpose:** Enforce TP requirement on all orders.

**When true (Recommended):**

```
Signal: XAUUSD BUY @ 2650, SL: 2630, TP: (none)
Result: ⚠️ Skipped
EA Logs: "Order skipped - No TP level found"
```

**When false:**

```
Signal: XAUUSD BUY @ 2650, SL: 2630, TP: (none)
Result: ✅ Opens without TP (manual exit required)
```

**When to use:**

* `true`: Automated trading, no manual intervention
* `false`: You manually manage exits via Telegram commands

***

### ⏱️ Pending Orders Management

#### **8. AllowPendingOrders**

```
AllowPendingOrders = true | false
```

**Controls whether EA opens pending orders (Buy Stop, Sell Limit, etc.).**

***

#### **true** (Allow Pending Orders)

**Behavior:** Opens pending orders when signal specifies entry price.

**Signal Example:**

```
📊 EURUSD BUY STOP @ 1.0900
Current Price: 1.0850
SL: 1.0850
TP: 1.0950
```

**EA Action:**

```
Opens: Buy Stop pending order @ 1.0900
Triggers when: Price reaches 1.0900
```

**When to use:**

* Signal provider sends breakout strategies
* Want automated entry at specific levels
* Professional pending order strategies

***

#### **false** (Block Pending Orders)

**Behavior:** Skips all pending order signals.

**Signal Example:**

```
GBPUSD SELL LIMIT @ 1.2800 (pending)
```

**EA Action:**

```
⚠️ Skipped
EA Logs: "Pending orders are disabled"
```

**When to use:**

* Only want market execution
* Don't trust pending order signals
* Reduce complexity

***

#### **9. TimeOrderNext**

```
TimeOrderNext = 10  // Seconds to wait between orders on same symbol
```

**Purpose:** Prevent rapid-fire duplicate orders from signal provider.

**Example with TimeOrderNext = 10:**

```
10:00:00 - EURUSD BUY signal → ✅ Opens
10:00:03 - EURUSD BUY signal → ⚠️ Blocked ("Too soon, wait 7 more seconds")
10:00:15 - EURUSD BUY signal → ✅ Opens (10 seconds passed)
```

**Configuration:**

**Strict (30 seconds):**

```
TimeOrderNext = 30
// Prevents signal spam effectively
```

**Moderate (10 seconds):**

```
TimeOrderNext = 10
// Balance between protection and responsiveness
```

**Permissive (3 seconds):**

```
TimeOrderNext = 3
// Quick signals allowed
```

**Disabled:**

```
TimeOrderNext = 0
// No time restriction (risky!)
```

**When to use:**

* Signal provider sometimes duplicates
* Telegram connectivity issues cause message repeats
* Protect against network glitches

***

### 🎯 Risk Exposure Validation

#### **10. MaxRiskPerTrade**

```
MaxRiskPerTrade = 1.0  // Maximum % of balance to risk per trade
```

**(Covered in Lot Size & Risk Management doc - see 01\_LOT\_SIZE\_AND\_RISK\_MANAGEMENT.md)**

**Purpose:** Limit risk amount per order.

**Example:**

```
Balance: $10,000
MaxRiskPerTrade: 2%
Max Risk Amount: $200 per order

Signal: GBPUSD BUY, SL 100 pips
Calculated lot: 0.25 (risks $250)
Result: ⚠️ Adjusted to 0.20 lot (risks $200)
```

***

#### **11. MaxTotalRiskPercent**

```
MaxTotalRiskPercent = 10.0  // Maximum % of balance at risk across all orders
```

**Purpose:** Limit total exposure across all open orders.

**Example:**

```
Balance: $10,000
MaxTotalRiskPercent: 10%
Max Total Risk: $1,000

Current Orders:
- EURUSD: Risking $300
- GBPUSD: Risking $400
- XAUUSD: Risking $250
Total Risk: $950

New Signal: USDJPY (would risk $200)
Result: ⚠️ Blocked ("Total risk would exceed 10% limit")
```

**Configuration:**

**Conservative:**

```
MaxTotalRiskPercent = 5%
MaxRiskPerTrade = 1%
// Max 5 trades at once (5 × 1% = 5%)
```

**Moderate:**

```
MaxTotalRiskPercent = 10%
MaxRiskPerTrade = 1%
// Max 10 trades at once
```

**Aggressive:**

```
MaxTotalRiskPercent = 20%
MaxRiskPerTrade = 2%
// Max 10 trades at once (10 × 2% = 20%)
```

**Why important:**

* Prevents over-exposure during high signal volume
* Drawdown protection
* Forces position selectivity

***

### 💼 Real-World Configuration Examples

#### **Example 1: Conservative Single Position**

**Goal:** Only one position per symbol, strict limits.

**Configuration:**

```
AllowDuplicateOrders = false
MaxOrdersPerSymbol = 1
MaxTotalOrders = 5
MaxRiskPerTrade = 1%
MaxTotalRiskPercent = 5%
TimeOrderNext = 30
SkipOrderWithoutTP = true
```

**Result:**

* Max 5 symbols traded
* 1 position per symbol
* 1% risk each = 5% total exposure
* No duplicates possible

***

#### **Example 2: Pyramiding Strategy**

**Goal:** Add to winners, up to 3 positions per symbol.

**Configuration:**

```
AllowDuplicateOrders = true
MaxOrdersPerSymbol = 3
MaxOrdersPerDirection = 3
MaxTotalOrders = 15
MaxRiskPerTrade = 1%
MaxTotalRiskPercent = 15%
TimeOrderNext = 60
```

**Result:**

* Can open 3 BUY + 3 SELL per symbol = 6 total per symbol
* Up to 15 total orders (5 symbols × 3 orders)
* Each risks 1%, max 15% total exposure

***

#### **Example 3: High Volume Trading**

**Goal:** Trade many signals, diversified portfolio.

**Configuration:**

```
AllowDuplicateOrders = false
MaxOrdersPerSymbol = 2
MaxTotalOrders = 30
MaxRiskPerTrade = 0.5%
MaxTotalRiskPercent = 10%
TimeOrderNext = 5
```

**Result:**

* Up to 30 orders (15 symbols × 2)
* Low risk per trade (0.5%)
* Controlled total exposure (10%)

***

#### **Example 4: Strict Risk Management**

**Goal:** Absolute control, no exceptions.

**Configuration:**

```
AllowDuplicateOrders = false
MaxOrdersPerSymbol = 1
MaxOrdersPerDirection = 1
MaxTotalOrders = 8
MaxRiskPerTrade = 1%
MaxTotalRiskPercent = 8%
MinLot = 0.01
MaxLot = 0.30
MinSLPips = 10
MaxSLPips = 150
SkipOrderWithoutTP = true
TimeOrderNext = 60
```

**Result:**

* Every limit enforced
* Maximum protection
* Clean, controlled trading

***

#### **Example 5: Aggressive Scalping**

**Goal:** Many quick trades, accept more orders.

**Configuration:**

```
AllowDuplicateOrders = true
MaxOrdersPerSymbol = 5
MaxTotalOrders = 50
MaxRiskPerTrade = 0.5%
MaxTotalRiskPercent = 15%
TimeOrderNext = 3
AllowPendingOrders = false
```

**Result:**

* High frequency trading
* Many small positions
* Market orders only
* Fast execution

***

### ⚠️ Common Mistakes

#### ❌ **Mistake 1: Unlimited Everything**

**Bad:**

```
AllowDuplicateOrders = true
MaxOrdersPerSymbol = 0  // Unlimited!
MaxTotalOrders = 0      // Unlimited!
MaxTotalRiskPercent = 0 // No limit!
```

**Risk:** 50+ orders on one symbol, 100% account risk, margin call!

**Good:**

```
Set ALL limits appropriately based on account size
```

***

#### ❌ **Mistake 2: Conflicting Settings**

**Bad:**

```
AllowDuplicateOrders = false  // Block duplicates
MaxOrdersPerSymbol = 5         // But allow 5 per symbol?
// Conflict: Can only have 1 per direction, so max 2 total (BUY + SELL)
```

**Good:**

```
AllowDuplicateOrders = true
MaxOrdersPerSymbol = 5
// Now makes sense: Up to 5 orders per symbol
```

***

#### ❌ **Mistake 3: No Time Buffer**

**Bad:**

```
TimeOrderNext = 0
// Result: Signal repeats → 10 duplicate orders in 1 second
```

**Good:**

```
TimeOrderNext = 10-30
```

***

#### ❌ **Mistake 4: MaxLot Too High**

**Bad:**

```
Balance: $1,000
MaxLot = 10.0
// Result: One order risks entire account + margin call
```

**Good:**

```
Balance: $1,000
MaxLot = 0.10-0.20  // Proportional to account
```

***

#### ❌ **Mistake 5: Ignoring Total Risk**

**Bad:**

```
MaxRiskPerTrade = 2%
MaxTotalOrders = 50
MaxTotalRiskPercent = 0  // No total limit!
// Result: 50 × 2% = 100% risk possible!
```

**Good:**

```
MaxRiskPerTrade = 2%
MaxTotalOrders = 10
MaxTotalRiskPercent = 20%  // Enforces 2% × 10 = 20% max
```

***

### ✅ Best Practices

#### ✅ **1. Always Set All Limits**

Minimum required:

```
MaxOrdersPerSymbol = (value)
MaxTotalOrders = (value)
MaxLot = (value)
MaxTotalRiskPercent = (value)
TimeOrderNext = (value > 0)
```

#### ✅ **2. Start Conservative**

First week:

```
MaxTotalOrders = 5
MaxRiskPerTrade = 0.5%
MaxTotalRiskPercent = 2.5%
```

Then gradually increase if comfortable.

#### ✅ **3. Match Account Size**

| Account Size | Max Total Orders | Max Risk/Trade | Max Total Risk |
| ------------ | ---------------- | -------------- | -------------- |
| $500-$2K     | 5                | 1%             | 5%             |
| $2K-$10K     | 10-15            | 1-2%           | 10-15%         |
| $10K+        | 20-30            | 1-2%           | 15-20%         |

#### ✅ **4. Test Configuration**

* Run on demo for 2 weeks
* Monitor order count, exposure, behavior
* Adjust limits based on signal frequency

#### ✅ **5. Document Your Limits**

```
Configuration Notes:
Date: 2024-10-28
MaxTotalOrders: 10 (account size: $5,000)
MaxOrdersPerSymbol: 2 (diversification)
MaxTotalRiskPercent: 10% (conservative)
Review Date: 2024-11-15
```

***

### 🔍 EA Logging Examples

**Order Accepted:**

```
========== ORDER VALIDATION PASSED ==========
Symbol: EURUSD
Direction: BUY
Lot: 0.15
SL: 50 pips (within 5-200 range)
TP: 100 pips
Risk: $150 (1.5% of balance)
Total Risk: $450 (4.5% of balance)
Orders on EURUSD: 1/3
Total Orders: 5/15
==============================================
```

**Order Rejected (Duplicate):**

```
⚠️ ORDER REJECTED: Duplicate order
Symbol: GBPUSD BUY
Reason: AllowDuplicateOrders = false
Existing order: GBPUSD BUY #12345678
```

**Order Rejected (Position Limit):**

```
⚠️ ORDER REJECTED: Position limit reached
Symbol: XAUUSD
Current orders on XAUUSD: 3/3 (MaxOrdersPerSymbol)
```

**Order Rejected (Total Risk):**

```
⚠️ ORDER REJECTED: Total risk limit
Current Total Risk: $950 (9.5%)
This Order Would Risk: $100
Total Would Be: $1,050 (10.5%)
MaxTotalRiskPercent: 10%
```

***

### 📊 Monitoring Your Orders

**Telegram Command:**

```
/status
```

**EA Response:**

```
📊 ACCOUNT STATUS
Balance: $10,000
Total Orders: 8/15
Total Risk: $720 (7.2%)

EURUSD: 2 orders (BUY, SELL)
GBPUSD: 1 order (BUY)
XAUUSD: 3 orders (BUY×2, SELL×1)
USDJPY: 2 orders (SELL×2)

Max Total Risk: 10%
Available Risk: $280 (2.8%)
```

***

### 🚀 Quick Start Guide

#### **Step 1: Determine Your Risk Profile**

Conservative: Smaller limits, strict validation Aggressive: Higher limits, more flexibility

#### **Step 2: Set Core Limits**

```
// Position Limits
MaxTotalOrders = ?
MaxOrdersPerSymbol = ?

// Risk Limits
MaxRiskPerTrade = ?
MaxTotalRiskPercent = ?

// Lot Limits
MaxLot = ?
```

#### **Step 3: Configure Duplicate Handling**

```
AllowDuplicateOrders = ?
TimeOrderNext = ?
```

#### **Step 4: Enable Validation**

```
MinSLPips = 10
MaxSLPips = 200
SkipOrderWithoutTP = true
```

#### **Step 5: Test & Monitor**

* Run on demo
* Check EA logs for rejections
* Adjust limits if too strict/loose

***

### 📞 FAQ

**Q: Orders not opening at all?** A: Check logs for rejection reasons. Likely exceeding MaxTotalOrders or MaxTotalRiskPercent.

**Q: Too many duplicate orders?** A: Set `AllowDuplicateOrders = false` and `TimeOrderNext = 30`.

**Q: EA only opens 1 order per symbol?** A: Increase `MaxOrdersPerSymbol` and set `AllowDuplicateOrders = true`.

**Q: Can I have different limits per symbol?** A: Not directly. Use separate EA instances or file config feature.

***

**Remember:** Proper order management is key to long-term profitability. Better to miss a trade than blow your account! 🎯


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://copier-docs.redfox-capital.com/config/order-management-and-validation-guide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
