TAYU Academy course material · MQL5 EA Programming Intro
Course Notes
1. Understand the core idea of “Order management and error handling” and explain it in your own words
2. Master this module's focus: EA trading logic
3. Complete the assignment on your own and check it against the reference answer
Order management should distinguish between request acceptance and transaction completion, and error recovery must first check the status. The real transaction interface involves account permissions, contracts, and idempotence. The example demonstration in this lesson does not execute these interfaces.
A common approach is to calculate signals only when new K lines appear, to avoid placing multiple orders for each quote. Before placing an order, check for existing positions, ensure the spread is not too wide, and confirm the lot size is appropriate for the minimum step size of the underlying instrument. Also handle the return codes for failed order placements.
Record the time of the previous candle; only cross judgment of SMA is made when the time changes; do not place orders when the spread exceeds 3 pips; use `SymbolInfoDouble` to read `SYMBOL_VOLUME_STEP` to standardize the lot size.
Draw states such as "Pending," "In-Flight," "Partially Executed," "Completed," "Rejected," and "Unknown" → list allowable actions for each state → settle pending transactions first, do not automatically retry indefinitely.
Assume a request timed out and it is unknown whether it filled. Design a paper error-handling record; sending real orders is not allowed.
Record unique requests, timestamps, and errors, freeze new requests in the same direction, and decide to restore after querying. Do not resend a timeout as a rejection directly. Design a solution for unimplemented interfaces.
Receive 20 ticks in the same minute, cross signals should only be registered once according to the predetermined logic of "once per new bar". If the account already has positions from other strategies, do not modify or close them solely because the product is the same. Output signal.csv first, validate the duplicates, and then discuss the simulation execution adapter.
Course Examples deliberately do not use OrderSend; additional execution code requires separate simulation testing and platform verification.
The companion .mq5 file only logs signals and never submits orders. Below is a terminal checklist; having the source on the web does not mean it has compiled or run in your terminal. Without a terminal, complete the state machine on paper and record which steps were not run.
1. Download AcademySmaSignal.mq5
2. Open and compile it in MT5 MetaEditor; save the version and diagnostics
3. Watch new-bar signal logs on a demo chart or in the Strategy Tester only
4. Check CopyBuffer failures, duplicate new-bar events and resource release on exit
5. Do not enable live trading; verify the order state machine on paper1. Evaluate signals only on a new candle
2. Run several checks before placing an order
3. Handle failure return codes
Risk warning: leveraged trading in forex, precious metals and similar products carries a high level of risk and you may lose all of your capital, or more. This course is for education only. It is not investment advice and does not promise any return. Example prices and contract specifications are teaching assumptions; always use what your own platform discloses. Past performance and backtests do not indicate future results.
All values, prices, accounts and cases in this course are teaching assumptions; the fixed materials can be reproduced offline. Marking a lesson complete only records your study. It is not a certification, a service approval or a promise of returns. Workbooks and answer files are currently provided in Chinese.
Key Takeaways
Completion records your own study, not verified competence. Exercises use fictional data; no real account or deposit is required.