102 lines
No EOL
3 KiB
Markdown
102 lines
No EOL
3 KiB
Markdown
# MyEA.mq5 – Simple MQL5 Expert Advisor Template
|
|
|
|
Welcome to **MyEA.mq5**, a minimal template for developing your own Expert Advisor (EA) in MQL5.
|
|
This project is designed to help both beginners and experienced traders quickly start coding, testing, and customizing automated trading strategies for MetaTrader 5.
|
|
|
|
---
|
|
|
|
## 📂 File Structure
|
|
|
|
```
|
|
/MyEA.mq5 # Main Expert Advisor source code
|
|
/README.md # Project documentation
|
|
```
|
|
*(Add more files or folders as your project grows)*
|
|
|
|
---
|
|
|
|
## 🚀 Features
|
|
|
|
- Clean and standard MQL5 code structure
|
|
- Easy-to-edit input parameters (LotSize, StopLoss, TakeProfit)
|
|
- Uses built-in MQL5 trading library (`Trade.mqh`)
|
|
- Simple logic: opens a buy position if none exists
|
|
- Includes standard event handler functions (`OnInit`, `OnDeinit`, `OnTick`)
|
|
- Ready for further customization
|
|
|
|
---
|
|
|
|
## 📝 Code Breakdown
|
|
|
|
Below is the full code with explanations for each section:
|
|
|
|
```mql5
|
|
//+------------------------------------------------------------------+
|
|
//| MyEA.mq5 |
|
|
//| Copyright 2025, Daruma00 |
|
|
//| https://forge.mql5.io/Daruma00/my-ea-template |
|
|
//+------------------------------------------------------------------+
|
|
|
|
#property copyright "Copyright 2025, Daruma00"
|
|
#property link "https://forge.mql5.io/Daruma00/my-ea-template"
|
|
#property version "1.00"
|
|
#property strict
|
|
|
|
// === 1. Input Parameters ===
|
|
// These can be changed by the user from the EA settings in MetaTrader
|
|
input double LotSize = 0.1; // Trading lot size
|
|
input int StopLoss = 100; // Stop loss in points
|
|
input int TakeProfit = 200; // Take profit in points
|
|
|
|
// === 2. Include Required Library ===
|
|
// Provides trading functions (buy, sell, etc.)
|
|
#include <Trade\Trade.mqh>
|
|
|
|
// === 3. Global Variables ===
|
|
CTrade trade; // Trading object for executing orders
|
|
|
|
// === 4. Main Event Functions ===
|
|
|
|
// Called once when the EA is attached to a chart
|
|
int OnInit() {
|
|
Print("EA started");
|
|
return(INIT_SUCCEEDED);
|
|
}
|
|
|
|
// Called once when the EA is removed from the chart
|
|
void OnDeinit(const int reason) {
|
|
Print("EA stopped");
|
|
}
|
|
|
|
// Called on every new market tick
|
|
void OnTick() {
|
|
// Simple trading logic: open buy if no position exists
|
|
if(PositionsTotal() == 0) {
|
|
trade.Buy(LotSize, _Symbol, Bid, (Bid-StopLoss*_Point), (Bid+TakeProfit*_Point));
|
|
}
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## 🛠️ How to Use
|
|
|
|
1. **Copy or download** the `MyEA.mq5` file into your MetaTrader 5 `/Experts/` directory.
|
|
2. **Open MetaEditor** and compile the EA.
|
|
3. **Attach the EA** to your chart in MetaTrader 5.
|
|
4. **Adjust input parameters** (LotSize, StopLoss, TakeProfit) as needed.
|
|
5. **Run backtests** or live trading on a demo account to see how it works.
|
|
|
|
---
|
|
|
|
## 🤝 Contribution
|
|
|
|
Feel free to fork, modify, and share your improvements!
|
|
If you find bugs or want to suggest enhancements, please open an issue or pull request.
|
|
|
|
---
|
|
|
|
## 📄 License
|
|
|
|
This project is released under the MIT License.
|
|
See the `LICENSE` file for details. |