VPS Toolkit: Secure Order Sending and Restart-Safe State for Expert Advisors
Info
The VPS Toolkit: Secure Order Sending and Restart-Safe State for Expert Advisors is a Expert Advisor for MetaTrader 5 that vps toolkit this is a small include file (vpstoolkit. mqh) for Expert Advisors (EAs) that run 24/7 on an MQL5 VPS or your own PC.
Usage
This tool is typically used for automated trading on major forex pairs and gold.
Platform
This Expert Advisor works exclusively on MetaTrader 5 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL5/Experts folder via File ? Open Data Folder in MetaTrader 5.
How to Install and Use VPS Toolkit: Secure Order Sending and Restart-Safe State for Expert Advisors
1. Installation: Open the "File" menu, select "Open Data Folder," navigate to MQL/Experts, paste your file, and restart the terminal.
2. Activation: Drag the EA from the Navigator onto a chart, ensure "Allow live trading" is checked in the Common tab, and verify the AutoTrading button is green.
3. Optimization: Right-click your chart, choose "Expert List," click "Properties" to adjust inputs, and save your preferred setup as a set file for future use.
4. Maintenance: Regularly check the "Experts" tab in the terminal window to monitor trade logs and potential execution errors.
Frequently Asked Questions
Q: Why is my EA not opening trades? A: Check the "AutoTrading" button, ensure "Allow live trading" is enabled, and verify your broker allows automated trading on your account type.
Q: Can I run multiple EAs on one chart? A: No, each chart can only host one active EA; however, you can open multiple charts for different currency pairs to run several EAs.
Q: What does the "smiley face" icon mean? A: A smiley face in the top-right corner of the chart indicates the EA is successfully running; a frowny face means it is disabled.
What this tool does
VPS Toolkit This is a small include file (VpsToolkit.
Typical Use Case
This Expert Advisor excels in automated trading and technical analysis on MetaTrader 5.
Compatible Platform & Setup
This Expert Advisor works on MetaTrader 5. Place the file in the MQL5/Experts folder and restart the terminal.
Description & Settings
Related: Gonisshi MT5 Sync: Securely Journal Your Trades - another powerful expert for MetaTrader 5 traders.
VPS Toolkit This is a small include file (VpsToolkit.mqh) for Expert Advisors (EAs) that run 24/7 on an MQL5 VPS or your own PC. It contains no trading logic; you include it and call only the functions you need. The VpsToolkit_Demo.mq5 file demonstrates how to integrate it into an EA. The toolkit addresses common issues that arise when an EA is deployed live, such as: - The same EA running concurrently on a VPS and a PC. - Duplicate orders resulting from timeouts. - Counters being reset after a restart. - Trades being closed while the EA was offline. - Inaccessible log files due to them remaining on the VPS. Features Execution Location Control - VT_ActiveHere(): Use this function with a run-where switch (anywhere / only on MQL5 VPS / only on this PC) to ensure that redundant copies of the EA remain inactive. - VT_CanTrade(why): This function provides the reason why trading is blocked (e.g., no connection, Algo Trading disabled, account not permitted). Secure Order Sending - VT_OpenMarket(): This function returns OK, FAIL, or UNKNOWN. Only orders confirmed as 'OK' are considered successful. In case of a timeout or lost connection, it checks the account status for a few seconds instead of resending the order, preventing duplicate positions due to connection instability. Restart-Safe State Management - VT_Init() and VT_Ready(): These functions ensure that the EA waits until the account data is fully loaded, especially after a VPS restart when the login might initially be zero. - Global variable names are designed to include the login, symbol, and magic number to avoid conflicts. - VT_TradesToday(): This function retrieves the number of trades for the day from the deal history rather than relying on an in-memory counter. Handling Trades Closed While Offline - VT_ClosedWhileOff(): This function reports positions associated with your magic number that were closed while the EA was not running (due to Stop Loss/Take Profit, manual closure, or stop out), including the total Profit/Loss. Restart Counting - VT_RestartsToday() and VT_ShouldAnnounce(): These functions manage the notification of EA restarts, preventing a 'started' message from being sent on every single VPS restart. Append-Only Logging - VT_Log(): This function writes to a UTF-8 encoded CSV file that is never cleared upon restart. It also maintains daily counters (VT_CountInc() / VT_CountGet()). Telegram Integration (Optional) - VT_TgSend(): Allows sending messages via Telegram. - VT_DailyDue(): Schedules a daily summary at your local hour, including weekends. - VT_CsvNewRows(): Sends new log rows, as files on an MQL5 VPS cannot be directly downloaded. Quick Start Guide 1. Include the header file: Add #include "VpsToolkit.mqh" to your EA file. 2. Initialization in OnInit(): Call VT_Init(_Symbol, magic, runWhere, "MyEA_log.csv") and start a timer. 3. Timer handling in OnTimer(): Return while !VT_Ready(), then call VT_Heartbeat(). 4. Deinitialization in OnDeinit(): Call VT_Deinit(). 5. Placing orders: Use VT_OpenMarket() for sending orders. If the result is UNKNOWN, do not resend the order on the same signal; wait for the next bar to make a decision. 6. Telegram setup: Ensure Allow WebRequest is enabled in Tools > Options > Expert Advisors. Messages are sent only from the timer function, not during Strategy Tester runs. The Demo EA The VpsToolkit_Demo EA, when run on a live or demo chart, does not execute trades. Instead, it displays the EA's status, counts restarts, reports positions closed while offline, and writes a daily summary. When used in the Strategy Tester only (InpTesterDemo), it opens one example trade per day using VT_OpenMarket(). The InpRunSelfTest parameter initiates the built-in self-test. Testing and Verification - The code compiles without errors or warnings. - The self-test includes 38 checks, performed both in the Strategy Tester and on a live chart. - Strategy Tester (EURUSD H1, January to March 2026): 62 example trades were executed through VT_OpenMarket(), and a daily summary was generated every day, including weekends. - Live Demo Account (hedging, BTCUSD): A standard order was successfully placed (result 10009). An order with an incorrectly placed Stop Loss returned FAIL (result 10016). A position closed while the EA was offline was correctly reported after the restart (1 position, P/L -0.19). When using run-where = "only on VPS", the EA copy on the PC remained inactive. Restarts were counted sequentially (1, 2, 3), and the log file retained every entry. Areas Pending Confirmation: - Telegram message delivery. - Execution on an MQL5 VPS. - The UNKNOWN order path during a real connection loss (this scenario is covered by the self-test only). Please report any issues encountered that differ from this description. This toolkit is free to use. Feedback in the comments is appreciated.Also recommended: Multi-Currency Expert Advisor - similar expert with strong performance on MetaTrader 5.
You may also like: ka-gold bot mt5 - excellent alternative for expert users on MetaTrader 5.
Source Code
#property copyright "RobotFX"
#property link "https://robotfx.org"
#property version "1.00"
#property description "This code is educational. Feel free to use, modify and upgrade as you wish. Visit ROBOTFX.ORG for professional trading tools"
#include "VpsToolkit.mqh"
input group "Your EA"
input long InpMagic = 12345;
input int InpRunWhere = 0;
input bool InpLog = true;
input int InpStartGapMin = 30;
.......
⚠ Limitations & Risk Warning
- This tool is provided for educational and testing purposes only.
- Past performance does not guarantee future results.
- Trading involves substantial risk of loss. Use on a demo account first.
- Results may vary depending on market conditions, broker, and settings.
- We recommend thorough backtesting and forward testing before using with real funds.