ViniciusArruda
ViniciusArruda

Reputation: 990

Alternative to MQL5

I am starting with Expert Advisors on MetaTrader Terminal software and I have many algorithms to use with it. These algorithms were developed in MATLAB using its powerfull built in functions ( e.g. svd, pinv, fft ). To test my algorithms I have some alternatives:

  1. Write all the algorithms in MQL5.
  2. Write the algorithms in C++ and than make a DLL to call by MQL5.
  3. Write the algorithms in Python to embed in C and than make a DLL.
  4. Convert the MATLAB source code to C and than make a DLL.

About the problems:

  1. Impracticable because MQL5 does not have built in functions so I will have to implement one by one by hand.
  2. I still did not try this, but I think it will take a long time to implement the algorithms ( I wrote some algorithms in C but took a good time and the result wasn't fast like MATLAB ).
  3. I am getting a lot of errors when compiling to a DLL but if I compile to an executable there is no error ( this would be a good alternative since to convert MATLAB to python is quite simple and fast to do ).
  4. I am trying this now, but I think there is so much work to do.

I researched about other similar pieces of software, like MetaTrader Terminal but I didn't found a good one.

I would like to know, if there is a simplest ( and fast ) way to embed other language in some way to MQL5 or some alternative to my issue.

Thanks.

Upvotes: 0

Views: 2600

Answers (2)

Sean Champ
Sean Champ

Reputation: 361

MetaTrader 5 offers support for OpenCL and DirectX.

In 2020, Sergey Golubev published an outline of introductory articles for OpenCL support in MetaTrader 5, at the MQL forums. Compared to an implementation singularly in MQL, perhaps the OpenCL subsystem may provide for a more computationally optimized approach towards implementing any more relatively math- and data-intensive technical analysis methods in MT5. There's also support for Python, of course.

Though I haven't been able to work with it directly, as yet, I believe that the OpenCL support is implemented with a second programming language supplementing MQL5, mainly a programming language for OpenCL. From the examples, it looks quite similar to C. I'm sure that there must be a number of books, expanding on the topic.

In MQL5, it seems that the OpenCL programs can be provided to the OpenCL driver subsystem using literal strings in the MQL program, or via separate source files.

For more complex graphics, there's also support for DirectX as well as an API for chart objects in MetaTrader 5.

As one idea, perhaps these APIs could be of use for a port of the heat map indicators illustrated by John F. Ehlers, such as in Ehlers' book, Cycle Analytics for Traders, furthermore discussed in the Technical Papers published by John F. Ehlers at the MESA Software Web site. These examples are implemented mainly in the TradeStation EasyLanguage.

Given the examples in the book and in the articles - as compared to the perhaps more common, commonly more moving-average-based and more directly price-based indicator methods, such as with Welles Wilder's ADX - most of these newer examples may be relatively math-intensive to program, using a number of trigonometric transformations for instance. Given one of the more data-intensive autocorrelation examples using "line drawing", while it may be simple enough to be implemented in MQL4, but - in at least one approach - it may sort of bog the terminal down in MQL4 with an otherwise straightforward operation on a 2x48 array of double typed values. I'm working on porting this, at present, as a part of a broader codebase in MQL4. Hopefully it can be ported to MQL5 and OpenCL, given at least one approach in an earlier edition of the MQL language.

For new projects, there's the documentation and the examples available?

Porting from MQL4 would be a whole other topic, LoL, ostensibly a short process though.

Upvotes: 0

user3666197
user3666197

Reputation: 1

Yes, there is alternative ... 5 ) Go Distributed :

having a similar motivation for using non-MQL4 code for fast & complex mathematics in external quantitative models for FX-trading, I have started to use both { MATLAB | python | ... } and MetaTrader Terminal environments in an interconnected form of a heterogeneous distributed processing system.

MQL4 part is responsible for:

  1. anAsyncFxMarketEventFLOW processing
  2. aZmqInteractionFRAMEWORK setup and participation in message-patterns handling
  3. anFxTradeManagementPOLICY processing
  4. anFxTradeDetectorPolicyREQUESTOR sending analysis RQST-s to remote AI/ML-predictor
  5. anFxTradeEntryPolicyEXECUTOR processing upon remote node(s) indication(s)

{ MATLAB | python | ... } part is responsible for:

  1. aZmqInteractionFRAMEWORK setup and participation in message-patterns handling

  2. anFxTradeDetectorPolicyPROCESSOR receiving & processing analysis RQST-s to from remote { MQL4 | ... } -requestor

  3. anFxTradeEntryPolicyREQUESTOR sending trade entry requests to remote { MQL4 | other-platform | ... }-market-interfacing-node(s)

Why to start thinking in a Distributed way?

The core advantage is in re-using the strengths of MATLAB and other COTS AI/ML-packages, without any need to reverse engineer the still creeping MQL4 interfacing options ( yes, in the last few years, DLL-interfaces had several dirty hits from newer updates ( strings ceased to be strings and started to become a struct (!!!) etc. -- many man*years of pain with a code-base under maintenance, so there is some un-forgettable experience what ought be avoided ... ).

The next advantage is to become able to add failure-resilience. A distributed system can work in ( 1 + N ) protected shading.

The next advantage is to become able to increase performance. A distributed system can provide a pool of processors - be it in a { SEQ | PAR }-mode of operations ( a pipeline-process or a parallel-form process execution ).


MATLAB node just joins:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MATLAB script to setup 

zeromq-matlab
clear all;
if ~ispc
    s1 = zmq( 'subscribe', 'ipc', 'MATLAB' );   %% using IPC transport on <localhost>
else
    disp( '0MQ IPC not supported on Windows.' )
    disp( 'Setup TCP transport class instead' )
    disp( 'Setting up TCP')                     %% using TCP transport on <localhost>
    s1 = zmq( 'subscribe', 'tcp', 'localhost', 5555 );
end

recv_data1 = [];                                %% setup RECV buffer

This said, one can preserve strengths on each side and avoid any form of duplications of already implemented native, high-performance tuned, libraries, while the distributed mode of operations also adds some brand new potential benefits for Expert Advisor modus operandi.


A Distributed System, on top of a Communication Framework:

MATLAB has already available port of ZeroMQ Communication Framework, the same that MetaTrader Terminal has, thanks to Austin CONRAD's wrapper ( though the MQH is interfacing to a ver 2.1.11 DLL, the services needed work like a charm ), so you are straight ready to use it on each side, so these types of nodes are ready to join their respective roles in any form one can design into a truly heterogeneous distributed system.

enter image description here

My recent R&D uses several instances of python-side processes to operate AI/ML-predictor, r/KBD, r/RealTimeANALYSER and a centralised r/LOG services, that are actively used, over many PUSH/PULL + XREQ/XREP + PUB/SUB Scalable Formal Communication Patterns, from several instances of MetaTrader Terminal-s by their respective MQL4-code.

MATLAB functions could be re-used in the same way.

Upvotes: 1

Related Questions