Remember EA state after restart with terminal global variables

Remember EA state after restart with terminal global variables

A value stored only in an EA variable disappears when the program is unloaded. Terminal global variables provide another storage mechanism, but they are shared terminal resources rather than private variables belonging automatically to one EA.

Understand the lifetime

The MQL5 reference distinguishes terminal global variables from program-scope globals. Terminal globals remain for four weeks after their last access, and other MQL5 programs in the same terminal can access them. They are not a permanent database.

Name the state explicitly

For a hypothetical once-per-session flag, include a strategy identifier, symbol, account context and session date in the key. Use a schema version when the meaning changes. Avoid generic names such as done that another chart could reuse.

Reconcile on startup

A saved flag can disagree with reality after a rejected request, manual closure or interrupted shutdown. Read current positions and trade history before deciding what the flag means. Repeating initialization should lead to the same state, not another trade.

Test the recovery path

In a demo environment, stop the EA before and after the important event, then restart it. Also test a missing key and an older-format key. Ask AI to document the fallback and preserve unrelated terminal variables instead of deleting everything to reset one strategy.

Terminal global variables

Back to top

MQLume Bespoke

Built around your ambition.

Explore bespoke services →

Have something more specific in mind?

Ask us about advanced custom development. Share your requirements through private support or email; we will discuss the scope and quote separately.

100% committed to following up on your delivery and support requests.

Free downloads. Real source files.

FREE

Lizard [MQLume]

MQL5 / MT5Version v2.1

Free editable gold breakout project with six independently selectable cores, session filters and flexible position sizing.

US$99.00FREE
FREE

Scraper Gold [MQLume]

MQL5 / MT5Version v3.7

Free editable source with compiled EX5: four gold breakout engines with independent profiles, sizing, direction and exits.

US$95.00FREE
MQLume

More to explore. A community to share it with.

Stay close to MQLume, wherever you like to learn.

YouTube

See our EAs in action. Explore backtests, walkthroughs and practical guides.

Watch on YouTube

Telegram

Meet other EA users, share ideas and keep up with what’s new.

Join the community Follow official updates

Cart

One personal-use licence per project. Each project can be added once.

Your cart is waiting for its first passenger.

Choose an EA or source edition to get started.

Continue shopping