Reputation: 21
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
Upvotes: 1
Views: 3928
Reputation: 1
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.
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.
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.
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 ).
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.
Upvotes: 2