DLL files - usage of dynamic link library files

The NeTtradeX Language (NTL+) supports DLL files. These could be user-created DLL files as well as standard DLL files supplied with OS Windows (for example, user32.dll or kernel32.dll). Thanks to the fact that DLL functions are machine code, their usage significantly increases execution speed, for instance, in complex calculations. Functions used in a DLL from a script must follow the linkage convention adopted for Windows API functions. To comply with this convention in the initial program code, written either in the C or C++ language, the keyword __stdcall is used, which is specific to Microsoft compilers.

To start working with library files, it is necessary to place user DLL files in the folder username\Documents\NeTTradeX Advisors\scripts\libraries. It is not required to place system DLL files (for instance, user32.dll) in that folder.

One should create a dll type object in the script editor. This could be done as follows: dll arbitrary_identifier("path_and_filename"). All the paths to DLL files (except for system ones) should be specified relative to the folder username\Documents\NeTTradeX Advisors\scripts\libraries.

The function is called from a specified library by means of the Call and CallProc methods. The difference between the methods is the following: when a function from a library returns an int value, the Call method is used; when a function does not return any value (void), the CallProc method is used.

Let us assume that we have created an object dll mydll("test.dll") and there is a function int func(int a, int b) in the library that we want to utilize. The call of that function in code will be mydll.Call("func",a,b).

As variables of bool, int8 and int16 types are sent to a library file, they are converted to the int type (int32 is a synonym for int).

Let us demonstrate how a message could be shown to a user with the help of the standard user32.dll library. While the script is launching, you should put a tick mark against Allow DLL usage option on the Common tab of the advisor's properties. This advisor will save the current price at the moment of launching and, afterwards, if the price has risen by more than 20 pips, the advisor will show the message "The price has gone up", and if it has dropped by 20 pips - "The price has gone down".

 #define MB_OK 0x00000000 #define MB_ICONEXCLAMATION 0x00000030 bool priceLevelIsSet = false; double price; int Run() { if(priceLevelIsSet == false) { price = Symbols.LastBid(Chart.Symbol); System.Print("Price level = "+price); priceLevelIsSet = true; } dll _dll("user32.dll"); if(Symbols.LastBid(Chart.Symbol)>price + 20*Chart.Point) { _dll.CallProc("MessageBoxA",0,"The price has gone up","Notification",MB_OK|MB_ICONEXCLAMATION); return -1; } if(Symbols.LastBid(Chart.Symbol)<price - 20*Chart.Point) { _dll.CallProc("MessageBoxA",0,"The price has gone down","Notification",MB_OK|MB_ICONEXCLAMATION); return -1; } return(0); }