Click here to Login




Custom functions


Custom functions

1. Custom functions

 

1.1. Introduction

 

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'.

 

1.2. Create a new function

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.

1.3. Update a function

Clicking on 'Save' button will compile the function and updates it.

1.4. Remove a function

Select a function, click on 'Remove' then confirm.

1.5. Functions

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.

 




Manual

 

Back Parent

 

Download Manual in CHM or PDF format







QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.