1

I need to create an automatic code converter
from MQL4 API ( a C-like language )
into Forex Tester API ( C++ / Delphi DLL ).

There are suggestions that it can be done with the help of ANTLR and MMVP. However, I do not know how it can be done with the help of the above-mentioned technologies.

Could anybody tell how my problem can be solved?

If you do not know how to accomplish my task using ANTLR or MMVP then please advise other technologies.

Here is an example of a simple MQL4 program.

int Count=0;                                    // Global variable.

int init()                                      // Special function init()
{
   Print ("init()"); 
   return 0;                                      
}   

int start()                                     
{
   double Price = Bid;                          
   My_Function();                               
   Print("New tick:  ",Count,"   Price = ",Price); 
   return 0;                                      
}

int deinit()                                    
{
   Print ("deinit()"); 
   return 0;                                      
}

int My_Function()                               
{
   Count++; 
   return Count;                             
}

An example of the same program written in C++ API.

#include <windows.h>
#include "StrategyInterfaceUnit.h"
#include "TechnicalFunctions.h"

int Count=0;
char buf[100];

EXPORT void __stdcall InitStrategy()
{
   Print ("init "); 
}

EXPORT void __stdcall DoneStrategy()
{
   Print ("deinit()");
}

EXPORT void __stdcall ResetStrategy()
{
   Print ("ResetStrategy()");
}

int My_Function()                               
{
   return Count++;                                     
}

EXPORT void __stdcall GetSingleTick()
{
   SetCurrencyAndTimeframe("EURUSD", PERIOD_M1);
   double Price = Bid();                          
   My_Function();
   sprintf (buf, "New Tick %d   Price = %f", Count, Price);
   Print(buf); 
}

Sample.def
LIBRARY ISHIMOKU

EXPORTS InitStrategy
    DoneStrategy
    GetSingleTick
    ResetStrategy
    ReplaceStr
    IntrfProcsRec
user3666197
  • 1
  • 6
  • 50
  • 92
Justinserg
  • 21
  • 1
  • 7
  • First, **welcome to start asking at the StackOverflow**. You might have already noticed, that your `MQL4` -code syntax is not the current version of `MQL4` ( as noted below, a *"New"*-`MQL4` ). Kindly check and review, if your Project does not run into problems just due to this sort of shift-of-paradigm, just per se. Hope you can control your "input"-side code base. In case not, the whole effort goes to nose-dive into the rock bed ( for details kindly check further remarks below ) – user3666197 Dec 16 '15 at 09:00
  • Thank you for such a prompt answer. These experts work on a new Meta Trader. Most of the experts who need to be converted into Forex Tester API are written in the old MQL4. That is why I provided you with an example written in the old MQL4 – Justinserg Dec 16 '15 at 09:17
  • What is the approximate size of the code-base? In **`SLOC`** 's? In **`man*years`** ? – user3666197 Dec 16 '15 at 09:40
  • The amount of the code-base is constantly increasing. Users send new experts on a regular basis – Justinserg Dec 16 '15 at 14:02
  • **Which practically means** an approximate size of an accumulated code-base about a **`1 man*year`**, **`10 man*years`** or **`100 man*years` till EoY 2015?** Be quantitative. – user3666197 Dec 16 '15 at 14:13

1 Answers1

2

You were recommended to use ANTLR / MMVP for your Task ?

Well, the core issue is not hidden in the ANTLR kind of tools' capabilities.

I have spent some time researching, if ANTLR could "save" our code-base problems where our IDE ( not the default MetaLang, another, a more flexible, configurable and programmable IDE was used ) still was not able to resolve syntax-errors on brace-matching inside a multi-level commented source code.

While ANTLR is out of question a very powerful horse, one would spend ages to narrow-band specialise into just using this kind of general language-modelling and abstract syntax-tree modelling knowledge.

If your team can spend a few man*years into this learning curve, well, keep planning. If not, there is a high time to review, redesign and reschedule your Project Plan.

Why?

Nota bene: code-conversion is the easiest part...

a need to cover differences in syntax,
a need to cover differences in variables' scope (getting a bit harder)

Lexers may help a bit in this.


Understanding conceptual differences

I like your idea to create a proxy-layer on C++ side, based on target API-services, so as to mediate a missing behaviour on the more flexible part of the MQL4->Forex Tester march route.

In good old days of MQL4, ( when it was indeed an MQL4, not the "New"-hybrid ) I have developed a few syntax-wrappers for similar purposes but with a different motivation, where the plain & simple MQL4 concepts were not feasible to remain help-less.

The proper understanding of both the principal architecture and different modi operandi available in MetaTrader Terminal 4 as a code execution ecosystem of the MQL4 programme types { EA | Script | Indicator } is only a start of the approach once you decided to elaborate a code-conversion from MQL4-DSL-domain into another DSL-domain.


The final nail into the coffin ... syntax creeps in New-MQL4.56789

It is hard not to mention that recent years MQL4 started to become a very different language.

Once can guesstimate what that means for a code-base maintenance, the more what nightmare this represents "behind the curtain" once code-base spans about n-hundreds man years.

Simply put, while the key concepts do not move so often, each new release of either MetaTrader Terminal 4 as a code execution ecosystem or the MetaEditor as a semi-integrated code compilation tool-chain } formerly known as a MetaLang.exe ( pre-New-MQL4.56789... ) ( whereas both are distributed out of ones own control, even with an "enforced update" by a Broker-side operated policy, so no way for a particular "version-freezing" can save you from a mandatory dancing on this mine-field ).


How it can be solved?

If I were in your situation, I would ask the Project Manager / Project Sponsor to state what is the available budget, time constraint and Customer preference for creating such a universal code-convertor.

If feasible, I would launch a new Project with such given Time Schedule / Work-force / Budget and acquire an independent Project Management and Cost Control thereof.

If not feasible, I would ask the Project Steering Committee to redefine metrics and update and publish adapted Project Plan / Work-force / Schedule / Budget for the code-base conversion task to be performed without an automated tool.

user3666197
  • 1
  • 6
  • 50
  • 92
  • Hi user3666197. What is the meaning of `man*years`? You're [using this construction](https://stackoverflow.com/search?tab=newest&q=user%3a3666197%20%22man*years%22) a great deal, but I am not familiar with it. I think it should be treated as a typo or mis-spelling. – halfer May 24 '17 at 13:12
  • You've asked about [subscript and superscript](https://en.wikipedia.org/wiki/Subscript_and_superscript) in your edit remarks. This is often used for numerical powers, chemical symbols, mathematical variables, etc, and it is generally distracting to use them for an "aside", since it disturbs the line that characters sit on. Parenthesis are better for that. See the wiki article: "In professional typography, subscript and superscript characters are not simply ordinary characters reduced in size". – halfer May 24 '17 at 13:15
  • After some 30 years in Project Management & Consulting domains, man*year has been for ages standard Unit-of-Measure in RFP / RFQ, SoW, invoices and similar documents. As per the typography, forget about math indices, the question was **"... could you enlighten me -- where is subscript / superscript as per your own opinion (cit.) "appropriate" typesetting form??"** -- so **when** is one -- upon your personal opinion -- fair to set some part of the intended text as a subscript / superscript? Deleting an intended typographical feature is possible, but if having no rational reason for that? – user3666197 May 24 '17 at 13:45
  • Thanks for the reply. I think I've answered that question, about sub/super already. I've just worked out that `man*years` uses the asterisk as a multiplier, i.e. person times time. At least that makes some sense, though that usage is not obvious - I thought that perhaps the asterisk was a wildcard. However, it is [not mentioned on Wikipedia](https://en.wikipedia.org/wiki/Man-hour), and as such is probably rather esoteric. – halfer May 24 '17 at 13:59
  • Maybe it is a time to realise, the World does not live by the Wikipedia, does it? – user3666197 May 24 '17 at 14:17
  • I'd be happy to see any other references. I don't want you to feel a sense of obligation, but perhaps in the spirit of improving readability - which we both care about - do you have any links? I tried to search, but asterisks don't perform well in search engines. – halfer May 24 '17 at 14:21