MT5 global variables for a daily trade counter: surviving a terminal restart
Posted: Sat Oct 24, 2026 11:53 am
MT5 global variables for a daily trade counter: surviving a terminal restart
An EA limits itself to 3 trades a day. If the counter is a plain integer inside the EA, it resets when the terminal restarts or the EA is reloaded, so a restart at 10:40 after two trades quietly gives the day three more. Terminal global variables, set with GlobalVariableSet, are stored by the terminal and survive restarts.
Example key: "tc_EURUSD_7001_20261029", with the symbol, the magic number and the date in it so every day starts from a new variable. On each entry, increase it: GlobalVariableSet(name, GlobalVariableGet(name) + 1). Before trading, read it and compare against the limit.
Facts to keep in mind. Values are doubles, not integers. Names are limited to 63 characters. A variable that hasn't been accessed for four weeks is deleted by the terminal. They are shared by every EA and script in that terminal, so two EAs using the same name will trample each other. GlobalVariableGet returns 0 for a name that doesn't exist, which for a counter is fine, but it also hides a typo in the name. GlobalVariableCheck tells you whether the variable exists, so the missing case can be handled on purpose.
An EA limits itself to 3 trades a day. If the counter is a plain integer inside the EA, it resets when the terminal restarts or the EA is reloaded, so a restart at 10:40 after two trades quietly gives the day three more. Terminal global variables, set with GlobalVariableSet, are stored by the terminal and survive restarts.
Example key: "tc_EURUSD_7001_20261029", with the symbol, the magic number and the date in it so every day starts from a new variable. On each entry, increase it: GlobalVariableSet(name, GlobalVariableGet(name) + 1). Before trading, read it and compare against the limit.
Facts to keep in mind. Values are doubles, not integers. Names are limited to 63 characters. A variable that hasn't been accessed for four weeks is deleted by the terminal. They are shared by every EA and script in that terminal, so two EAs using the same name will trample each other. GlobalVariableGet returns 0 for a name that doesn't exist, which for a counter is fine, but it also hides a typo in the name. GlobalVariableCheck tells you whether the variable exists, so the missing case can be handled on purpose.