- 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
2.5 KiB
2.5 KiB
| 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[]) forArraySetAsSeries()andCopyRates() - Verify property constant names (e.g.,
OBJPROP_FONTSIZEnotOBJPROP_FONT_SIZE)
EA-Specific Instructions
- Structure: All EAs must have a clear structure using the standard event handlers:
OnInit(),OnDeinit(), andOnTick(). - Initialization (
OnInit()):- All indicator handles (e.g., from
iMA,iRSI) MUST be created only once inOnInit()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_INCORRECTwhen invalid values are detected.
- All indicator handles (e.g., from
- Trading Logic (
OnTick()):- Use the object-oriented
CTradeclass from the Standard Library for all trade operations. Avoid legacy functions likeOrderSend(). - 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.
- Use the object-oriented
- 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.