GlobalVariable
This EA is a utility demonstration of MQL5 global variable functions (GlobalVariableSet, GlobalVariableGet, GlobalVariableCheck). It creates a client-side global variable with a calculated random value on init and updates it on deinit, with no trading logic whatsoever.
Open the interactive view (equity curve, symbol switch)Key facts
Backtest results (H1, about 1 year)
Not backtested yet — this EA could not be converted automatically.
Strategy analysis
This EA has no trading strategy at all; it is purely a demonstration tool for MQL5 global variable operations. In terms of strategy concept, it illustrates how to create, check, and read variables in the terminal's global variable pool. There are no entry conditions since it does not execute any trading operations, and likewise no exit conditions exist. Position sizing and money management are completely absent because the EA does not involve any orders or positions. The core logic is: on initialization, it checks if the global variable exists; if not, it calculates a random value via MathRand and creates it; if it exists, it reads the existing value. On deinitialization, it recalculates the value and updates the global variable. Variable naming uses a prefix plus magic number pattern (main_id_1010458) to ensure uniqueness.
Strengths
- Clearly demonstrates the MQL5 global variable creation, checking, and reading workflow
- Uses magic number suffix to ensure global variable name uniqueness and avoid conflicts
- Clean and straightforward code structure with error handling and error code output
- OnInit and OnDeinit show different scenarios for creating and updating global variables respectively
Weaknesses
- No actual trading functionality; it is merely an API usage example
- OnDeinit logic heavily duplicates OnInit logic with no code reuse
- Global variable value is randomly generated via MathRand with no practical business meaning
- Missing GlobalVariableDel cleanup logic, potentially leaving orphaned global variables
Possible improvements
- Add GlobalVariableDel cleanup logic in OnDeinit to avoid leaving orphaned global variables
- Extract duplicated global variable operation logic from OnInit and OnDeinit into a shared function
- Add demonstration of GlobalVariableTemp for temporary variables to expand example coverage
Risk assessment
Overall risk: Safe
- Not cleaning up global variables may lead to accumulation of obsolete data in the terminal's global variable pool
- No range validation on global variable values, but actual risk is extremely low since this is a demo tool
Evaluation scores
Parameters
| Parameter | Default | Description |
|---|---|---|
strGlobalId | main_id | Global variable name prefix identifier |
magic | 1010458 | Magic number, suffix for unique global variable names |
Similar Utility EAs
Backtests are historical simulations and do not guarantee future results. Not financial advice.