Skip to content

algomql/Grid-EA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid Pyramid EA for MT4

Platform Language Symbol Timeframe

Professional-grade Expert Advisor implementing a sophisticated pyramid trading strategy for XAUUSD (Gold) on the M1 timeframe.

🎯 Overview

Grid Pyramid EA is a fully-automated trading system that:

  • Places pending Buy/Sell pairs around current price
  • Pyramids positions at fixed price steps when one side triggers
  • Manages all positions as a unified basket
  • Closes the entire basket when exit conditions are met
  • Automatically re-places new pending pairs after reset

✨ Key Features

Core Functionality

  • Two-Sided Entry System: Configurable Stop or Limit pending orders
  • Smart Pyramiding: Fixed USD-based price steps (≈6 pips for XAUUSD)
  • Flexible Lot Sizing: Arithmetic or Geometric progression
  • Basket Management: Unified exit for all positions
  • Intelligent Spacing: Time/Bar/Pip-based order placement control

Advanced Features

  • 🎯 Virtual TP/SL: Hidden from broker to prevent stop hunting
  • 📈 Trailing Stop: Lock in profits with configurable trailing logic
  • Trading Sessions: Filter trading hours for optimal performance
  • 🛡️ Drawdown Reduction (DDR): Dynamic loss mitigation system
  • 🎛️ Interactive Trade Panel: Real-time monitoring and control
  • 📝 Comprehensive Logging: Timestamped actions with error handling

Risk Management

  • 🔒 Position Limits: Max layers per side and total lots
  • 💰 Multiple Exit Modes: Profit, Time, Combined (OR/AND)
  • 🚨 Emergency Controls: Instant basket closure and trading halt
  • 📊 Real-Time P/L: Live profit/loss tracking

📦 Deliverables

File Description
GridPyramidEA.mq4 Full MQL4 source code
GridPyramidEA.ex4 Compiled executable (generated after compilation)
GridPyramidEA_Default.set Default parameter preset
USER_GUIDE.md Comprehensive user documentation
TEST_INSTRUCTIONS.md Detailed testing procedures
README.md This file

🚀 Quick Start

Installation

  1. Copy Files

    GridPyramidEA.mq4 → MT4/MQL4/Experts/
    GridPyramidEA_Default.set → MT4/MQL4/Presets/
    
  2. Compile

    • Open MetaEditor (F4 in MT4)
    • Open GridPyramidEA.mq4
    • Press F7 to compile
    • Verify "0 errors" in output
  3. Attach to Chart

    • Open XAUUSD M1 chart
    • Drag EA from Navigator
    • Enable "Allow live trading"
    • Load GridPyramidEA_Default.set preset
    • Click OK

Default Settings

Platform: MT4 (MQL4)
Symbol: XAUUSD
Timeframe: M1 (1 Minute)
Magic Number: 222222

Entry Distance: $1.50
Price Step (Buy): $0.62 (≈6 pips)
Price Step (Sell): $0.68 (≈6 pips)

First Lot: 0.02
Lot Mode: Arithmetic
Lot Step: 0.02
Max Adds: 20 layers
Max Total Lots: 10.0

Basket TP: $100
Exit Mode: Profit

📊 Strategy Explanation

Phase 1: Initial Placement

Price: 2650.00
├── BuyStop: 2651.50 (+$1.50)
└── SellStop: 2648.50 (-$1.50)

Phase 2: Trigger & Pyramid

Price hits BuyStop → Basket Direction: BUY
├── Layer 1: 0.02 lots @ 2651.50
├── Layer 2: 0.04 lots @ 2652.12 (+$0.62)
├── Layer 3: 0.06 lots @ 2652.74 (+$0.62)
└── Layer 4: 0.08 lots @ 2653.36 (+$0.62)

Phase 3: Exit & Reset

Basket P/L reaches $100 → Close All Positions
├── Close Layer 1, 2, 3, 4
├── Cancel opposite pendings
└── Wait 30 seconds (spacing)
    └── Place new BuyStop/SellStop pair

🎛️ Trade Panel

The interactive control panel provides:

Status Display

  • Current EA state
  • Active basket direction
  • Real-time P/L
  • Pyramid layers count
  • Total lot exposure

Control Buttons

  • START/STOP TRADING
  • PAUSE/RESUME ADDS
  • CLOSE ONLY MODE
  • CLOSE BASKET
  • EMERGENCY CLOSE ALL
  • REFRESH PENDINGS

📈 Performance Expectations

Conservative Setup

Account: $1,000+
Risk: Low
Expected Monthly: 5-10%
Max Drawdown: <15%

Balanced Setup

Account: $5,000+
Risk: Medium
Expected Monthly: 10-20%
Max Drawdown: <25%

Aggressive Setup

Account: $10,000+
Risk: High
Expected Monthly: 20-40%
Max Drawdown: <40%

Past performance does not guarantee future results

🧪 Testing

Backtesting (Strategy Tester)

Symbol: XAUUSD
Period: M1
Model: Every tick (most accurate)
Date Range: 3 months minimum
Initial Deposit: $1,000+

