MQL4 -gt R-Project - Interface Library
Page 1 of 6118 12311 ... LastLast
Results 1 to 10 of 175

Thread: MQL4 -gt R-Project - Interface Library

  1. #1
    2 Attachment(s) [Keywords: mt4R.dll, mt4R.mqh, R, Metatrader]

    Hello,

    maybe some of you want to experiment with my own MT4 R interface which allows one to begin as numerous R sessions (usually one per running EA), transfer data forth and back and call R functions. The R sessions will be conducted as separate processes in the background however, the API towards mql4 are synchronous function calls, writing and polling files. Communiion goes via stdio pipes to and from each of the R procedures.

    Within this .zip file are the needed files (mt4R.mqh and mt4R.dll) for running this item. The .mhq file also includes all API documentation and other necessary information.
    Https://www.nigeriaforextrading.com/...big-bucks.html

    And optionally for those considering how the DLL functions below is the dll source code (it requires FPC 2.4.2 or newer to compile. You need to put in a current snapshot of Lazarus/FPC with a 2.4.3 compiler, you'll discover a current snapshot installer (IDE and Compiler in 1 bundle ) for win32 on ftp://ftp.freepascal.org/pub/lazarus/snapshots/):).

    Here is the source:
    https://www.nigeriaforextrading.com/...weblogger.html

    The aforementioned documents are upgraded to the Most Recent version. Forget the preview files in place they are old.

  2. #2
    I just noticed that it'll leak a thread handle on each call to RExecuteAsync(), this really is an issue if you leave it running for a few days. The main reason is I had been too lazy to use the TThread class as it would have been the recommended way but rather quickly hacked a BeginThread() into my current code without even caring about the thread handle afterwards. I am preparing a new release which will fix this issue.

  3. #3
    Quote Originally Posted by ;
    I'm now preparing a new release which will fix this issue.
    Uploaded new variant 1.2.0.36 which fixes this issue.

  4. #4
    Quote Originally Posted by ;
    Uploaded new variant 1.2.0.36 which fixes this issue.
    Thanks Bernd!

  5. #5
    7bit,

    is there a way to use this port under Linux running Metatrader using Wine?

  6. #6
    Quote Originally Posted by ;
    ,

    is there a way to utilize this interface under Linux running Metatrader with Wine?
    I haven't tested it. It will (since it assumes it is running in windows) attempt to start (with the help of wine) the windows* executable ~/.wine/drice_c/.../rterm.exe (not /usr/bin/R) since inside the wine surroundings it has no idea that there could exist anything out ~/.wine/ (and the way such a strange alien universe [the OS that lives outside] might look like function) and that is the reason the wine execution of the windows API CreateProcess() could not start indigenous linux executables anyways, even though it had the correct path name. It could not cross this border.

    You'll have to put in the windows version of R in wine and it should theoretically work. (untested but this is the way it should work in theory).

  7. #7
    You are the usual genius... I had been doing so with sockets so far, and I am sorry for all of the dual to char array conversions I forced my cpu to carry out.
    Cant wait to check this, thanks.

  8. #8
    Quote Originally Posted by ;
    you are the usual genius... I had been doing so with sockets so far, and I am sorry for all the dual to char array conversions I forced my cpu to carry out.
    Cant wait to test this, thanks.
    There are still dual to char and char to dual conversions for vectors, only in the event that you move a matrix it will compose the whole raw memory block because it's into a temp file and then read.bin() with R. Nonetheless, as there is absolutely no polling 11, it's fairly fast and the temp file writing is so quickly that the majority of it occurs in the file cache only.

    The typical roundtrip time for a simple RExecute() is ~300µs on my slow laptop. (measured using a separate .exe that loads my dll, maybe not with mql4)

  9. #9
    Quote Originally Posted by ;
    There continue to be dual to char and char to dual conversions for vectors, only in the event that you move a matrix it will write the whole raw memory block as it is to a temp file and then read.bin() together with R. But as there is absolutely no polling involved it is fairly fast and also the temp file writing is so fast that most of it occurs in the file cache just.

    The typical roundtrip time to get a simple RExecute() is 300µs on my slow laptop.
    Oh well, I suppose we could always try using the writetobinary/readBin mechanism for passing vectors too, but it feels like we all have more cpus than we need these days.

    You should take a look in the tcltk / tcltk2 packs for R; they have some sort of timer mechanism that runs in a different R ribbon -- you can use it to execute dummy R calls in fixed intervals so your R graphics windows dont block.

  10. #10
    Quote Originally Posted by ;
    you should look into the tcltk / tcltk2 packs for R; they still have some type of timer mechanism that runs in another R thread -- you could use it in order to execute dummy R calls in fixed intervals so that your R graphics windows dont block.
    I could do this straight from my DLL (I already have the locking mechanism along with the thread that waits for the result of RExecuteAsync() to release the lock again, so this would not be much work. I'll apply it.

    PS: I just made some measurements with mql4 along with the next code:
    Inserted Code for(I=0; ilt;100000; I ) RExecute(R, ); needs 14 seconds, this means 140µs each RExecute(). Should I do something like
    Inserted Code for(I=0; ilt;100000; I ) RGetInteger(R, 1 1); which translates to
    Inserted Code as.integer(1 1) it requires 20 seconds (200µs per call).

    The next assigns the exact same 100 component vector 100000 times:
    Inserted Code double foo#91;100#93;; int I; ArrayInitialize(foo, 1.0/3); // odd amounts, long strings with 15 digits log(Start); for(I=0; ilt;100000; I ) RAssignVector(R, foo, foo, 100); log(End); needs 208 seconds (2.08 ms each vector). That remains 500 vectors or 50000 drops or roughly 0.8 Megabytes per second ascii information that's going through the pipe.

    The same as above but each* vector as matrix: (transfer via file 10000 times create compose as.matrix(readBin()) delete)

    Inserted Code double foo#91;100#93;; int I; ArrayInitialize(foo, 1.0/3); // odd amounts, long strings with 15 digits log(Start); for(I=0; ilt;100000; I ) RAssignMatrix(R, foo, foo, 100, 1); // 100 rows, 1 column log(End); 582 moments (5.8ms each vector (each being a file of 800 byte))

    (Of course this is simply a stupid benchmark. When I had delegated a matrix of 100 x 100000 this would be only 1 control and one temp file of 80MB (8 bytes per double) and be accomplished in a couple of seconds.)

    These amounts are from an old Pentium-M running in 1300MHz and wndows is operating within a virtualbox.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.