Prototyped Function (MQL Function)
- Selecting the configuration(+) button of an MQL function Element will display the MQL Function Configuration Window.
- There is a single tab on the MQL Function Configuration Window, the MQL Tab.
- The MQL Tab is used to edit native MQL code.
- VTS automatically determines if an MQL Element is a Code Snippet or a Prototyped Function when the MQLElement is saved.
- If the first uncommented line of code contains a correctly formed function prototype, the Element will be saved as a Prototyped Function. Otherwise the Element will be saved as a Code Snippet.
- A correctly formed function prototype follows this format:
return type Function_Name ( data type Parameter_name1, data type Parameter_name2, ... )
There can be zero to any number of parameters.
- This is an example of a function without any parameters:
double GetSpread()
{
return( MathAbs(Bid-Ask) );
}
- This is an example of a function with two parameters:
int GetSum( int a, int b)
{
return( a + b );
}
- NOTE: The behaviour of the configuration (+) button differs if the MQL Element is a prototyped function:
- The first time the configuration(+) button is selected, the editor is in edit mode allowing the MQL code to be edited.
- After the MQL Element is saved, subsequent selections of the configuration(+) button will display the platform function configuration window.
- This allows the parameters of an MQL function to be set the same way parameters are set for a platform function.
- The MQL code is shown as read-only text.
- The Original MQL function is saved by name in the Functions Toolbox in the menu: Advanced -> MQL
- The name of the function is the name taken from the prototype, not the name of the MQL Element.
- To edit the original MQL function, drag and drop the function from the MQL menu and use the configuration(+) button to open and edit the MQL code.
Summary
When you create an MQL function, the name of the function within the MQL code will be the name of the function on the Advanced->MQL menu.
The name of the MQL Element in which the MQL code was entered can be named any available name, for example MyMql.
The function on the Advanced->MQL menu holds the MQL source code and can be edited at any time.
The function MyMql represents a call to the function on the Advanced->MQL menu. It does not contain the MQL code, only a call to the underlying function with the parameters set specifically.
- NOTE: Knowledge of MQL is required to create MQL Elements. Syntax errors can be injected into the trading system if care is not taking when using native MQL to create MQL Elements.