Spezifikation
📌 Project: Multi-Layer Pending Order EA (MT5)
1. Overview
The EA should:
-
Detect a manual pending order placed by the user
-
Create 3 additional layered pending orders based on it
-
Treat each manual order as an independent group
-
Activate only after Stop Loss (SL) is set
-
Keep SL/TP synchronized across group orders
-
On Take Profit (TP) hit, perform:
-
Pending cancellation OR
-
Break Even (BE) action (based on conditions)
-
2. Group Concept (Core Logic)
-
Each manual pending order = one unique group
-
Each group must be identified using:
-
Magic Number (recommended) OR
-
Unique Order Comment (Group ID)
-
👉 Important:
-
Groups must be completely independent
-
No cross-interference between groups
3. Activation Rule (SL Required)
-
EA must NOT take any action until:
-
The manual order has a Stop Loss set
-
Conditions:
-
SL = 0 → ❌ No action
-
SL is set → ✅ Activate EA for that order
4. Order Structure (Example - Buy)
🔹 Base Order (Manual)
-
Entry Price = 4809
-
Stop Loss = 4800
-
Take Profit = 4813
🔹 EA Layer Orders (after SL is set)
-
Layer 1
-
Entry = 4808
-
SL = 4800
-
TP = 4813 + 5 = 4818
-
-
Layer 2
-
Entry = 4807
-
SL = 4800
-
TP = 4818 + 5 = 4823
-
-
Layer 3
-
Entry = 4806
-
SL = 4800
-
TP = ❌ No TP (leave open)
-
5. SL / TP Synchronization
If the user modifies the base order:
When SL is changed:
-
EA must update SL of all pending layer orders in the same group
When TP is changed:
-
EA must recalculate and update TP for all layer orders:
-
Layer 1 → Base TP + 5
-
Layer 2 → Previous layer TP + 5
-
Layer 3 → No TP
-
👉 Only pending orders should be updated
👉 Do NOT modify already filled trades
6. Execution Behavior
-
Orders may be filled partially or fully
-
EA should only monitor until conditions are triggered
7. Take Profit Logic (Core Behavior)
🔹 Case 1: Pending Orders Still Exist
If:
-
Base order TP is hit
-
AND some group orders are still pending
Action:
-
❌ Cancel ONLY remaining pending orders of that group
-
✅ Do NOT affect filled/open trades
🔹 Case 2: All Orders Filled
If:
-
All group orders are filled (Base + 3 layers = 4 trades open)
-
AND price reaches Base TP
Action:
-
✅ Set Break Even (BE) for all open trades
8. Break Even Logic
Preferred:
-
Basket Average BE
-
SL = weighted average price of all open trades
-
Alternative:
-
Individual BE per trade (optional)
9. Multi-Group Handling
Example:
Group 1:
-
4809 + (4808, 4807, 4806)
Group 2:
-
4780 + (4779, 4778, 4777)
If:
-
Group 1 TP is hit
Then:
-
✅ Apply logic ONLY to Group 1
-
❌ Do NOT affect Group 2
10. Restrictions
The EA must NOT:
-
Interfere with other groups
-
Cancel unrelated pending orders
-
Modify open trades unnecessarily
11. Final Summary
-
SL must be set → EA activates
-
1 manual order = 1 group
-
EA creates 3 layered pending orders
-
SL/TP changes → auto synchronized
-
TP hit:
Case A:
-
Pending exists → cancel pending
Case B:
-
All filled → move all trades to BE
12. One-Line Logic
👉 SL set → create layers → sync updates → TP hit → cancel pending OR move all trades to BE (based on fill status)
End of Specification