简体   繁体   English

如何将MQL4代码转换为C ++ / Delphi DLL(Forex Tester API)?

[英]How to convert MQL4 code into C ++ / Delphi DLL (Forex Tester API)?

I need to create an automatic code converter 我需要创建一个自动代码转换器
from MQL4 API ( a C-like language ) 来自MQL4 API (一种C语言)
into Forex Tester API ( C++ / Delphi DLL ). 进入Forex Tester API (C ++ / Delphi DLL )。

There are suggestions that it can be done with the help of ANTLR and MMVP . 有建议可以通过ANTLRMMVP来完成。 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. 如果您不知道如何使用ANTLRMMVP完成我的任务,请建议其他技术。

Here is an example of a simple MQL4 program. 这是一个简单的MQL4程序的示例。

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. 用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

You were recommended to use ANTLR / MMVP for your Task ? 建议您为任务使用ANTLR / MMVP?

Well, the core issue is not hidden in the ANTLR kind of tools' capabilities. 好吧,核心问题并没有隐藏在ANTLR工具的功能中。

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. 我花了一些时间进行研究,如果ANTLR可以“保存”我们的IDE的代码库问题(不是默认的MetaLang,而是另一个使用更灵活,可配置和可编程的IDE),则仍然无法解决语法错误。在多级注释源代码中进行花括号匹配。

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. 尽管ANTLR毫无疑问是一匹非常强大的马,但人们会花很多时间在窄带领域专攻使用这种通用语言建模和抽象语法树建模知识。

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. Lexers可能对此有所帮助。


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. 我喜欢您的想法,即基于目标API服务在C ++端创建代理层,以便在MQL4-> Forex Tester行进路线的更灵活的部分上调解缺失的行为。

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. 在MQL4的美好时光(当时确实是MQL4,而不是“ New” -hybrid),我出于类似的目的但出于不同的动机而开发了一些语法包装器,其中普通的和简单的MQL4概念是不可行的保持无助。

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 | MetaTrader Terminal 4中作为MQL4程序类型的代码执行生态系统可用的主要架构和不同的modi操作的正确理解。 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. 如果您决定详细说明从MQL4- DSL域到另一个DSL域的代码转换,那么}只是该方法的开始。


The final nail into the coffin ... syntax creeps in New-MQL4.56789 棺材的最后钉子……语法在New-MQL4.56789中蔓延

It is hard not to mention that recent years MQL4 started to become a very different language. 值得一提的是,近年来MQL4开始成为一种非常不同的语言。

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 ). 简而言之,尽管关键概念并没有经常变动,但每个新版本的MetaTrader Terminal 4作为代码执行生态系统或MetaEditor作为半集成代码编译工具链}(以前称为MetaLang.exe( New-MQL4.56789 ...)(尽管两者都是由自己控制的,即使是由代理方操作的策略强制执行“强制更新”,因此,进行任何特定的“版本冻结”都无法使您摆脱困境在此雷场上进行强制性跳舞)。


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. 如果不可行,我将请项目指导委员会重新定义指标,并更新和发布调整后的项目计划/劳动力/进度/预算,以便在没有自动化工具的情况下执行代码库转换任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM