Visual Studio Code

To add comments, please log in or register
nicholi shen
1894
nicholi shen  
Post your Visual Studio Code (VSC) tips, tricks, extensions, and snippets here. 
Maxim Dmitrievsky
25709
Maxim Dmitrievsky  

To enable mql5 intellisense, you can use this plugin:

then, you can save this page as html and open is vscode on second tab. So, all sintax will availble for autocomplete commands

also you can use mql4 Syntax Highlight plugin

and you can add mql5 folder with metaeditor to PATH and then you can compill your code directly in vscode

nicholi shen
1894
nicholi shen  
Maxim Dmitrievsky:

To enable mql5 intellisense, you can use this plugin:

then, you can save this page as html and open is vscode on second tab. So, all sintax will awailble for autocomplete commands


I just published a new MQL syntax highlight extension that runs on top of cpp so you can use all cpp extensions (Intellisence, clang-format, etc.) with MQL and keep the MQL syntax. In order to make this work you need to map MQL file extensions to cpp in the user settings:

"files.associations": {
   "*.mqh":"cpp",
   "*.mq4":"cpp",
   "*.mq5":"cpp"
}


Extension available in the VS marketplace

https://marketplace.visualstudio.com/items?itemName=nicholishen.mql-over-cpp

MQL-syntax-over-cpp - Visual Studio Marketplace
  • marketplace.visualstudio.com
Extension for Visual Studio Code - Highlights MQL syntax over the cpp profile in order to utilize the cpp intellisence and cpp extensions
Maxim Dmitrievsky
25709
Maxim Dmitrievsky  

Thanks, Ill try it :)

nicholi shen
1894
nicholi shen  

MQL extensions pack now available in the marketplace

Includes:

MQL Syntax highlighting over cpp
MQL Snippets
C++ Intellisence
clang formatter

Search the marketplace for "MQL Extensions pack" or download here

Anton Nel
49604
Anton Nel  

Very clever.

1) How to compile from mq4 to ex4 in Visual Studio Code?

2) How to run debugging mq4 in Visual Studio Code?

Thanks.

Stanislav Korotky
24579
Stanislav Korotky  
Anton Nel:

1) How to compile from mq4 to ex4 in Visual Studio Code?

2) How to run debugging mq4 in Visual Studio Code?


For 1) look in the documentation (section Compilation from the Command Line).

2) is impossible at the moment.

Compiling - Creating Programs - MetaEditor Help
Compiling - Creating Programs - MetaEditor Help
  • www.metatrader5.com
Any file (*.MQ4, *.MQ5 or *.MQH) can be compiled, but an executable file (*.EX4 or *.EX5) can be generated only as a result of the compilation of the main MQ4 or MQ5 file of a program. Compiled executable EX4/EX5 files can be distributed without source MQ4, MQ5 or MQH files. Debugging is impossible without them. It is recommended not to...
nicholi shen
1894
nicholi shen  
Anton Nel:

Very clever.

1) How to compile from mq4 to ex4 in Visual Studio Code?

2) How to run debugging mq4 in Visual Studio Code?

Thanks.


I'm pumped - this editor is seriously awesome and the only real hiccup is that the c++ intellisence doesn't recognize the dot operator being used on pointers... oh well. Here is a script that compiles and outputs the results to the terminal inside of VSC using the default Build keybinding of Ctrl+Shift+B.

You'll need to create a workspace.. I created one directly in my MQL folder. Next, go to Tasks > Configure tasks and create a new tasks.json file and paste and edit the paths to your MT install. Note: this isn't ideal...

{
   "version": "2.0.0",
   "tasks": [
      {
         "label": "launch_metaeditor",
         "type": "shell",
         "command": "C:\\Users\\User\\Dropbox\\MT-TK\\metaeditor.exe /portable",
      },
      {
         "label": "launch_terminal",
         "type": "shell",
         "command": "C:\\Users\\User\\Dropbox\\MT-TK\\terminal.exe /portable",
      },
      {
         "label": "MQL4-Compile",
         "group": {
            "kind": "build",
            "isDefault": true
         },
         "presentation": {
            "echo": true,
            "reveal": "always",
            "focus": true,
            "panel": "shared"
         },
         "promptOnClose": true,
         "type": "shell",
         "command": "C:\\Users\\User\\Dropbox\\MT\\metaeditor.exe",
         "args": [
            "/compile:${file}",
            "/inc:C:\\Users\\User\\Dropbox\\MT\\MQL4",
            "/log:${file}.log;",
            "type ${file}.log;",
            "del ${file}.log"
         ],
      }
   ]
}

Here are some bonus keymappings to quick-launch the terminal or the meta-editor

[
   {
      "key": "ctrl+alt+m",
      "command": "workbench.action.tasks.runTask",
      "args":"launch_metaeditor"
   },
   {
      "key": "ctrl+alt+t",
      "command": "workbench.action.tasks.runTask",
      "args":"launch_terminal"
   },
]


Anton Nel
49604
Anton Nel  

Thank you nicholishen. It works well. :-)

nicholi shen
1894
nicholi shen  
Anton Nel:

Thank you nicholishen. It works well. :-)


No worries... I actually ran into some issues with the compile script when working with larger projects due to the compile time. I introduced sleep into the shell command and now I don't have any issues. 

{
   "version": "2.0.0",
   "tasks": [
      {
         "label": "launch_metaeditor",
         "type": "shell",
         "command": "C:\\Users\\User\\Desktop\\MT5-BB\\metaeditor64.exe /portable",
      },
      {
         "label": "launch_terminal",
         "type": "shell",
         "command": "C:\\Users\\User\\Desktop\\MT5-BB\\terminal64.exe /portable",
      },
      {
         "label": "MQL-Compile",
         "group": {
            "kind": "build",
            "isDefault": true
         },
         "presentation": {
            "echo": true,
            "reveal": "always",
            "focus": true,
            "panel": "shared"
         },
         "promptOnClose": true,
         "type": "shell",
         "command": "C:\\Users\\User\\Desktop\\MT5-BB\\metaeditor64.exe",
         "args": [
            "/compile:${file}",
            "/inc:C:\\Users\\User\\Desktop\\MT5-BB\\MQL5",
            "/log:${file}.log;",
            "timeout 3;",
            "type ${file}.log;",
            "del ${file}.log"
         ],
      }
   ]
}
Anton Nel
49604
Anton Nel  
nicholishen:

No worries... I actually ran into some issues with the compile script when working with larger projects due to the compile time. I introduced sleep into the shell command and now I don't have any issues. 


"timeout 3;" -- this 3 seconds is still not 100% working so I have increased to 5 seconds then it is working. I guess because I have over 3000 lines of code. 5 seconds via VS Code seems too long for me. It took 97ms via Metaeditor. Thanks. 

To add comments, please log in or register