This plug-in lets you create custom function that you can use
in your formulas.
Function are created using Jscript.Net compiler.
Let
us say you created a function which have two numeric parameters and whose name
is 'MyFunction'.
To use this function, open the formula editor (Right click
on a chart, then click on 'Edit formula'), type for example 'a = ', then click
on CTRL+SPACE; in the list box you will find your function 'MyFunction'.
Open the 'Create functions' form by clicking on 'Create
functions' in the 'Tools' menu.
In the 'Create functions' form, click on 'Add', type a name
then save.
Select the function, you have just created, in the
'Functions' panel, then move to the 'Script' panel.
Press on 'CTRL+SPACE' to see the
initialized variables.
The application creates a
variable for each parameter.
'result' is the variable that your function will
returns to the application
'result' is of type 'VectorD' if your function
returns a numeric time-series or 'VectorS' if your function return a string
time-series
Example: to create a function that returns an array
containing the value '2'.
Type this code in your script panel:
for(var i: int =
0;i<result.Length;i++)
{
result.SetValue(i,
2);
}
You can add parameters to your function, by clicking on 'Add
a parameter'.
You can update the parameters name, type, default value and
description.
After adding a parameter, press on CTRL+SPACE to see the new
variable in the list.
Example: to create a function that adds one to the provided
parameter and returns the new array.
var val : double;
for(var i: int =
0;i<result.Length;i++)
{
val = var1.GetValue(i);
result.SetValue(i, val + 1);
}
When done, click on Save.
Clicking on 'Save' button will compile the function and
updates it.
Select a function, click on 'Remove' then confirm.
The 'cFunctions' class contains
the symbol name, close, open, high, low, volume, open interest and date vectors
of the symbol that is used when executing a formula.
This class also
contains three important functions:
CompileFormula:
This function compiles a QuantShare formula and returns a QSFormula class. This
class can be used to extract vectors.
Example: cFunctions.CompileFormula("a
= rsi(14);").GetVectorDouble("a");
GetCustomDatabaseData:
This function loads custom database data for the current symbol or another one
and returns a VectorCustom class.
The vectorCustom class is like the other
vector classes with the difference that it can contain more than one element in
a bar period.
If you execute a function on a daily timeframe and you
reference an intraday database (news for example), then for a specific bar
(date), you may have more than one news
item.
SetForwardAndBackwardBars: This function let you
define how many backward and forward bars your formula use.
Forward and
Backward bars are used to optimize the execution of formulas.
As an example,
the RSI or relative strength index function (rsi(14)), uses 14 backward bars and
0 forward bars. Because for each bar, it needs the previous 14 bars to perform
its calculation and it does not require any future bar.