NeedForTrade Documentation

Function Creation Tutorial

There is a detailed description of creation Summation function.

At first:

  1. Use the File menu.
  2. Select New.

  3. Select Function.

Now you can see Code Editor. It's empty.

           

Click the right mouse button anywhere in the Code Editor window. See also Working with Code Editor.

           

In the shortcut menu select Properties and enter function name in the field Name at the Analysis Technique tab. 

           

Enter the name: "Summation". After filling name field this function name will appear in the end of the list of functions at Browser. See also Working with Browser. Default function Type is DoubleFunction. Summation is Double function so keep this field without changes. We want to write this function with CSharp so keep field Language without changes too.

           

Click the right mouse button anywhere in the Code Editor window again. Now in the shortcut menu select Parameters. Enter input parameters for this Function. This Function calculates summary of Length last values, stored in Values parameter.

           

For adding parameters click right mouse button in the Parameters box and in the shortcut menu select Add Parameter and special form will appear.

           

In this form enter Parameter name, Parameter type, Parameter default value, Parameter description and if necessary mark that parameter is Reference. Then click Save if you want to save this parameter or Discard if you don't.

           

For this function at first enter Parameter name ("Values") and select Parameter type ("DoubleSeries") and then click Save.

           

Then again click right mouse button in the Parameters box and in the shortcut menu select Add Parameter. Now enter Parameter name ("Length") and select Parameter type ("Integer") and click Save.

           

So we felt Parameters box:

           

For this simple function we don't need to use References and Variable Store.

Now enter the code of Summation function into the Code Editor window.

           

At first we need to define the variables and initialize its. Declare sum variable to store resulting summary and set it's default value to zero.

double sum = 0;

To calculate summary of all passed values we need to use loop.

  1. Set integer valiable i to zero: int i = 0;
  2. Set condition when to stop the loop: i < Length;
  3. Set what to do with i after each loop iteration: i++;
  4. Specify the action we need to perform in the loop (in this case we want to add i-th value to the currently counted summary): sum = sum + Value[i].

for ( int i = 0; i < Length; i++ ) sum = sum + Values[i];

Then we move to assigning calculated summary, stored in sum variable to Value variable (the actual value of the function).

Value = sum;

After all listed actions click the right mouse button anywhere in the Code Editor window and select Build Analysis Technique. If there are no errors in the Function it will appear in the list of functions at Browser with the green tick. Otherwise Task List will appear. For example if you forgot semicolon it will display in Task List with indication of concrete line and file name with error.

           

When you will find the error and correct it click the right mouse button anywhere in the Code Editor window and select Build Analysis Technique again. If there are no errors in the Function now Task List will be empty and function name will appear in the list of functions at Browser with the green tick.