Specification
1. Overview
This EA implements a modular, hedged grid trading strategy for Forex and Metals. It can place buy/sell stop or limit orders based on user-defined parameters such as grid range, spacing, lot size sequences, and directional preferences.
Designed for multi-purpose use, this EA supports:
- Hedged grid logic with full auto-basket closure
- One-sided grid strategies with breakeven or trailing stop exits
- Virtual SL management
- Visual, interactive UI for per-symbol control
- Multiple chart and watchlist integration
- High customizability for traders of different styles
2. Grid Placement Configuration
2.1 Grid Range & Spacing
User can define:
- Start Price
- End Price
- Total Number of Orders
- Grid Spacing Method:
Grid Spacing Methods:
- Fixed: Constant pip or price gap (e.g., every 10 pips)
- Arithmetic: Gradually increasing spacing (e.g., +10, +15, +20 pips)
- Geometric: Spacing increases by a factor (e.g., 10, 20, 40 pips)
- Divided Range:
Formula: (Start Price - End Price) / (Number of Orders - 1)
Example: Start = 1.6900, End = 1.6800, Orders = 5
Spacing = (1.6900 - 1.6800) / (5 - 1) = 0.0025 (25 pips) - Fibonacci Levels: Spacing follows Fibonacci intervals
- Manual: User defines each grid price level manually
2.2 Order Types to Place
Users can select any combination of the following:
- ✅ Buy Stop Orders
- ✅ Buy Limit Orders
- ✅ Sell Stop Orders
- ✅ Sell Limit Orders
This enables:
- Hedged setups (e.g., Buy Stop + Sell Limit)
- Reversal setups (e.g., Buy Limits only)
- Breakout setups (e.g., Sell Stops only)
- Partial hedging (e.g., Buy Limit + Sell Stop)
2.3 Trend Direction Buttons
Two core buttons define default structure:
- Buy Grid = Uptrend (places Buy Stops and Sell Limits)
- Sell Grid = Downtrend (places Sell Stops and Buy Limits)
However, user can override order types manually via checkboxes.
2.4 Lot Size Sequences
User can input custom sequences for lot sizing:
Supported Methods:
- Fixed: e.g., [0.1, 0.1, 0.1, 0.1]
- Progressive: e.g., [0.1, 0.2, 0.3, 0.4]
- Fibonacci: e.g., [0.1, 0.1, 0.2, 0.3, 0.5]
- Custom: Any array input accepted
Lot Sequence Direction:
Each side (Buy and Sell) can apply:
- Normal: Use input sequence as-is
- Reversed: Apply in reverse order
Example:
Input Lot Sequence: [0.1, 0.1, 0.2, 0.3, 0.5]
- Buy Limits → Normal → [0.1, 0.1, 0.2, 0.3, 0.5]
- Sell Stops → Reversed → [0.5, 0.3, 0.2, 0.1, 0.1]
3. Execution Workflow Example
Example Setup:
- Start: 1.6900
- End: 1.6800
- Orders: 5
- Lot Sequence: [0.1, 0.1, 0.2, 0.3, 0.5]
- Trend: Downtrend (via Sell Grid button)
- Selected Order Types: ✅ Sell Stop + ✅ Buy Limit
- Spacing: (1.6900 - 1.6800) / 4 = 0.0025
Order Execution:
- Sell Stops (reversed lot order):
- Prices: 1.6900, 1.6875, 1.6850, 1.6825, 1.6800
- Lots: [0.5, 0.3, 0.2, 0.1, 0.1]
- Buy Limits (original lot order):
- Prices: Same as above
- Lots: [0.1, 0.1, 0.2, 0.3, 0.5]
4. Basket Closure Logic
4.1 In Hedged Mode (Buy + Sell Orders)
- Basket automatically closes when all selected grid orders are filled
- No TP required — profit is locked via hedging
- Virtual SL can still be applied as a safety net
4.2 In Single-Sided Mode (One Order Type Only)
- EA activates breakeven and/or trailing stop logic
- Basket closed when:
- Breakeven triggered
- Trailing Stop hit
- Manual close
- No hedging, so SL/TP logic is essential
4.3 Manual Option
- Basket can be closed manually at any time using "Close Basket" button
5. Breakeven & Trailing Stop Logic (Single-Sided Grids Only)
5.1 Breakeven
- Activates after price moves in favor by X points
- Moves stop loss to entry + buffer
User Inputs:
- Activation distance (e.g., 30 pips)
- Breakeven buffer (e.g., +2 pips)
5.2 Trailing Stop Types
a) Fixed Point Trail
- Trail SL by fixed value after reaching profit threshold
b) ATR-Based Trail
- Trail distance = ATR(n) × Multiplier
- Example: ATR(14) × 1.5
c) Swing-Based Trail
- SL placed below/above recent swing highs/lows
- Swing lookback period is configurable
User Inputs:
- Activation Profit (e.g., 20 pips)
- Trail Type (Fixed / ATR / Swing)
- Trail Distance or Lookback
- Optional SL buffer
6. Virtual Stop Loss
- All SL is virtual — not visible to broker
- Basket is closed if floating loss exceeds threshold
- Applies in both hedged and single-sided modes
7. UI Panel (Per Symbol)
UI Displays:
- Active grids
- Grid direction
- Order count: Filled / Pending
- Lot totals (Buy/Sell)
- Average breakeven prices
- Real-time locked PNL
- Commission per basket
- Estimated margin usage
UI Inputs:
- Start / End price
- Number of orders
- Lot size sequence
- Lot direction (Normal / Reversed)
- Select Order Types (checkboxes)
- Select Grid Spacing Type
- Trailing / Breakeven settings (if single-sided)
- Grid Preview on Chart (price levels, margin usage)
- Confirm button for order placement
UI Buttons:
- 🔘 Create Buy Grid (Uptrend logic)
- 🔘 Create Sell Grid (Downtrend logic)
- ❌ Close Basket
8. Multi-Symbol & Auto-Attach
- EA automatically applies settings across all symbols in watchlist
- Once configured, settings are remembered per chart
- Each symbol runs independently with its own grid, orders, and UI
9. Margin Estimation
- EA estimates required margin:
- Before order placement
- As orders are filled
- Factors:
- Symbol leverage
- Lot sizes
- Contract size
- Entry prices
10. Safety & Error Handling
- Max number of orders (user-defined)
- Max lot size (user-defined)
- Re-attempts failed order placements up to 3 times
- Logs all errors (invalid levels, insufficient margin, etc.)
- Alerts user on invalid inputs or conditions
11. Developer Notes
- Grid logic must support:
- Float pricing
- Custom sequences and spacing
- Opposite lot direction mirroring
- SL/TP must be fully virtual
- UI should be responsive and update live
- Support trailing stop logic per type (ATR, swing, fixed)
- Margin preview required before order confirmation
- Must support fast switching between symbols
- Modular order type handling
12. Deliverables
- ✅ Complete MQL5 EA (compiled and source code)
- ✅ Per-symbol UI with live display and control
- ✅ Clean, commented codebase
- ✅ User Manual (PDF or markdown)
- ✅ Backtest and forward test logs
- ✅ Optional