- 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
3.2 KiB
3.2 KiB
| applyTo |
|---|
| **/Include/_Thivyam/**/*.mqh |
Instructions for _Thivyam MQL Include Files (.mqh)
- Purpose: Include files should contain reusable functions, classes, or constants to promote modular and DRY (Don't Repeat Yourself) code.
- Modularity: Functions should be self-contained and perform a single, well-defined task.
- Documentation: All public functions and classes MUST be documented using a JSDoc-like comment style, explaining the purpose, parameters, and return value.
- Example:
/** * Calculates the dynamic lot size based on risk percentage. * @param riskPercent The risk per trade as a percentage of account equity. * @param stopLossPips The stop loss distance in pips. * @return The calculated lot size, or 0.0 on error. */ double CalculateLotSize(double riskPercent, int stopLossPips)
- Example:
- No Global State: Avoid defining mutable global variables within include files. Pass data through function parameters instead.
- Pointer Syntax (CRITICAL): In MQL5, use the dot operator (
.) for pointer member access, NOT the arrow operator (->). Example:CObject *ptr; ptr.Method();is correct,ptr->Method()causes compilation errors. - Pointer Safety: When classes manage pointers, always initialise members to
NULL, validate indices before dereferencing, and delete allocations exactly once (set pointers toNULLimmediately after deletion). - Array Operations: Prefer helper functions that wrap
ArrayResizeand boundary logic. When removing items from dynamic arrays, iterate from the end toward the beginning to avoid skipped elements and keep arrays tightly packed. Use dynamic arrays (Type[]) not static arrays (Type[N]) for functions likeArraySetAsSeries(). - Loop Variable Declaration: Never declare variables inside for-loop initializers. Always declare loop counters before the for statement:
int i; for(i = 0; i < n; i++). Use post-increment (i++) not pre-increment (++i). - Boolean Expressions: Ensure conditionals evaluate to explicit
boolexpressions (e.g., compare values or call methods returningbool). Do not rely on implicit pointer-to-bool conversions or assignments withinifstatements. - Error Reporting: Check and log the return values from MQL5 system calls (
ArrayResize,CopyRates, trading functions). UsePrintor structured logging helpers so runtime failures are visible during backtests. - Rendering & State Updates: Separate state mutation from rendering calls. Update your model object first, then invoke drawing functions on closed bars only.
- Tooling Recommendations: Before delivering changes, compile the modified module in MetaEditor (
MetaEditor64.exe /compile:"path"), enable “Treat warnings as errors”, and run available unit/back-test scripts where practical to surface regressions early. - Formatting: Stick to four-space indentation, keep lines under 120 characters where practical, and group related helper functions together to aid review by agentic coders.
- Agent Workflow: Leave breadcrumb comments for complex logic so future automated agents can understand intent without guessing (e.g., “// shift remaining contexts left after removal”). Keep such comments concise and meaningful.