MQL4/.github/instructions/mql5-experts.instructions.md
Rahul Dhangar 669ecde7b7 Initial commit: Documentation and MT4 EA Phases 1-3 complete
- Added comprehensive MQ4/MQ5 comparison documentation (60+ pages)
- Added MT4 EA implementation plan and tracking documents (60+ pages)
- Phase 1: Core infrastructure with input parameters and data structures
- Phase 2: Bar detection system for H4, M30, M15 timeframes
- Phase 3: Pattern detection logic (Regular/Irregular Buy/Sell patterns)
- Reference files: FINAL_H4_ZONES.mq4, MultiTimeframeZoneEA.mq5, Strategy.md
2025-11-04 01:38:41 +05:30

33 lines
No EOL
2.5 KiB
Markdown

---
applyTo: "**/MQL5/Experts/_Thivyam/**/*.mq5"
---
# Instructions for _Thivyam MQL5 Expert Advisors
## CRITICAL: MQL5 Syntax Compliance
**Before writing any MQL5 code, read and follow:** `mql5-syntax-critical.instructions.md`
Key mandatory rules:
- Use dot operator (`.`) for pointer member access, NOT arrow (`->`)
- Declare loop variables BEFORE for-loop: `int i; for(i=0; i<n; i++)`
- Use dynamic arrays (`Type[]`) for `ArraySetAsSeries()` and `CopyRates()`
- Verify property constant names (e.g., `OBJPROP_FONTSIZE` not `OBJPROP_FONT_SIZE`)
## EA-Specific Instructions
- **Structure:** All EAs must have a clear structure using the standard event handlers: `OnInit()`, `OnDeinit()`, and `OnTick()`.
- **Initialization (`OnInit()`):**
- All indicator handles (e.g., from `iMA`, `iRSI`) **MUST** be created only once in `OnInit()` and stored in global variables.
- Set the EA's magic number using `CTrade::SetExpertMagicNumber()`. The magic number must be a unique input parameter.
- Validate user inputs (risk %, symbol, timeframe) and return `INIT_PARAMETERS_INCORRECT` when invalid values are detected.
- **Trading Logic (`OnTick()`):**
- Use the object-oriented `CTrade` class from the Standard Library for all trade operations. Avoid legacy functions like `OrderSend()`.
- All trading conditions must be encapsulated in clear, well-named boolean functions (e.g., `bool CheckBuySignal()`).
- Enforce once-per-bar execution using a dedicated detector so automated agents do not accidentally trigger multiple trades on the same candle.
- Before any trade, compute position size from equity and stop distance; never hardcode lot sizes.
- Check margin requirements via `AccountInfoDouble(ACCOUNT_MARGIN_FREE)` and log informative warnings before aborting a trade.
- **Deinitialization (`OnDeinit()`):**
- Properly release all resources, such as indicator handles and graphical objects, to prevent memory leaks.
- **Error Handling:** Wrap every trade execution call with success/failure checks, log `GetLastError()` details, and surface actionable messages for both human and AI reviewers.
- **Telemetry:** Emit concise status and risk metrics to the Experts log so downstream tools can parse behaviour during backtests.
- **Testing:** Provide default input parameter sets suitable for Strategy Tester, and document any required custom symbols or data in the project README.
- **Agent Workflow:** Leave breadcrumbs explaining complex state transitions (e.g., when escalating from H4 to M15 logic) so future automated refactors remain safe.