EA1/README.md
2026-03-09 13:22:39 +07:00

157 Zeilen
5,2 KiB
Markdown

# EA1 — Simple Moving Average 12/26 Crossover Bot
**Timeframe:** M15 (15-Minute)
**Strategy:** SMA 12 / SMA 26 Crossover
**Platform:** MetaTrader 5 (MQL5)
---
## Indicator Setup
Two Simple Moving Averages (SMA) are applied to the **closing price** of each 15-minute candle:
| Line | Period | Role |
|------|--------|------|
| Fast SMA | 12 | Short-term momentum |
| Slow SMA | 26 | Long-term trend direction |
When the two lines **cross each other**, a trade signal is generated.
---
## Trade Entry Logic
Signals are confirmed only on **fully closed M15 bars** (no repainting).
The EA compares the last two closed bars to detect a fresh crossover.
### 🟢 BUY Signal
**Condition:** SMA 12 crosses **above** SMA 26
```
Bar [2]: SMA12 <= SMA26 (fast was below or equal to slow)
Bar [1]: SMA12 > SMA26 (fast is now above slow)
```
**Action:**
1. Close any open **SELL** position immediately.
2. Open a **BUY** market order at the current **Ask** price.
3. Attach Stop Loss and Take Profit to the order (see below).
---
### 🔴 SELL Signal
**Condition:** SMA 12 crosses **below** SMA 26
```
Bar [2]: SMA12 >= SMA26 (fast was above or equal to slow)
Bar [1]: SMA12 < SMA26 (fast is now below slow)
```
**Action:**
1. Close any open **BUY** position immediately.
2. Open a **SELL** market order at the current **Bid** price.
3. Attach Stop Loss and Take Profit to the order (see below).
---
## Stop Loss & Take Profit
Every trade is opened with a **fixed pip-based** Stop Loss and Take Profit calculated from the entry price.
| Level | Pips | Direction | Purpose |
|-------|------|-----------|---------|
| **Take Profit** | 1000 pips | In trade direction | Lock in profit when price moves favourably |
| **Stop Loss** | 500 pips | Against trade direction | Limit loss if price moves the wrong way |
### BUY Trade Levels
```
Entry = Ask price
Take Profit = Ask + 1000 pips (price rises 1000 pips → trade closes in profit)
Stop Loss = Ask - 500 pips (price drops 500 pips → trade closes at a loss)
```
### SELL Trade Levels
```
Entry = Bid price
Take Profit = Bid - 1000 pips (price drops 1000 pips → trade closes in profit)
Stop Loss = Bid + 500 pips (price rises 500 pips → trade closes at a loss)
```
---
## Trade Exit Logic
A trade is closed under **one of three conditions**:
| Condition | Type | Triggered By |
|-----------|------|-------------|
| Price hits **Take Profit** level | Profit exit | Broker / MT5 automatically |
| Price hits **Stop Loss** level | Loss exit | Broker / MT5 automatically |
| **Opposite crossover** signal fires | Signal exit | EA closes trade before opening new one |
---
## Visual Flow
```
M15 Chart
─────────────────────────────────────────────────────► Time
SMA12 crosses ABOVE SMA26
┌───────────────┐
│ BUY ORDER │
│ Entry: Ask │
│ TP: +1000pip │
│ SL: -500pip │
└───────┬───────┘
┌──────────────────┼──────────────────┐
▼ ▼ ▼
Price hits TP Price hits SL SMA12 crosses below
(profit +1000p) (loss -500p) (EA closes → SELL opens)
SMA12 crosses BELOW SMA26
┌───────────────┐
│ SELL ORDER │
│ Entry: Bid │
│ TP: -1000pip │
│ SL: +500pip │
└───────┬───────┘
┌──────────────────┼──────────────────┐
▼ ▼ ▼
Price hits TP Price hits SL SMA12 crosses above
(profit +1000p) (loss -500p) (EA closes → BUY opens)
```
---
## Input Parameters
| Parameter | Default | Description |
|-----------|---------|-------------|
| `FastPeriod` | 12 | Period of the fast SMA |
| `SlowPeriod` | 26 | Period of the slow SMA |
| `LotSize` | 0.1 | Volume per trade |
| `TakeProfitPips` | 1000 | Take Profit distance in pips |
| `StopLossPips` | 500 | Stop Loss distance in pips |
| `PipSize` | 0.0001 | Pip value (`0.0001` for FX; `0.01` for JPY pairs) |
| `MagicNumber` | 112600 | Unique ID to identify EA trades |
---
## Notes
- **One trade at a time** — the EA never opens a second trade in the same direction.
- **New bar logic** — signals are only evaluated once per new M15 candle to prevent noise.
- **JPY pairs** — change `PipSize` to `0.01` when trading symbols like USDJPY or EURJPY.
- Always **backtest** in MetaTrader 5 Strategy Tester before running on a live account.