Run a script outside Metatrader?

 

Hi all,


Is it possible to run a script outside metatrader, eg from vba?


Rgds

 
Surreall:

Hi all,


Is it possible to run a script outside metatrader, eg from vba?

Of course,  you can run a VBA script in Windows . . .  what does this have to do with MT4 or mql4 ?  if you want to run a script written in mql4 you need to run it in MT4.
 
RaptorUK:
Of course,  you can run a VBA script in Windows . . .  what does this have to do with MT4 or mql4 ?  if you want to run a script written in mql4 you need to run it in MT4.


My apologies i wasnt very clear, can i run a mt4 script from vba?
 
Surreall: My apologies i wasnt very clear, can i run a mt4 script from vba?
Start the script.
#include <WinUser32.mqh>
#import "user32.dll"
  int GetAncestor(int, int);
#import
 bool Shell(string file, string parameters=""){
    #define DEFDIRECTORY NULL
    #define OPERATION "open"    // or print
    #define SW_SHOWNORMAL       1
    int r=ShellExecuteA(0, OPERATION, file, parameters, DEFDIRECTORY, SW_SHOWNORMAL);
    if (r <= 32){   Alert("Shell failed: ", r); return(false);  }
    return(true);
}

Figure out when it has completed is up to you.

Such as A DLL-free solution to communicate between MetaTrader 5 terminals using Named Pipes - MQL5 Articles and Named Pipes Client in MQL4 and Server in C++ - MQL4 forum

There was also a post/article about create process call and reading the result from the pipe.

 
William Roeder:
Start the script.

Figure out when it has completed is up to you.

Such as A DLL-free solution to communicate between MetaTrader 5 terminals using Named Pipes - MQL5 Articles and Named Pipes Client in MQL4 and Server in C++ - MQL4 forum

There was also a post/article about create process call and reading the result from the pipe.


Hi,

I'm trying to get mt4 Data into Excel,
& i have a mt4 Script that writes the CSV files i need. (see attached)
- But i'm wanting to run the script from a vba excel command.

( i'm to new to it right now for deep troubleshooting and trying to get the basic functionality running.)

I'm wondering if you (or someone else with insight) can provide some direction.

- If i add this code at the beginning of the mt4 script, how do i call it with VBA/ CMD prompt?

Regards,
 
mackiebthatsme: I'm trying to get mt4 Data into Excel, & i have a mt4 Script that writes the CSV files i need. (see attached) - But i'm wanting to run the script from a vba excel command. ( i'm to new to it right now for deep troubleshooting and trying to get the basic functionality running.) I'm wondering if you (or someone else with insight) can provide some direction. - If i add this code at the beginning of the mt4 script, how do i call it with VBA/ CMD prompt?

Read the documentation on launching a Script in MetaTrader 4 via the command line configuration file.

Configuration at Startup - Tools - MetaTrader 4 Help
Configuration at Startup - Tools - MetaTrader 4 Help
  • www.metatrader4.com
The client terminal can be launched with some predefined settings. For this purpose, the configuration file name will be passed to the client...
 
Fernando Carreiro:

Thank you

 
mackiebthatsme: Thank you

You are welcome!

 
Fernando Carreiro:

Read the documentation on launching a Script in MetaTrader 4 via the command line configuration file.


Hi,
I can get this process to open the terminal, and run the script on start up.
but that it, i can only get it to run once once.
(without closing the terminal manually & repeating the cmd process)


Do you have any ideas on how i can run the script multiple times (with the cmd prompt), while the terminal remains open?


*My Plan B, is to run the script on timed loop, but i'd rather call it manually with the vba / cmd process
- i am researching the named pipe solution solution also, but not clear on it yet

any ideas appreciated,
thx
 
mackiebthatsmeI can get this process to open the terminal, and run the script on start up. but that it, i can only get it to run once once. (without closing the terminal manually & repeating the cmd process) Do you have any ideas on how i can run the script multiple times (with the cmd prompt), while the terminal remains open? *I may need to run the script on timed loop, but i'd rather call it manually with the vba / cmd process any ideas appreciated,

There is no perfect solution.

  • Either have the Script close the MetaTrader terminal via WinAPI calls.
  • Or instead of a Script, make an Expert that constantly monitors an external source to serve as a signal to proceed with exporting the data. In other words use IPC - Inter Process Communications (e.g. responding to Windows Messaging with the OnChartEvent handler, or monitor for file existence on regular interval with the OnTimer handler, or other forms of IPC).
In either way, you should do more research into how MetaTrader works and how to properly code things in MQL4.
 
Fernando Carreiro:

thx, i will work towards it.

Reason: