Loading…

MQL4 Gotcha Tour

Most MQL4 traps are explained in isolated forum posts, years apart, with no way to see several of them demonstrated together against a live terminal. This script runs ten of the classic ones back to back, computing real numbers on this exact broker wherever that is possible, rather than asserting the trap from memory. The ten traps covered: forward-deleting from the order pool while it re-indexes; MarketInfo() silently returning 0 on an unselected symbol; GetLastError() only being valid immediately after the failing call; comparing doubles with == instead of a tolerance; lot-step division without an epsilon; sending a price without NormalizeDouble(); hardcoding Digits()/Point() instead of reading them per symbol; treating a pip and a point as the same distance; ignoring MODE_STOPLEVEL/MODE_FREEZELEVEL before placing a stop; and not checking IsTradeAllowed() before attempting to trade. Nine of the ten read this broker's real, current values live - the account's real Digits(), Point(), MODE_STOPLEVEL, MODE_FREEZELEVEL, and IsTradeAllowed() state, plus a real (safe, ticket -1) failing API call for the GetLastError() timing trap. The order-pool trap is the one exception: it runs against a small synthetic ticket list built inside the script, so the lesson is visible and identical whether or not this account happens to have any open orders right now - it never touches a real order. Notes and limitations - Entirely read-only. The one API call that can "fail" (an OrderModify on ticket -1, for the GetLastError timing trap) can never touch a real order - that ticket cannot exist. - Some live readings depend on this broker/symbol's current configuration (Digits, Point, stop/freeze level, AutoTrading state) and will differ from another broker or another symbol on the same terminal - that is the point of the tour, not a limitation of it. - This is a teaching tool covering ten traps chosen for how often they actually break published MQL4 code; it is not an exhaustive list of every MQL4 pitfall.

Script · MT4 · v1.0 · Free

About MQL4 Gotcha Tour

MQL4 Gotcha Tour is an expert advisor (trading robot) for MetaTrader 4. MQL source code included.

Files in the download: MqlGotchaTour.mq4, MqlGotchaTour.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria