Conversion of scripts from MetaTrader 4 on NetTradeX Advisors

Introduction

A great number of advisors and scripts have been created for MetaTrader 4 trading platform. Before, those traders who wanted to use these scripts on NetTradeX platform, needed to fully process the source code, which took much time. To facilitate this task a library has been created for compatibility of MQL4 and NTL+ languages. That library allows simplifying the conversion process of scripts into NTL+ language for their subsequent launching in NetTradeX Advisors terminal. Because of the differences between MetaTrader and NetTradeX platforms (and between languages MQL4 and NTL+), as a rule, you need to make some small changes in converted scripts. The main part of adaptation is carried out by MQL4.ntl library, included in NetTradeX Advisors terminal; however, the developer may need to modify his script for launching. In this article it will be shown how to use functions from that library and additionally what changes should be made.

Basic principles to work with MQL4.ntl library

So, before starting the main work, you should have a fully debugged script in MQL4 language. What steps should be taken in order to turn this code into a working script NTL+?

Step 1 – at first, you should create a new script file in the tree Scripts of the window Navigator in NetTradeX Advisors terminal. The file itself should be in the folder Advisors or Utilities, depending on its purpose. Afterwards, you should copy the whole text of the script into that file in MQL4 language.

Step 2 - connection of MQL4.ntl library. For this, add the line #include "Libraries\MQL4.ntl" at the beginning of your file. It should be mentioned at once that there is no need to compile MQL4.ntl library itself and no executable file is required for library functions to work. That library is not intended for independent launch and is used for auxiliary purposes.

Step 3 – an attempt to compile the generated script. For that in the code editor click on Compile button or press F7. Most likely, the compiler will display a list of errors and warnings that we will eliminate step by step. Right now two key moments interest us: whether the compiler has detected the library and whether all special functions are in our script.

If the compiler will not be able to detect the file of the library, the message "Failed to open script file" will be displayed. In this case make sure that MQL4.ntl in the path determined in the directives #include, and its right name is specified.

There are three special functions in MQL4 language that have predefined names: init(), start(), deinit(). For launching in NetTradeX Advisors terminal all these functions should be determined. However, in several scripts one of the functions or both of them, init() and deinit(), may be missing. In such case the compiler will inform you "No matching signatures to 'init()'" or "No matching signatures to 'deinit()'". In that case you should add init() and deinit() functions with the only operator return 0;

int init()
{
	return 0;
}
int deinit()
{
	return 0;
}

The first stage can be considered as successfully performed, if the messages "Failed to open script file" and "No matching signatures to 'init()'" / "No matching signatures to 'deinit()'" are missing. Now, we may pass to elimination of local problems.

Common messages of compiler, causes and ways of their elimination

In this section we would describe the common messages of compiler, generated in the process of script adaptation, and practical decisions will be given for eliminating incompatibility in the code.

No matching signatures to Print

This kind of error is caused by the fact that in NTL+ the implementation of functions with variable number of properties is not allowed. In this case it will be needed to change the function in a way so that the number of properties in the call exactly corresponds with the number of parameters in its definition. The function Print() should have only one input parameter. In this way instead of Print (param 1, param 2, param 3) а concatenation should be produced - Print(param 1+ param 2+ param 3).

Unexpected token 'unrecognized token'

One of the reasons for this message to come is the attempt to connect the files of libraries of MQL4 language through the directives #include. NTL+ language does not operate with such libraries, that is why the usage of these files is impossible and those lines should be deleted from the program.

'True'/'False' is not declared

Names of logical variables in NTL+ start with small letters, that is why just replace "True" with "true" and "False" with "false".

No conversion from '_bars&' to 'int' available

The variable Bars in MQL4 is intended for determining the quantity of bars in the current chart. In NTL+ language there exists a homonymous object Bars, that is why in the library MQL4.ntl the variable "bars" (with small letter b) is added, returning the quantity of bars for the current chart. It is what should be used in your script instead of Bars.

Must return a value

This message is displayed when the operator “return” is called without return value. At the same time, the function, where this operator is used, is declared with a different from void return value. While displaying this message, you will need either to correct the function itself or specify the value for return.

Use of Magic number

Use of Magic numbers is not supported in the current version of NTL+ language. For all open positions the zero value of magic numbers is returned. In script in MQL4 language it is recommended to pay special attention to the use of Magic numbers in conditional operators. Often, it is enough to just delete or comment out the function OrderMagicNumber(), if you do not need to identify positions, produced by that advisor.

Usе of static variables

In NTL+ the keyword “static” is not used. If required to save the value of variables between launching of functions, such variables should be made global (without keyword static), placing them out of function. If desired, you can add a modificator extern, in case these properties are supposed to be changed by the user during launching or working of the script.

Specifying lot size

In the current version lot size of any instrument is 100 000 units, that is why if you use the instrument with different lot size, specify separately corresponding variable and assign necessary value of lot size to it, if it is different from 100 000.

Various kind of work with DLL files

Working with DLL files is performed differently in NetTradeX Advisors and MetaTrader4 terminals. In MQL4 full description of function from DLL module is necessary, and in NTL+ such description is not needed. Instead of indicating

#import "name of file or module"
    Description of function1;
    Description of function2;
    Description of functionN;
#import

You should simply create dll object random_identifier("name_of_file _or_module "); and call the function you need by
identifier.Cal ("name_of_function", parameters_of_functions_ separated by_commas);
or
identifier. CallProc("name_of_function", parameters_of _function _separated_by_commas);

Checking keywords of the language

In MQL4 and NTL+ there are differences in keywords. Advisors in MQL4 language can use names of variables or functions, not available in NTL+ language and vice versa. The compiler can, for example, display a message Expected '(' for a line in which the use of brackets is not expected. One of possible reasons is coincidence of variable name with one of the keywords. In case of such coincidence, it is necessary to replace the variable name with another one in all locations in program code. The key combination CTRL+H in editor serves for quick call of Replace window

Float value truncated in implicit convertion to integer

This warning displays while trying to assign "float" or "double" value to an "int" variable. Correction of this incompatibility is not required for launching the script but it is desirable to do so. Conversion from "double" to "int" and from "float" to "int" must be performed explicitly. For example, for the variable d of the type "double" it will have the following form int(d).

No automatic conversion from bool to int and vice versa

Automatic conversion of int i; bool b = true; i=b; is impossible in NTL+. In that case the message “Can't implicitly convert from 'bool' to 'int'” displays. That is why if you need such kind of conversion you can use the following construction:

int Run()
{
	// conversion from bool to int;
	bool a=false;
	int b = a?1:0;
	
	// conversion from int to bool
	int c=1;
	bool d = c==0?false:true;
}
Can't implicitly convert from 'datetime' to 'int'

In NTL+ it is needed to perform conversion from "datetime" objects to an "int". variable. It can be performed in the following manner int i; datetime d; i=int(d);

Color constants

In MQL4 a number of constants can be used for working with object colors of graphic primitives. Such kind of constants can be substituted for any of 16 base colors, for example, by specifying White or Black. The only exception is the use of color in graphical indicators. If a color which is not recognized by NTL+ is used, it is needed to specify the color by RGB components. For example, for the color Tomato the specification will be like this: color Tomato = 0xFF6347

Working with data array

In MQL4 and NTL+ working with data arrays is performed differently. In NTL+ the declaration like type name[] is used only for indicator arrays. For saving other data all arrays are declared in the form array "type" name; or array "type" name (size) . So, instead of string symb[3] = {"EURUSD", "GBPUSD", "AUDCAD"}; it should be used array "string" symb= {"EURUSD", "GBPUSD", "AUDCAD"};

Unsupported functions

Severael functions are not supported in NTL+. Those functions should be deleted or the logic of script work should be changed in a way as to use NTL+ constructions. In case of using such functions, the following message will be displayed in the journal 'The function is not supported' or 'No matching signatures to function_name'.

List of some unsupported functions:

  • SendMail()
  • group of functions onArray
  • functions FileOpenHistory, FileIsLineEnding
  • group of functions "objects" and object properties
  • for the following modes the function MarketInfo returns zero value:
    • MODE_SWAPLONG
    • MODE_SWAPSHORT
    • MODE_STARTING
    • MODE_EXPIRATION
    • MODE_MINLOT
    • MODE_LOTSTEP
    • MODE_SWAPTYPE
    • MODE_PROFITCALCMODE
    • MODE_MARGINCALCMODE
    • MODE_MARGININIT
    • MODE_MARGINHEDGED
    • MODE_FREEZELEVEL
  • operator goto
  • function to calculate the custom indicator iCustom
  • group of functions for working with windows (Window functions), MessageBox
  • TerminalCompany(), TerminalName(), TerminalPath()
  • #property parameters

Summary

In this article we have introduced typical difficulties, encountered in converting scripts from MetaTrader on NetTradeX. This process is considerably simplified by MQL4.ntl library, provided together with the terminal. The advantage of this library is a fully open code that the developer can change or add at his discretion. In our turn, we are not resting on our laurels and will add new functions and update existing ones in the library to facilitate the conversion process.