MQL5 call/run javascript or bash or other external code

 

Hello all.  New here.  First post.  Would love some help on this if anyone can advise...

I've written the guts of a complex strategy in Javascript (node).  It takes some input parameters, and returns some output.

To implement all this in MT5, I could try to translate it all into MQL5 code.  Or if ther e's any way to do this, I could just call the Javascript code from MQL5, passing it the required inputs and receiving back the desired outputs, and then act on those results in MT5.

Is this possible? 

Most programming languages (including C++) have the ability to call shell scripts or code in other languages.  Is there any way MQLO5 can do this?

Thanks in advance for any direction!

 

I'm kind of thinking that I could write an EA with the usual event handling functions [onInit(), onDeInit(), onTick(), etc.] with the minimum code for defining the buffers and other essential variables, but then for each of those functions, call a shell script, or a node script, or whatever else, to do all the calculations and return results that I then store in the buffers and exit/return.

Something like that.  But open to any suggestions or advice, essentially on how to make use of the JS code I've already written without having to translate it to MQL5.

 

The environment is basically sandboxed for security reasons but there are several methods that you can use to set up bridging.

You can connect to python see here https://www.mql5.com/en/docs/integration/python_metatrader5

Or you can read and write to/from a file and have node pick it up and respond.

You can also work over a socket or use calls to external system api.

It all depends on what you want to achieve and the requirements it has to meet.

Documentation on MQL5: Integration / MetaTrader for Python
Documentation on MQL5: Integration / MetaTrader for Python
  • www.mql5.com
MetaTrader for Python - Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Marco vd Heijden #:

The environment is basically sandboxed for security reasons but there are several methods that you can use to set up bridging.

You can connect to python see here https://www.mql5.com/en/docs/integration/python_metatrader5

Or you can read and write to/from a file and have node pick it up and respond.

You can also work over a socket or use calls to external system api.

It all depends on what you want to achieve and the requirements it has to meet.

Hi.  Thanks for the reply!  


At first glance, this doesn't look particularly helpful to my specific situation, but that's just first glance.  I'll look a bit deeper in case I've missed anything.  Thanks for the tip.


... use calls to external system api.

This sounds promising.  Could I trouble you to elaborate on that?


It all depends on what you want to achieve and the requirements it has to meet.

Ok, let's go with what I think should be the simplest...  Let's say I want my MQL5 EA or Indicator to perform a shell command or run a shell script, with arguments, and get back a result it can act on (because if I can do that, I pretty much know how to do anything else with that).

A shell command can run a script that can echo/log/print to stdout. Most languages I've used can synchronously perform a shell command or run a shell script, wait for it to run and generate its result, which it would normally write to stdout if executed in a terminal/command line, but instead returns it back to the calling program (which in this case if it's possible will be my MQL5 EA or Indicator) for that to act on.

Does that cover enough for "what [I] want to achieve and the requirements it has to  meet"?  And if so, what might be one or more best ways to do that?

(I don't think "read and write to/from a file and have node pick it up and respond" will work well for me, unless it's the only way.  My node scripts aren't the type that have node running all the time waiting for some event to act on.  They're more like standard shell executables that I call with:

node myScript.js arg1 arg2 etc

They take arguments, process something, and echo back a result, just like most shell/bash/etc commands/programs, but happen to be written in JS and using node as their env instead of sh, bash, or whatever else.)

Hope this helps, and hope you/someone can help further.  Thanks again!

 

If you could do that you could pretty much take over a users entire computer and use it to do whatever you want with it.

Making calls to the operating system is also operating system dependent so you have to code it specifically for the target machine.

//+------------------------------------------------------------------+
//|                                             ShellExecuteTest.mq4 |
//|                      Copyright c 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright c 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#property version   "1.00"

#import "shell32.dll"
int ShellExecuteW(int hwnd,const string Operation,const string File,const string Parameters,const string Directory,int ShowCmd);
#import

void OnStart()
{
   int r = ShellExecuteW(0,NULL,"C:\\windows\\notepad.exe",NULL,NULL,5);
   Print("Shell",r);
}

You can use the search function to find use cases for various dll cases.

 
Marco vd Heijden #:

If you could do that you could pretty much take over a users entire computer and use it to do whatever you want with it.

Making calls to the operating system is also operating system dependent so you have to code it specifically for the target machine.

You can use the search function to find use cases for various dll cases.

Hi again. First of all, apologies.  I thought I posted a reply here a week ago thanking you for the information and suggestions.  In fact I'm sure of it.  But I see no record of it here, so I must have screwed something up there.

Meanwhile, I've had a look at what you've suggested, but, not surprisingly that particular code is not going to work for me, as I'm running this on a Mac -- like you said, operating system dependent.  I've tried to research how to do more or less the same on Mac in MQL, but I'm coming up empty.

Agreed there are security concerns, but my use case is entirely internal, on machines I have control over and can give the required security permissions needed, so no security concerns for me.  So assuming I give it the appropriate permissions/authorization, can the Mac version of MT4 and/or 5  (which is really the Windows version running in a Mac Wine/Crossover "bottle") talk to the Mac shell, or AppleEvents, or any other Mac app?  

In short: how does one do on a Mac what you've illustrated can be done on Windows?

Thanks!

PS. I started this looking only at MT5, but now wanting to do this on MT4 as well, so preferably looking for guidance compatible with both.

ShellExecute not in docs
ShellExecute not in docs
  • 2015.08.18
  • www.mql5.com
Hello I've recently found ShellExecuteA and W. qs: 1. Why are these not in any of the documentation categories except Forum? i.e...