What is your workflow for maintaining single-source code files between MQL5 and MQL4+ projects?

 
I wish to get some feedback from other coders/developers on their experiences and workflow process with regards to projects written to be both MQL5 and MQL4+ compatible.

For the past few years, I have being coding in a way that all my Indicators and EAs make use of conditional compilation, so that the code will compile and run on both MT4 and MT5 systems. It all works relatively well, but I find myself having to store files in duplicate form sometimes due to two main factors:
  1. The first being, of having to have different file extensions for the same file for the two systems (namely “.mq4” and “.mq5”).
  2. The second being that I use OneDrive to synchronise and backup files between devices and the cloud, which is all good and well, but It does not play nice with symbolic or hard links between files within its own folder space. For example, I can store the file with “.mq5” and then create a link for the “.mq4” file, but OneDrive does not like that.
For point (1), I get somewhat around this by using skeleton “.mq4” and “.mq5” files and putting most of the code in “.mqh” files, but it still find it a hassle to do this for every project. Many times, the code is not big enough to justify this and I would prefer to just have one single source file only. I could use soft/hard links to the files, but this too can be a hassle and OneDrive does not like it either.

For point (2), I simply don’t have a solution, OneDrive allows links to/from files outside of its folder space but not within its own folder space. I also do not plan to use other Cloud systems like DropBox, because I already have 1TB space included in my Office license and don’t wish to pay extra or have to run two systems on my PCs eating away at resources. I also don’t wish to use Git for this because I don’t have much need for version control and I find it a hassle to always have to manage the commits when I make changes. OneDrive does a decent job of keeping a version history of the file updates automatically and I rarely need to make use of it, so I don’t need the complexity of Git for my MQL code.

When I have large projects and need to make use of the “Project” system of MetaEditor, the issues become quite more complex since I need to duplicate all the project files due to points (1) and (2), which is a pain.

So, my question to all coders/developers that work in a similar fashion of maintaining single-source for both MQL5 and MQL4+, how to you go about it in respect to your personal workflow habits?
 
Fernando Carreiro:
I wish to get some feedback from other coders/developers on their experiences and workflow process with regards to projects written to be both MQL5 and MQL4+ compatible.

For the past few years, I have being coding in a way that all my Indicators and EAs make use of conditional compilation, so that the code will compile and run on both MT4 and MT5 systems. It all works relatively well, but I find myself having to store files in duplicate form sometimes due to two main factors:
  1. The first being, of having to have different file extensions for the same file for the two systems (namely “.mq4” and “.mq5”).
  2. The second being that I use OneDrive to synchronise and backup files between devices and the cloud, which is all good and well, but It does not play nice with symbolic or hard links between files within its own folder space. For example, I can store the file with “.mq5” and then create a link for the “.mq4” file, but OneDrive does not like that.
For point (1), I get somewhat around this by using skeleton “.mq4” and “.mq5” files and putting most of the code in “.mqh” files, but it still find it a hassle to do this for every project. Many times, the code is not big enough to justify this and I would prefer to just have one single source file only. I could use soft/hard links to the files, but this too can be a hassle and OneDrive does not like it either.

For point (2), I simply don’t have a solution, OneDrive allows links to/from files outside of its folder space but not within its own folder space. I also do not plan to use other Cloud systems like DropBox, because I already have 1TB space included in my Office license and don’t wish to pay extra or have to run two systems on my PCs eating away at resources. I also don’t wish to use Git for this because I don’t have much need for version control and I find it a hassle to always have to manage the commits when I make changes. OneDrive does a decent job of keeping a version history of the file updates automatically and I rarely need to make use of it, so I don’t need the complexity of Git for my MQL code.

When I have large projects and need to make use of the “Project” system of MetaEditor, the issues become quite more complex since I need to duplicate all the project files due to points (1) and (2), which is a pain.

So, my question to all coders/developers that work in a similar fashion of maintaining single-source for both MQL5 and MQL4+, how to you go about it in respect to your personal workflow habits?


Have you tried having a variable that says what version you are at runtime. Then having each function go from there? I have some old code somewhere, but not sure I can find it. Not really the solution you are looking for, but that's how I dealt with it.

 
Scott MarshallHave you tried having a variable that says what version you are at runtime. Then having each function go from there? I have some old code somewhere, but not sure I can find it. Not really the solution you are looking for, but that's how I dealt with it.

Sorry, but I really don't see the relevance of your post! I don't need help with coding. There are already conditional compilation rules defined in MQL. I have no need for the creation of any special "variables" or "versioning"! My query is about workflow and file-handling for maintaining a single-source environment without the file duplication between the two systems.

 
Fernando Carreiro:
I wish to get some feedback from other coders/developers on their experiences and workflow process with regards to projects written to be both MQL5 and MQL4+ compatible.

For the past few years, I have being coding in a way that all my Indicators and EAs make use of conditional compilation, so that the code will compile and run on both MT4 and MT5 systems. It all works relatively well, but I find myself having to store files in duplicate form sometimes due to two main factors:
  1. The first being, of having to have different file extensions for the same file for the two systems (namely “.mq4” and “.mq5”).
  2. The second being that I use OneDrive to synchronise and backup files between devices and the cloud, which is all good and well, but It does not play nice with symbolic or hard links between files within its own folder space. For example, I can store the file with “.mq5” and then create a link for the “.mq4” file, but OneDrive does not like that.