Target Metrics:

  • Profit Factor: > 1.2
  • Win Rate: > 50%
  • Max Drawdown: < 30%

Forward Testing (Demo)

  1. Attach to demo XAUUSD M1 chart
  2. Monitor for 1-2 weeks
  3. Verify:
    • Correct order placement
    • Accurate pyramiding
    • Basket exit at target
    • Panel accuracy

See TEST_INSTRUCTIONS.md for detailed procedures.

📚 Documentation

Document Purpose
USER_GUIDE.md Complete parameter reference, setup, usage examples
TEST_INSTRUCTIONS.md Backtesting, visual testing, validation procedures

⚙️ Parameter Categories

🔧 Core Settings

  • Magic Number
  • First Lot Size
  • Slippage Tolerance

📍 Entry Settings

  • Order Type (Stop/Limit)
  • Entry Distance from Price

📊 Pyramiding

  • Price Steps (Buy/Sell)
  • Lot Mode (Arithmetic/Geometric)
  • Lot Progression Settings
  • Position Limits

🎯 Basket Exit

  • Exit Mode (Profit/Time/Combined)
  • Profit Target (USD)
  • Time Limits

⏱️ Spacing Control

  • Mode (Time/Bar/Pip)
  • Minimum Spacing Values

🛡️ Risk Management

  • Virtual TP/SL
  • Trailing Stop
  • Session Filter
  • DDR (Drawdown Reduction)

🎨 User Interface

  • Trade Panel Display
  • Colors and Positioning

🔍 Log Messages

The EA provides detailed logging:

[2025-11-05 10:15:23] EA Initialized - Magic: 222222, Symbol: XAUUSD
[2025-11-05 10:15:25] Initial pending pair placed: Buy #12345, Sell #12346
[2025-11-05 10:18:42] Pyramid buy added: Layer 2, Ticket #12347
[2025-11-05 10:22:15] Basket exit triggered: Profit target reached: 105.50 USD
[2025-11-05 10:22:18] Basket closed - Final profit: 105.50 USD

🚨 Risk Warning

IMPORTANT: Trading forex and CFDs involves substantial risk of loss. This EA is provided for educational purposes. Key points:

  • ⚠️ Never risk more than you can afford to lose
  • ⚠️ Always test on demo accounts first
  • ⚠️ Past performance ≠ future results
  • ⚠️ Monitor EA performance regularly
  • ⚠️ Use appropriate risk management
  • ⚠️ Understand all parameters before live trading

🛠️ System Requirements

Minimum

  • MT4 Build 1090+
  • Windows 7+ / Wine (Linux/Mac)
  • 2GB RAM
  • Stable internet connection

Recommended

  • MT4 Latest Build
  • Windows 10/11
  • 4GB+ RAM
  • VPS with <10ms broker latency
  • Broker with low spreads (<30 pips XAUUSD)

📋 Broker Requirements

Required:

  • Allows Expert Advisors
  • XAUUSD symbol available
  • Sufficient leverage (1:100+)
  • Acceptable spreads

Preferred:

  • ECN/STP execution
  • No requotes
  • Fast order execution
  • 24/5 support

🔧 Troubleshooting

EA Not Trading

  • Check "Allow live trading" enabled
  • Verify sufficient margin
  • Review session filter settings

Orders Not Pyramiding

  • Check "PAUSE ADDS" not active
  • Verify position limits not reached
  • Review price step settings

Basket Not Closing

  • Check exit mode configuration
  • Verify profit target is realistic
  • Review time settings

See USER_GUIDE.md troubleshooting section for complete solutions.

📝 Version History

v1.00 - Initial Release

  • ✅ Core pyramid strategy
  • ✅ Two-sided pending orders
  • ✅ Arithmetic/Geometric lots
  • ✅ Multiple exit modes
  • ✅ Virtual TP/SL
  • ✅ Trailing stop
  • ✅ Trading sessions
  • ✅ DDR logic
  • ✅ Interactive panel
  • ✅ Comprehensive logging

🤝 Support

Before Contacting Support:

  1. Read USER_GUIDE.md thoroughly
  2. Check TEST_INSTRUCTIONS.md
  3. Review Experts log for errors
  4. Test with default settings
  5. Verify MT4 is updated

📜 License

This software is provided "as-is" for educational and testing purposes. The developer assumes no responsibility for trading losses or any damages arising from the use of this EA.

🎯 Acceptance Criteria

Correct two-sided re-placing: Verified ✅ ≈6-pip add spacing: Implemented ($0.62/$0.68 USD steps) ✅ Proper Arithmetic/Geometric lots: Both modes supported ✅ Basket settlement: All legs close within seconds ✅ Cancel-and-replace behavior: Fully functional ✅ Comprehensive logging: Time, action, broker codes included


🏁 Quick Start Checklist

  • Copy files to MT4 directories
  • Compile EA (0 errors)
  • Load default .set file
  • Attach to XAUUSD M1
  • Enable live trading
  • Verify panel displays
  • Run backtest
  • Forward test on demo
  • Monitor 1-2 days
  • Optimize if needed
  • Go live cautiously

Made with precision for professional traders

Happy Trading! 📈

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages