Terminal Capability Shim
A program that assumes AutoTrading is on, a broker populates every MarketInfo mode, and DLLs are allowed finds out otherwise mid-run - a failed OrderSend, a MarketInfo() that quietly returns 0.0, or a rejected feature it never checked for. This header moves those checks to one place and one moment: TCS_Detect takes a snapshot in OnInit and every call site afterward reads a plain struct instead of repeating the same probes. MQL4 has no clean "is mode X supported" query. MarketInfo() returns 0.0 both for a genuinely zero reading and for "this broker/symbol does not populate this mode" - nothing built into the language resolves that ambiguity. TCS_ProbeMarketInfoMode narrows it rather than pretending to solve it: it checks GetLastError() immediately after the probe, since an unsupported query usually still sets an error code even when it returns 0.0 rather than raising a runtime exception, and treats a genuine 0.0 with no error as ALSO unsupported (a real freeze level of exactly zero is rare enough that this conservative default causes fewer surprises than the alternative). Every Supports* flag in TerminalCapabilities is documented as best-effort evidence, not a guarantee - a program that needs certainty about one specific mode should not treat these flags as the final word. TCS_RequireOrWarn and TCS_SafeMarketInfo give the graceful-degradation half a single call site too: log a plain Print() naming the missing feature and fall back, rather than silently doing less than a program looks like it is doing. Notes and limitations - The Supports* flags are best-effort, as explained above - they cannot perfectly distinguish "genuinely zero" from "not supported" using only documented MQL4 behaviour. Treat a "no" as "proceed with a documented fallback", not as certain proof the feature is absent. - TCS_Detect takes the account-wide and terminal-wide fields (DllAllowed, ExpertTradeAllowed, etc.) fresh on every call - it is not itself cached, so calling it repeatedly inside OnTick would repeat every probe. Call it once in OnInit and read the returned struct afterward, as the demo and the OnInit example both do. - IsTradeAllowed() reflects the CURRENT program's own "Allow live trading" checkbox state at the moment it is called - a user can change this mid-session, so a long-running EA should re-check it periodically rather than trusting a single OnInit snapshot forever for that one field specifically.
Script · MT4 · v1.0 · Free
About Terminal Capability Shim
Terminal Capability Shim is a script for MetaTrader 4. MQL source code included.
Files in the download: TerminalCapabilityShim.mqh, TerminalCapabilityShim.txt, TerminalCapabilityShimDemo.mq4.
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: MT4 Script · MQL4 Source Code