SDK API reference
Every class, lifecycle method, callback, and configuration type in the MQL5 SDK — the contract your Expert Advisor or indicator implements.
Base class & constructors
CTheMarketRobo_Base is the unified base class; CTheMarketRobo_Bot_Base is an alias.
Expert Advisor (Robot):
Custom Indicator:
Call on_deinit() before destroying the instance (e.g. from OnDeinit).
Lifecycle methods
on_init(api_key, magic_number) for Robots;on_init(api_key) for Indicators. Returns INIT_SUCCEEDED or INIT_FAILED.
on_deinit(reason) — terminate session and cleanup. on_timer() — heartbeats and token refresh. on_chart_event(id, lparam, dparam, sparam) — SDK events (config/symbol/termination/token refresh).
Feature configuration
Call before on_init():
Callbacks
Override in your class. Default implementations are empty (not pure virtual).
Getters: get_robot_version_uuid(), get_token_refresh_threshold(), is_indicator_mode(), is_robot_mode().
Config & symbol change — handling requests
The server can send config change and symbol change requests in the heartbeat (or start) response. The SDK delivers them to your robot, applies changes using your code (config) or SymbolSelect() (symbols), and sends the result back in the next heartbeat. Support is optional: use set_enable_config_change_requests(false) / set_enable_symbol_change_requests(false) to ignore.
Config change — request format (from server)
For each item the SDK calls your validate_field(field_name, new_value_str, reason). If valid, it calls update_field(field_name, new_value_str). You must implement both so config changes apply. Values arrive as strings (e.g. "0.05", "10").
Example: update_field and validate_field
Config change — response (SDK sends in next heartbeat)
Example: on_config_changed — react after changes
Called after the SDK has applied one or more config changes. Your config object already has the new values. Use this to recalculate, log, or alert.
Symbol change — request format (from server)
The SDK calls SymbolSelect(symbol_name, active_to_trade) for each item and updates its internal list. It then sends symbols_change_results in the next heartbeat. For each applied change it calls your on_symbol_changed with event JSON.
Example: on_symbol_changed — close positions when symbol disabled
Summary: SDK receives request → validates (config) / applies SymbolSelect (symbol) → your update_field applies config values → SDK builds result → next heartbeat sends result. Optionally override on_config_changed / on_symbol_changed to react.
IRobotConfig
Override: define_schema(), apply_defaults(), to_json(), update_from_json(CJAVal), update_field(name, value), get_field_as_string(name). Use m_schema.add_field() with CConfigField.
Provided: validate_field, get_field_names, get_schema, get_schema_json, get_field_definition.
CConfigField & schema
Factory methods: create_integer, create_decimal, create_boolean, create_radio, create_multiple. Fluent setters: with_description, with_range, with_precision, with_option, with_group, etc.
Events & constants
Event IDs: SDK_EVENT_CONFIG_CHANGED, SDK_EVENT_SYMBOL_CHANGED, SDK_EVENT_TERMINATION_START/END, SDK_EVENT_TERMINATION_REQUESTED, SDK_EVENT_TOKEN_REFRESH.
Constants: SDK_API_BASE_URL, SDK_DEFAULT_TOKEN_REFRESH_THRESHOLD (60), SDK_DEFAULT_HEARTBEAT_INTERVAL (60), SDK_MAX_HEARTBEAT_INTERVAL (300). See and endpoint flows for request/response details.
Error handling
Init: "Invalid robot_version_uuid" (36 chars), "API Key is required", "Failed to start SDK session". Robots: auth failure triggers ExpertRemove(). Indicators: SDK stops timer and alerts user (no self-removal). Use token refresh threshold and monitor logs.