Speeding up script

 

Hi all, I'm wondering if imports and includes are all done at the start of a file, or done when they are first needed? 

I have a script that places an immediate buy or sell order with OrderSend, then uses OrderModifty to add stops, and finally after the dust as settled, uses the imported functions to print all the useful figures to a .csv file (outside the metatrader 'files' folder). These functions are needed for the file writing but do the slow the order placement at all?

As mentioned in another post, the lots are calculated in accordance with my risk tolerance and stoploss settings and slippage throws these numbers off a bit, so if I can make the script faster.. great.

 The head looks like this: 

#define OF_READ               0
#define OF_WRITE              1
#define OF_READWRITE          2
#define OF_SHARE_COMPAT       3
#define OF_SHARE_DENY_NONE    4
#define OF_SHARE_DENY_READ    5
#define OF_SHARE_DENY_WRITE   6
#define OF_SHARE_EXCLUSIVE    7
 
 
#import "kernel32.dll"
   int _lopen  (string path, int of);
   int _lcreat (string path, int attrib);
   int _llseek (int handle, int offset, int origin);
//   int _lread  (int handle, string buffer, int bytes);
   int _lwrite (int handle, string buffer, int bytes);
   int _lclose (int handle);
   int CreateDirectoryA(string path, int atrr[]);
//   bool DeleteFileA(string lpFileName);
//   void OutputDebugStringA(string msg);
#import

#include <stderror.mqh>
#include <stdlib.mqh> //for printing error message desription
 
alladir: Hi all, I'm wondering if imports and includes are all done at the start of a file, or done when they are first needed?
Neither, they are used during compile time, and when the script is loaded the DLL is loaded if not already in memory.
 
WHRoeder:
Neither, they are used during compile time, and when the script is loaded the DLL is loaded if not already in memory.


Ah excellent,

As regards loading the DLL, does that mean the first time I run the script (after starting MT4 or after a reboot or something) will be slower than the next times? Could I run a dummy version of the same script to load up the dll before trading?

I know this is get a bit ridiculous now, I'm just curious. 

 
WHRoeder:
Neither, they are used during compile time, and when the script is loaded the DLL is loaded if not already in memory.

This is not true, read the documentation :

To import functions during execution of an mql4 program, the so-called late binding is used. This means that, until the imported function is called, the corresponding module (ex4 or dll) will not be loaded.

 
angevoyageur:

This is not true, read the documentation :



Even better, so I can put as much rubbish as I want in the header and it won't slow the OrderSent at the start.. :]
Reason: