Closing the Remote Desktop window does not stop MT4. It disconnects you: the Windows session on the VPS stays open, and MetaTrader keeps running with its Expert Advisors until you reconnect. What closes MetaTrader is Sign out, which ends the session and every program in it, or a Shut down or Restart of the VPS. If you came back and found MT4 closed, one of those happened, and two checks on the VPS tell you which.
What each way of leaving does
A Windows session is your signed-in desktop on the VPS, with the programs you started in it. Disconnecting detaches your screen from it; signing out deletes it.
| What you do | What happens to the session | MetaTrader and the EAs |
|---|---|---|
| Close the Remote Desktop window (the X at the top, or on the bar at the top of the screen in full screen) | Disconnected, kept on the VPS | Keep running |
| Your PC sleeps, shuts down or loses its internet connection | Disconnected, kept on the VPS | Keep running |
| Lock the VPS screen | Stays open | Keep running |
Type tsdiscon in a Command Prompt on the VPS | Disconnected, kept on the VPS | Keep running |
Sign out from the Start menu, or type logoff | Ended and deleted | Closed. The EAs stop |
| Shut down from the Start menu | The VPS powers off | Closed until the VPS is started again |
| Restart, by you or by Windows Update | Every session ends | Back only if they are set to start on their own |
Microsoft's reference for tsdiscon states that programs running when a session is disconnected are running when you reconnect, with no loss of data. Its reference for logoff states that after a sign-out all processes end and the session is deleted.
Leave the VPS without stopping anything
- Leave each MetaTrader window open. Minimising is fine; File, Exit closes the terminal and its EAs.
- Close the Remote Desktop window with its X. If a message says the remote session will be disconnected, confirm it: that is the safe action.
- Do not open the Start menu to leave. Its user menu holds Sign out, and its power button holds Shut down and Restart.
Signing out before you walk away is a good habit on an office PC; on a trading VPS it stops the terminals. The steps for opening the connection in the first place, and saving it for next time, are in connecting to a Windows VPS with Remote Desktop.
Find out whether you disconnected or signed out
If MT4 was closed when you came back, check what ended it before you change anything.
- Reconnect with the same user name as before (usually
Administrator). A different user gets a different session, and does not see the terminals of the first one. - Open a Command Prompt and type
query user. It lists each session with its state (Active or Disc, for disconnected) and its logon time; a>marks the session you are in (Microsoft reference). - Read the logon time of your session and use the table below.
- If the logon time is after you left, open Task Manager (right-click the taskbar), go to Performance, select CPU and read Up time. Count back from now to see when Windows last started.
- Open the Journal tab of each terminal once it runs again. Its time-stamped entries for the login and for each EA being loaded show when the terminal last started.
| What you find | What happened | Next step |
|---|---|---|
| Logon time from before you left, terminals open | You disconnected; everything ran | Nothing to fix |
| Logon time from before you left, a terminal missing | The session survived; the terminal itself closed or crashed | Read its Journal and Experts logs; see why a trading VPS gets slow |
| Logon time after you left, Windows up since before you left | The old session was signed out: by you, a script, or a session time limit | Restart the terminals (below), then check the time limits |
| Logon time after you left, Windows started after you left | The VPS restarted | See autostart after a VPS reboot and Windows updates on a trading VPS |
| Your user name listed twice, one line Disc | You are in a new, empty session; the terminals are in the disconnected one | Switch to it with tscon (below) |
A terminal that is open when you reconnect is not proof that it ran the whole time: if your terminals are set to start automatically, they may also open when you sign in. The start time in the Journal settles it.
Two sessions for one user. Windows Server normally reconnects you to your disconnected session, because by default each user is restricted to a single session. If that restriction was turned off, a new connection can open a second desktop with nothing running in it, while MetaTrader carries on in the first. Note the ID of the line marked Disc in query user, then type tscon <ID>, for example tscon 2. The tscon reference says this connects you to that session and disconnects the current one. The empty session can stay. To remove it, run query user again and type logoff <ID> with the ID of the empty session, never the one that holds MetaTrader.
When a disconnect still ends the session
By default Windows keeps a disconnected session for an unlimited time. Group Policy can change that, and the Session Time Limits settings are where it happens (current names):
- On the VPS, type
gpedit.mscin the Start menu and open the Local Group Policy Editor. - Go to Computer Configuration, Administrative Templates, Windows Components, Remote Desktop Services, Remote Desktop Session Host, Session Time Limits. The same settings also exist under User Configuration.
- Set time limit for disconnected sessions: if it is enabled, disconnected sessions are deleted after that time, which closes MetaTrader exactly like a sign-out. Set it to Not Configured, or keep it enabled with Never.
- End session when time limits are reached: if it is enabled, a session that reaches the idle or active time limit set in the same folder is signed out instead of only disconnected. Leave it not configured.
If both the Computer Configuration and the User Configuration settings are set, the Computer Configuration one wins.
Get the EAs trading again after a sign-out
- Start each terminal from its own shortcut. If you run several copies of the same broker's MetaTrader, each one has its own folder and shortcut, as in running multiple MT4 terminals with the same broker.
- Look at the connection status in the bottom-right corner. If the terminal is not logged in, log in again from File, Login to Trade Account.
- Check that AutoTrading (Algo Trading in MT5) is on, and that each chart shows its EA in the top-right corner.
- Read the Experts tab for errors from the restart.
- Compare your open trades with what the EA should have done. A stop loss and a take profit set on the order are held by the broker's server and kept working. Anything the EA manages itself, such as a trailing stop, a hidden stop or a time-based exit, did not run while the terminal was closed.
- Leave by closing the Remote Desktop window.
If the EA still does not trade once the terminal is back, the cause is no longer the session: see EA not trading on a VPS.
When this is not the right fix
- The terminal drops the broker connection while the session is fine. That is a connection problem, not a session problem: start from MT4 keeps disconnecting on a VPS.
- You would rather not manage Windows sessions at all. For one MetaTrader account, Metatrader In Cloud is one MetaTrader 4 or 5 that opens in a browser tab, with unlimited Expert Advisors and nothing to install. You start, stop or restart it from the service page in the client area.
- You use the Metatrader VPS (Linux). It runs an Ubuntu desktop reached through Chrome Remote Desktop, not Windows Remote Desktop, so the Windows commands on this page do not apply to it.
How this works on Dipgate
- On a Trading VPS you connect with Remote Desktop, usually as
Administrator, and Dipgate's Windows connection article says the same as this page: after you disconnect, the VPS stays on and your programs keep running. - Dipgate sets up autologin on the Trading VPS. Put each platform's shortcut in the My Platforms Autostart folder so it starts again after a reboot. If you change the VPS password, redo the autologin.
- If you chose Shut down by mistake, start the VPS again from the client area, where you can also stop it, change its password and open the VNC console.
