|
1 | | -# ⚡️ Meta Trader 5 + WebSockets + Real-time Ticker Messages |
2 | | -An example on how to push real-time ticker updates from MetaTrader 5 over WebSockets to any server. |
| 1 | +# ⚡️ MetaTrader 5 + WebSockets + Real-time Ticker Messages |
| 2 | + |
| 3 | +A solution for streaming real-time ticker updates from MetaTrader 5 over WebSockets to any server. |
3 | 4 |
|
4 | 5 |  |
5 | 6 |
|
6 | | -- 📘 Uses the robust WebSocket library implementation found in the MQL5 Book |
7 | | -- ⚡️ Sets a super tight update interval to have near-zero latency ticker updates |
8 | | -- 🚚 Combines ticker updates for symbols that changed in the same interval |
9 | | -- 📚 Uses JAson library to serialize/deserialize json |
| 7 | +- 📘 Leverages the robust WebSocket library implementation from the MQL5 Book |
| 8 | +- ⚡️ Implements tight update intervals for near-zero latency ticker updates |
| 9 | +- 🚚 Batches ticker updates for symbols that changed within the same interval |
| 10 | +- 📚 Utilizes JAson library for JSON serialization/deserialization |
10 | 11 |
|
11 | | -In use for our trade signaling website: [https://solidsignals.xyz](https://solidsignals.xyz) — Consistent Profitable Trades\ |
| 12 | +Currently powering our trade signaling platform: [https://solidsignals.xyz](https://solidsignals.xyz) — Consistent Profitable Trades |
12 | 13 | Written in MQL5, by polyclick |
13 | 14 |
|
14 | | -# Important |
| 15 | +## Important Note |
| 16 | + |
| 17 | +MetaTrader 5 restricts symbol tracking to those listed in the Market Watch window. When configuring the Expert Advisor, ensure that: |
| 18 | +1. All symbols you want to track are added to the Market Watch |
| 19 | +2. Symbol names in your configuration array match exactly with those in Market Watch |
| 20 | +3. Spelling is correct for all symbol names |
15 | 21 |
|
16 | | -MetaTrader 5 limits the symbols we can track. You can only request data from symbols that are listed in the Market Watch window. Keep this in mind when configuring the Expert Advisor. You'll find an array of strings for the symbols you want to track. Make sure you add those symbols in the Market Watch. Make sure the symbol name in the script is spelled correctly. |
| 22 | +## Setup Instructions |
17 | 23 |
|
18 | | -# Instructions |
19 | | -## 1. Download this github project |
| 24 | +### 1. Download this GitHub project |
20 | 25 |
|
21 | 26 | Shouldn't be too hard :) |
22 | 27 |
|
| 28 | +### 2. Install the MQL5Book library |
23 | 29 |
|
24 | | -## 2. Install the MQL5Book library |
| 30 | +Place the `MQL5Book` directory in your MetaTrader 5 include directory: |
| 31 | +``` |
| 32 | +/MQL5/Include/MQL5Book |
| 33 | +``` |
25 | 34 |
|
26 | | -Place the `MQL5Book` directory in the default `/MQL5/Include/` directory, resulting in the full path being: `/MQL5/Include/MQL5Book` |
| 35 | +When installed correctly, your directory structure should look like this: |
27 | 36 |
|
28 | | -When installed correctly your file structure should look like this: |
| 37 | + |
29 | 38 |
|
30 | | - |
| 39 | +### 3. Set up your Expert Advisor folder |
31 | 40 |
|
32 | | -## 3. Create your custom Expert Advisor folder & Copy files |
| 41 | +1. Create a custom Expert Advisor folder at `/MQL5/Experts/{YOUR_FOLDER_NAME}` |
| 42 | +2. Copy all files from the `Expert/` directory in this repo to your custom folder |
33 | 43 |
|
34 | | -Create your own custom Expert Advisor folder under `/MQL5/Experts/{FOLDER_NAME}` \ |
35 | | -Copy everything in this repo from `Expert/` into your custom folder |
| 44 | + |
36 | 45 |
|
37 | | - |
| 46 | +### 4. Compile the Expert Advisor |
38 | 47 |
|
39 | | -## 4. Compile |
| 48 | +1. Open MetaEditor |
| 49 | +2. Compile the Expert Advisor |
| 50 | +3. Resolve any include path issues that may arise |
40 | 51 |
|
41 | | -Compile & pray 🙏🏼 \ |
42 | | -Fix any include path issues |
| 52 | +### 5. Whitelist WebSocket URL |
43 | 53 |
|
44 | | -## 6. Whitelist the WebSocket url in Tools > Options |
| 54 | +In MetaTrader 5: |
| 55 | +1. Navigate to Tools > Options |
| 56 | +2. Add your WebSocket server URL to the allowed URLs list |
45 | 57 |
|
46 | | - |
| 58 | + |
47 | 59 |
|
48 | | -## 7. Attach compiled expert to any chart |
| 60 | +### 6. Attach the Expert Advisor to a chart |
49 | 61 |
|
50 | | -Although the Expert Advisor doesn't really use the `onTick()` event, we need to add it to a chart to start its execution. |
| 62 | +Even though the Expert Advisor doesn't primarily use the `onTick()` event, it needs to be attached to a chart to initialize and run. |
51 | 63 |
|
52 | | -There are some print statements in the code to help you debug. |
| 64 | +Debug messages are included in the code to assist with troubleshooting. |
53 | 65 |
|
54 | | -# Extra |
| 66 | +## Development Tools |
55 | 67 |
|
56 | | -## Start A Local, Temporary WebSocket Server |
57 | | -During development, setting up a temporary WebSocket server helps monitoring the sent Expert Advisor messages. For this, I suggest you use `wscat`: |
| 68 | +### Local WebSocket Server Setup |
58 | 69 |
|
59 | | -Starts a temporary WebSocket server on your local machine: |
60 | | -``` |
| 70 | +For development and testing, you can create a temporary WebSocket server: |
| 71 | + |
| 72 | +1. Start a local WebSocket server using `wscat`: |
| 73 | +```bash |
61 | 74 | npx wscat -l 8080 |
62 | 75 | ``` |
63 | | -Then, use `untun` to expose the local server for incoming public traffic using CloudFlare (Free): |
64 | | -``` |
| 76 | + |
| 77 | +2. Expose your local server to the internet using `untun` (CloudFlare-based tunneling): |
| 78 | +```bash |
65 | 79 | npx untun@latest tunnel http://localhost:8080 |
66 | 80 | ``` |
67 | | - |
68 | 81 |
|
69 | | -Untun will return a public url that routes public traffic to your local machine. |
| 82 | + |
70 | 83 |
|
71 | | -- Use the public url in the `Tools > Options` dialog (whitelist) |
72 | | -- Fill in the public url as an input for the Expert Advisor |
73 | | - |
74 | | -If connection fails, try different variations of the same url in both the `Tools > Options` (whitelist dialog) and the EA input parameter (WebSocket address): |
| 84 | +3. Use the public URL provided by `untun` in: |
| 85 | + - The MetaTrader 5 Tools > Options whitelist |
| 86 | + - The Expert Advisor input parameters |
75 | 87 |
|
| 88 | +If connection fails, try these URL variations in both the whitelist and EA parameters: |
76 | 89 | - `http://random-url.trycloudflare.com` |
77 | 90 | - `https://random-url.trycloudflare.com` |
78 | 91 | - `ws://random-url.trycloudflare.com` |
79 | 92 | - `wss://random-url.trycloudflare.com` |
80 | 93 |
|
81 | | -# Getting help |
82 | | -- Open an issue |
83 | | -- Check out our website: Solid Signals — [https://solidsignals.xyz](https://solidsignals.xyz) |
84 | | -- Join us on Discord: [https://discord.gg/NMVSE5mGkX](https://discord.gg/NMVSE5mGkX) |
| 94 | +## Support |
| 95 | + |
| 96 | +- Open an issue on GitHub |
| 97 | +- Visit our website: [https://solidsignals.xyz](https://solidsignals.xyz) |
| 98 | +- Join our Discord community: [https://discord.gg/NMVSE5mGkX](https://discord.gg/NMVSE5mGkX) |
0 commit comments