Discussion of article "MetaTrader 5 and MATLAB Interaction"

 

New article MetaTrader 5 and MATLAB Interaction is published:

This article covers the details of interaction between MetaTrader 5 and MatLab mathematical package. It shows the mechanism of data conversion, the process of developing a universal library to interact with MatLab desktop. It also covers the use of DLL generated by MatLab environment. This article is intended for experienced readers, who know C++ and MQL5.

Author: Andrey Emelyanov

 

I've followed your directions carefully but I'm unable to get this working with Matlab 2007b. I continuously get these errors, when trying to use your prebuilt examples, with the MT5 Terminal.

 2010.08.29 10:33:30 TestMLEngine (EURUSD,H1) Cannot open 'C:\Users\QuantFX\AppData\Roaming\MetaQuotes\Terminal\216E2BD2BB8CE60176A41ADF6AC1C76D\MQL5\Libraries\LibMlEngine.dll' (126)

 2010.08.29 10:33:47 TestDllMatlab (EURUSD,H1) Cannot open 'C:\Users\QuantFX\AppData\Roaming\MetaQuotes\Terminal\216E2BD2BB8CE60176A41ADF6AC1C76D\MQL5\Libraries\nnSMA.dll' (126)

I don't really know what to think of it becuase I'm able to get the project mentioned in the article   "How to Exchange Data: A DLL for MQL5 in 10 Minutes " found here https://www.mql5.com/en/articles/18 working without any problems. 

 2010.08.29 10:44:16 MQL5DLL_Test (EURUSD,H1) Access violation write to 0x00000000 in 'C:\Users\QuantFX\AppData\Roaming\MetaQuotes\Terminal\216E2BD2BB8CE60176A41ADF6AC1C76D\MQL5\Libraries\MQL5DLLSamples.dll'

2010.08.29 10:44:16 MQL5DLL_Test (EURUSD,H1) Replace: A quick brown cat jumps over the lazy dog

2010.08.29 10:44:16 MQL5DLL_Test (EURUSD,H1) Array: 0 1 2 3 4 5 6 7 8 9
2010.08.29 10:44:16 MQL5DLL_Test (EURUSD,H1) Time 297 msec, int: -752584127 double: 17247836076609

 So the terminal obvioulsy has no problems with access violations to the \Libraries folder, and I'm certain the Expert Advisor "Options" allow for dll imports and autotrading...Any help would be greatly appreciated because I've been stumped by this since first reading this article. Thanks In Advance

How to Exchange Data: A DLL for MQL5 in 10 Minutes
  • 2010.01.27
  • MetaQuotes Software Corp.
  • www.mql5.com
Now not so many developers remember how to write a simple DLL, and what are special features of different system binding. Using several examples, I will try to show the entire process of the simple DLL's creation in 10 minutes, as well as to discuss some technical details of our binding implementation. I will show the step-by-step process of DLL creation in Visual Studio with examples of exchanging different types of variables (numbers, arrays, strings, etc.). Besides I will explain how to protect your client terminal from crashes in custom DLLs.
 

Finally got this working...Excellent article I must say. I'm not highly experienced with Visual Studio and I'm a newbie to metatrader programming. So, this seemed somewhat of a challenge with all the errors I was recieving. Although it is very easy in the long run for all versions of matlab and visual studio. Anyone who is making their first attempts at connecting Metatrader and Matlab together I suggest do the following to gain insight, if you never have worked with matlab engine or metatrader external libraries. 1. Create the project that comes with matlab found in matlabroot\externs\examples\eng_mat\engwindemo.c by following this article. http://www.mathworks.com/support/solutions/en/data/1-78077S/index.html?product=ML&solution=1-78077S Compile it, and should you have problems, like missing dll files, use dependency walker, found here http://www.dependencywalker.com/ to determine what missing files need to be placed in your C:\Windows\System 32 folder in order to get the version of matlab engine you are using to work.  It might be good to note that you may end up having to put alot files in your system 32 folder,or know the right places to link them at in your project. Although most dll's are found in your matlabroot\bin\win(32 or 64) folder. After you've put in the first few dll files needed go back and try to build your project again. You might find that you don't need to do everything that dependency walker suggests. If you get the project to compile and run then your're almost done... 2. Build the project suggested in the article How to Exchange Data: A DLL for MQL5 in 10 Minutes   https://www.mql5.com/en/articles/18 . If you get that project working then just rememebr as you create the project above you're combining the two. Remember all the steps you followed and when you're ready to compile this project make sure "stdafx.h" is the first #include header in DLLUnit.cpp, and you have turned off precompiled headers, just before building.  Using the files above as is may give some warnings that are easily fixable, but the project should work without any hassle. My added two cents here may sound like the dummie's guide to this project, but doing those things may save you a couple hours of your spare time if you needed to build this project with another version of matlab or use visual studio.

 

Cheers 

 

Hello,

Has anyone got 3.1 Developing Universal Library of MetaTrader 5 & MATLAB Engine Interaction works with Strategy Tester?

It works with standard expert advisor, but not with strategy tester. Can anybody point me where I may have done it wrong?

 

Will this work also for MT4 ??? Or it is exclusively setup for MT5 ??

Krzysztof

 

I found a little bug in UnitDll.cpp

Its better to check  with OR and not AND

So you cant send a command to a closed Engine



bool __stdcall mlxInputChar(char *CharArray)
{//100% ready. Function of passing command/function/text to desktop
	/*
	** Check if virtual machine and string are present
	*/
----> // Original with Bug -> if((pEng == NULL)&&(strlen(CharArray)<1)) return false;        <---
	if ((pEng == NULL) || (strlen(CharArray)<1)) return false;
	/*
	** Enter formula into MATLAB desktop
	*/
	engEvalString((Engine *)pEng, CharArray);
	return true;
}
Reason: