Click here to Login




The custom trading indicators tool explained

Updated on 2011-12-28





QuantShare has an extensive list of trading indicators you can use in your charts, trading systems, neural network models or composites. Although the list contains more than 200 indicators, some users may not find the indicator they are looking for or they may want to create their own functions. For those users, we have developed a tool that allows you to create custom functions/indicators in CSharp or JScript.Net and reference these functions in QuantShare language.

Even if CSharp and JScript.Net may appear to be complicated at the start, theses languages are very powerful and with some practice, you should be able to create easily some custom indicators.


Custom Trading Indicators

- To open the custom trading indicators control, select "Tools" then "Create Functions".
- To add a new indicator, click on "Add", type the function name then click on "Save Item".

Note that you are not allowed to use a reserved keyword as function name. Reserved keywords are function names already implemented in QuantShare language. For example, the followings are reserved keywords: ref, sma, rsi, plot...


Formula

In the "Script" panel, you should type your CSharp (C#) code then click on "Save". Once it is saved, you can reference the function in your chart or trading system.

Example:

Let us say you have just created a custom indicator that is similar to RSI (Relative Strength Index). The indicator name is "MyIndicator".

- Right click on a chart then click on "Create new pane"
- Right click on the new pane then select "Edit Formula"
- Type the following lines to display your indicator on the chart:

a = MyIndicator();
plot(a, "");



How it works

When you execute the above formula, QuantShare will search for the "MyIndicator" function in its internal list of indicators/functions. In case it did not find the function, it will search for custom indicators that you have created or downloaded from the sharing server (List).

Once the function is found, the application fills the "cFunctions" class with data (dates, close, open, high, low... series) and executes the CSharp code. The time frame of these series depends on the time frame used by the calling QuantShare formula.

If you are backtesting stocks with a one-minute interval then the "cFunctions.Close" variable will get one-minute interval data. If you are displaying a daily chart then "cFunctions.Close" will contain daily bars.

The CSharp formula is executed once; it is not executed for each trading bar.

After the CSharp formula is executed, QuantShare will take the content of the variable "result" and return it. In other words, the technical indicator "MyIndicator" returns the series associated with the variable "result".

Here is an example of an implementation of the "MyIndicator" indicator. You should type the following lines in the script input box in "Create Functions" form:

VectorD a = TA.Rsi(14);
result = a;


Point 1: "TA" class contains a list of build-in indicators. Type "." character after "TA" to display the list of available technical analysis indicators.

Point 2: "TA.RSI" returns the relative strength index of the analyzed security.

Point 3: All numeric series are of type "VectorD". In CSharp, to associate a value to a variable you should type: [Variable Type] [Variable Name] = ...

Point 4: The variable that this function will return is "result". This variable gets the content of the variable “a” that is equal to the 14-bar relative strength index.

Point 5: The equivalent QuantShare formula to the above CSharp code is:

a = rsi(14);


Function Parameters

It is possible to add one or several parameters to a custom indicator.

Here is how to make the necessary modifications to allow the calculation of RSI with a different period:

- In "Create Functions" control, select your indicator ("MyIndicator")
- In the bottom of the control, click on "Add a parameter"
- Set the variable name to "period" and keep the type to "Number"
- Click on the script control and use the CONTROL+SPACE shortcut to display the list of available variables. Within this list, you will see the "period" variable we have just added.
- Replace the previous code by the following one:

VectorD a = TA.Rsi(period);
result = a;


- In QuantShare language, you can now change your previous formula to account for the newly added parameter:

a = MyIndicator(2); // Calculates the 2-bar RSI
plot(a, "");



In next posts, I will show you how to implement your own technical analysis indicators using several examples.











2 comments (Log in)

QuantShare Blog
QuantShare
Search Posts




QuantShare
Recent Posts

Create Graphs using the Grid Tool
Posted 1449 days ago

Profile Graphs
Posted 1554 days ago

QuantShare
Previous Posts

More Posts

Back







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.