For point (1), I get somewhat around this by using skeleton “.mq4” and “.mq5” files and putting most of the code in “.mqh” files, but it still find it a hassle to do this for every project. Many times, the code is not big enough to justify this and I would prefer to just have one single source file only. I could use soft/hard links to the files, but this too can be a hassle and OneDrive does not like it either.

For point (2), I simply don’t have a solution, OneDrive allows links to/from files outside of its folder space but not within its own folder space. I also do not plan to use other Cloud systems like DropBox, because I already have 1TB space included in my Office license and don’t wish to pay extra or have to run two systems on my PCs eating away at resources. I also don’t wish to use Git for this because I don’t have much need for version control and I find it a hassle to always have to manage the commits when I make changes. OneDrive does a decent job of keeping a version history of the file updates automatically and I rarely need to make use of it, so I don’t need the complexity of Git for my MQL code.

When I have large projects and need to make use of the “Project” system of MetaEditor, the issues become quite more complex since I need to duplicate all the project files due to points (1) and (2), which is a pain.

So, my question to all coders/developers that work in a similar fashion of maintaining single-source for both MQL5 and MQL4+, how to you go about it in respect to your personal workflow habits?
I am using hard links and mql5 Storage, with MetaEditor. I am using it as a backup system, not much as a CVS, and it works good. mql5 file is always the "main" file, mq4 the hard link not included in the Storage. Not perfect but it works without major issue.
 
Alain Verleyen: I am using hard links and mql5 Storage, with MetaEditor. I am using it as a backup system, not much as a CVS, and it works good. mql5 file is always the "main" file, mq4 the hard link not included in the Storage. Not perfect but it works without major issue.

Putting aside my OneDrive issue, how do you handle large projects with multiple ".mq5" files?

Ideally one would just need one hard-link for the entire folder tree, but that does not seem possible if one then needs extra separate hard-links for each ".mq5"->".mq4" file. Do you maintain multiple individual hard links for each ".mq5"->".mq4" file for such large projects?

It would be great if one could just instruct MetaEditor to compile to a certain target (MQL5/MQL4) irrespective of the file extension.

EDIT: For a large project, for example with multiple Indicators and an Expert as well, where there would be several ".mq5" files.

 
Fernando Carreiro:

Putting aside my OneDrive issue, how do you handle large projects with multiple ".mq5" files?

Ideally one would just need one hard-link for the entire folder tree, but that does not seem possible if one then needs extra separate hard-links for the ".mq5"->".mq4" file. Do you maintain multiple individual hard links for each ".mq5"->".mq4" file for such large projects?

It would be great if one could just instruct MetaEditor to compile to a certain target (MQL5/MQL4) irrespective of the file extension.

I don't use MetaEditor "Project", it's not flexible and buggy from my point of view. So yes I am creating a hard link for each mq5/mq4 file. I have a tool to do that which is pretty easy to use.

 
Alain Verleyen: I don't use MetaEditor "Project", it's not flexible and buggy from my point of view. So yes I am creating a hard link for each mq5/mq4 file. I have a tool to do that which is pretty easy to use.
I understand! So there really is no IDEAL solution which is a pity! Thank you for your feedback!
 
Fernando Carreiro:
I understand! So there really is no IDEAL solution which is a pity! Thank you for your feedback!
I forgot to say I am using the "Shared folders" structures, which allow to place and maintain all related files together. One main folder by project. One main folder for libraries.
 
Alain Verleyen: I forgot to say I am using the "Shared folders" structures, which allow to place and maintain all related files together. One main folder by project. One main folder for libraries.

"Shared Folders"? You mean, MQL's "Shared Projects" where you can have other users view the files as well through "MQL's Storage" solution?

 
Fernando Carreiro:

"Shared Folders"? You mean, MQL's "Shared Projects" where you can have other users view the files as well through "MQL's Storage" solution?

Yes sorry "Shared Projects", I used that but without using the project (.proj). It allows me to have a better organization (from my point of view) then the standard way.
 

- I am using two different installations, one for MT5, one for MT4. 

- I avoid the .mq4 and .mq5 extensions for real code and always create .mqh files which are just included in these .mq4/.mq5. This way I avoid double coding

- I packed all native MQL commands into a separate file, so that the almost all conditions like #ifdef __MQL4__ are located in one single file

- I packed all trade relevant code into a separate file and created a class which allows for trading with MT4/MT5 by providing the same functions

- Coding is done only within MT5 environment

- To synchronize / copy changes to the MT4 instance, I use the FreeFileSync app. After changes within MT5 code, it needs one click to update the whole MT4 folder-strcuture. Within MT4 I just compile, never edit. To update from MT5 to MT4 and to re-compile the complete stuff, which contains far more than 100 files, it takes less than 3 minutes. 

The process works reliable and without any issues since years.