11 KiB
Universal Buffer Reader EA - Quick Start Guide
Version: 2.0 Date: 2025-01-20
Overview
The Universal Buffer Reader EA is a sophisticated MetaTrader 5 Expert Advisor that reads custom indicator buffers to generate trading signals. It features advanced risk management, partial position closing, breakeven, trailing stops, and state persistence.
Key Features:
- ✅ Custom indicator signal detection
- ✅ Multiple take profit levels with partial closing
- ✅ Breakeven and trailing stop management
- ✅ Time-based trading filters
- ✅ Daily profit target enforcement
- ✅ State persistence across EA restarts
- ✅ Manual trading mode with chart controls
- ✅ Smart logging with error deduplication
Installation
Step 1: Copy Files to MetaTrader 5
-
Navigate to your MetaTrader 5 data folder:
- Windows:
C:\Users\{Username}\AppData\Roaming\MetaQuotes\Terminal\{TerminalID}\MQL5\ - Mac:
Open MetaTrader 5 → File → Open Data Folder
- Windows:
-
Copy the following files:
Universal_Buffer_Reader_EA.mq5 → MQL5/Experts/ Include/LoggingManager.mqh → MQL5/Include/ Include/SignalDetector.mqh → MQL5/Include/ Include/TimeFilter.mqh → MQL5/Include/ Include/MoneyManager.mqh → MQL5/Include/ Include/RiskManager.mqh → MQL5/Include/ Include/PartialCloseManager.mqh → MQL5/Include/ Include/TradeExecutor.mqh → MQL5/Include/ Include/StateManager.mqh → MQL5/Include/ Include/UIManager.mqh → MQL5/Include/ -
Copy your custom indicator file:
YourIndicator.ex5 → MQL5/Indicators/
Step 2: Compile the EA
- Open MetaEditor 5 (press F4 in MetaTrader 5)
- Open
Universal_Buffer_Reader_EA.mq5 - Press F7 or click "Compile"
- Verify no errors in the "Errors" tab
- Close MetaEditor 5
Step 3: Enable Algorithmic Trading
- In MetaTrader 5, go to Tools → Options → Expert Advisors
- Check "Allow algorithmic trading"
- Check "Allow DLL imports" (if your indicator requires it)
- Click OK
Quick Configuration
Option 1: Indicator Mode (Recommended)
-
Open a chart (e.g., EURUSD H1)
-
Drag
Universal_Buffer Reader EAfrom Navigator → Expert Advisors -
Click on the chart to open EA settings
-
Configure the following essential parameters:
General Settings:
Trade_Mode:MODE_INDICATORLotSize:0.03(or your preferred lot size)MagicNumber:24680(or any unique number)EnableDebugPrints:true(for testing)
Signal Detection:
IndicatorName:"Your Indicator Name"(exact name)BuySignalBuffer:0(buffer with buy signals)SellSignalBuffer:1(buffer with sell signals)BuySLBuffer:2(buffer with buy SL)BuyTP1Buffer:3(buffer with buy TP1)BuyTP2Buffer:4(buffer with buy TP2)BuyTP3Buffer:5(buffer with buy TP3)SellSLBuffer:6(buffer with sell SL)SellTP1Buffer:7(buffer with sell TP1)SellTP2Buffer:8(buffer with sell TP2)SellTP3Buffer:9(buffer with sell TP3)
-
Click OK
-
Click the "AutoTrading" button in the toolbar (should be green)
Option 2: Manual Mode
- Open a chart
- Drag
Universal Buffer Reader EAfrom Navigator → Expert Advisors - Configure:
Trade_Mode:MODE_MANUALLotSize:0.03MagicNumber:24680
- Click OK
- Click "AutoTrading" button
- Use the Buy/Sell buttons that appear on the chart
Indicator Buffer Setup
Your custom indicator must provide the following buffers:
| Buffer Index | Purpose | Description |
|---|---|---|
| 0 | Buy Signal | Price level for buy entry (0 = no signal) |
| 1 | Sell Signal | Price level for sell entry (0 = no signal) |
| 2 | Buy SL | Stop loss for buy orders |
| 3 | Buy TP1 | First take profit for buy orders |
| 4 | Buy TP2 | Second take profit for buy orders |
| 5 | Buy TP3 | Third take profit for buy orders |
| 6 | Sell SL | Stop loss for sell orders |
| 7 | Sell TP1 | First take profit for sell orders |
| 8 | Sell TP2 | Second take profit for sell orders |
| 9 | Sell TP3 | Third take profit for sell orders |
Example Indicator Code:
//+------------------------------------------------------------------+
//| Custom Indicator Example |
//+------------------------------------------------------------------+
#property indicator_buffers 10
#property indicator_plots 2
double BuySignalBuffer[];
double SellSignalBuffer[];
double BuySLBuffer[];
double BuyTP1Buffer[];
double BuyTP2Buffer[];
double BuyTP3Buffer[];
double SellSLBuffer[];
double SellTP1Buffer[];
double SellTP2Buffer[];
double SellTP3Buffer[];
int OnInit() {
SetIndexBuffer(0, BuySignalBuffer);
SetIndexBuffer(1, SellSignalBuffer);
SetIndexBuffer(2, BuySLBuffer);
SetIndexBuffer(3, BuyTP1Buffer);
SetIndexBuffer(4, BuyTP2Buffer);
SetIndexBuffer(5, BuyTP3Buffer);
SetIndexBuffer(6, SellSLBuffer);
SetIndexBuffer(7, SellTP1Buffer);
SetIndexBuffer(8, SellTP2Buffer);
SetIndexBuffer(9, SellTP3Buffer);
return(INIT_SUCCEEDED);
}
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[]) {
// Your signal logic here
// Example: Simple moving average crossover
// ...
return(rates_total);
}
Monitoring the EA
Chart Information
When the EA is running, you'll see:
-
Loss Display (top-left corner):
- Accumulated Loss: $X.XX
- Consecutive Losses: X
-
Manual Mode Controls (if in manual mode):
- Buy button
- Sell button
Experts Tab
Monitor the Experts tab for:
- Trade execution messages
- Error messages (with deduplication)
- Debug information (if enabled)
Journal Tab
Monitor the Journal tab for:
- EA initialization messages
- EA deinitialization messages
- System-level errors
Common Tasks
Stop the EA
- Click the "AutoTrading" button in the toolbar (should turn red)
- Or right-click on chart → Expert Advisors → Remove
Change Settings
- Right-click on chart → Expert Advisors → Properties
- Modify parameters
- Click OK
- EA will restart with new settings
View Open Positions
- Go to Terminal tab → Trade
- Filter by MagicNumber to see EA trades
Close All EA Trades
- Go to Terminal tab → Trade
- Right-click on any EA trade
- Select "Close by Magic Number" (if available)
- Or manually close each trade
Reset State
To reset accumulated loss and consecutive losses:
- Stop the EA
- Go to Tools → Global Variables
- Delete variables starting with
UnivBufEA_ - Restart the EA
Troubleshooting
EA Not Trading
Symptoms: EA is running but no trades are opening
Solutions:
- Check "AutoTrading" button is green
- Check
EnableTimeFilter- ensure current time is allowed - Check
DailyProfitTargetPercent- ensure target not reached - Check indicator is providing signals (enable
EnableDebugPrints) - Check Experts tab for error messages
Compilation Errors
Symptoms: Errors when compiling the EA
Solutions:
- Verify all include files are in
MQL5/Include/ - Verify file paths are correct (use backslashes
\\) - Check for syntax errors in custom indicator
- Ensure MetaTrader 5 is up to date
Indicator Not Found
Symptoms: "Indicator not found" error in Experts tab
Solutions:
- Verify indicator name matches exactly (case-sensitive)
- Verify indicator is in
MQL5/Indicators/ - Compile the indicator first
- Check indicator has correct buffer indices
Orders Rejected
Symptoms: Orders are rejected by broker
Solutions:
- Check
LotSizeis within broker limits - Check account has sufficient margin
- Increase
Slippageparameter - Verify symbol is allowed for trading
State Not Persisting
Symptoms: Accumulated loss resets after EA restart
Solutions:
- Check global variables are not being deleted
- Verify
MagicNumberis consistent - Check symbol name is correct
- Ensure EA is properly closed (not crashed)
Testing Recommendations
1. Demo Account Testing
Always test on a demo account first!
- Test for at least 1-2 weeks
- Monitor all trades closely
- Check all features are working:
- Signal detection
- Order execution
- Partial closes
- Breakeven
- Trailing stops
- Time filtering
- Daily profit target
2. Backtesting
- Open Strategy Tester (press F4 or View → Strategy Tester)
- Select
Universal Buffer Reader EA - Select symbol and timeframe
- Select test period
- Configure input parameters
- Click "Start"
- Review results and optimize parameters
3. Forward Testing
After successful backtesting:
- Test on demo account with live data
- Monitor for 2-4 weeks
- Compare results with backtest
- Adjust parameters if needed
Safety Tips
- Start Small: Use small lot sizes initially
- Monitor Closely: Check trades frequently in first week
- Use Stop Losses: Always ensure SL is set
- Test Thoroughly: Never skip demo testing
- Keep Backups: Save working configurations
- Review Logs: Check Experts tab regularly
- Know Limits: Understand broker requirements
- Stay Updated: Keep EA and indicator updated
Getting Help
Documentation
- Test Plan:
TEST_PLAN.md - Input Parameters:
INPUT_PARAMETERS_REFERENCE.md - Original MQL4 Code:
Indicator Signal EA base code.mq4
Debug Mode
Enable debug prints to see detailed information:
- Set
EnableDebugPrints = true - Monitor Experts tab
- Look for messages with
[ClassName]prefix
Common Error Messages
| Error | Cause | Solution |
|---|---|---|
| "Indicator not found" | Indicator name incorrect | Check exact name in Indicators folder |
| "Invalid lot size" | Lot size outside broker limits | Adjust LotSize parameter |
| "Not enough money" | Insufficient margin | Reduce lot size or deposit funds |
| "Trading not allowed" | Time filter blocking | Check time filter settings |
| "Daily target reached" | Profit target met | Wait for next day or increase target |
Next Steps
- ✅ Install the EA
- ✅ Configure for your indicator
- ✅ Test on demo account
- ✅ Monitor and adjust settings
- ✅ Backtest and optimize
- ✅ Deploy to live account (when ready)
Version History
- v2.0 (2025-01-20): Complete rewrite in MQL5 with enhanced features
- v1.0: Original MQL4 version
Happy Trading! 📈
Last Updated: 2025-01-20 Version: 2.0