Indicators are functions written in the QuantShare vector-based language, which is a very simple programming language you can use to plot indicators, create trading rules and more indicators. You can also create advanced indicators using the .Net programming language. More information on this in Custom Indicators lessons. We will now explain how the vector-based language of QuantShare works: To start, right click on a chart then click on "Edit formula". The form that is visible now allow you to enter a formula for the selected chart. QuantShare vector-based language A vector-based language deals with vectors instead of single numeric or text variables. There are 6 ready to use variables: close, open, high, low, volume and openint. The "close" variable, for example, do not contain a single value. It contains a series of values where each value corresponds to the close price of a specific bar/date. Let us say we are using Google quotes and we have 5 bars/dates in the historical database: 10-11-2010 - Close Price: 400.1 - Open Price: 400.4 10-12-2010 - Close Price: 400.5 - Open Price: 400.4 10-13-2010 - Close Price: 401.2 - Open Price: 401.1 10-14-2010 - Close Price: 400.3 - Open Price: 399.9 10-12-2010 - Close Price: 399.8 - Open Price: 399.8 In this case, the "close" variable is equal to: [400.1 | 400.5 | 401.2 | 400.3 | 399.8] and the "open" variable is equal to: [400.4 | 400.4 | 401.1 | 399.9 | 399.8] Here are some very simple operations: Assign (=) Example: a = close; Variable "a" will be equal to [400.1 | 400.5 | 401.2 | 400.3 | 399.8]. Sum (+) Example: a = close + open; When we perform a mathematical operation on two vectors, the operation is performed on each bar. For the first bar, we will add close (400.1) to open (400.4). Variable "a" will be equal to [800.5 | 800.9 | 802.3 | 800.2 | 799.6]. Higher than (>) Example: a = close > open; This is an example of a trading rule that returns TRUE or 1 when the close price is higher than the open price on a certain bar. Otherwise the rule returns FALSE or 0. Variable "a" will be equal to [0 | 1 | 1 | 1 | 0] Lower than or equal (<=) Example: a = close <= open; Variable "a" will be equal to [1 | 0 | 0 | 0 | 1] Note that each operation must ends with ";". This tells the compiler that our operation/instruction is completed. Functions There are two types of functions. Those that return a vector and those that perform an action. The first type of functions usually use other vectors to perform calculations and then return a result or another vector. The second type of functions are used to perform actions, such as displaying an indicator, updating the chart scale... When you click on CONTROL + SPACE, a list of all available functions is displayed. To display the list of functions/indicators that returns a vector, type a variable then the assign operator (example: "a="), then click on CONTROL + SPACE. Let us start with a very popular function "ref" that gets the value of a past bar for each bar (Reference past bars). Example: a = ref(close, 1); A function/indicator starts by a keyword ("ref" in this case) and then contains a opening and closing parentheses. Inside these parentheses you can add one or more parameters depending on the formula. The "ref" function accepts two parameters, the first one is the vector to use to get the past bars and the second is the number of lookback or past bars. After you type "(", a tooltip automatically appears displaying a description of the function and the parameters that this function accepts. Here is how the variable "a" will look like after executing the "ref" function: [NAN | 400.1 | 400.5 | 401.2 | 400.3] "NAN" refers to "Not a Number". This is because at bar 0, the function "ref" looks for the previous bar and cannot found one. At bar number 1, the "ref" function gets the previous bar value, which is the value at bar number 0. Debug Variables To display the debug form, right click on the formula editor. The debug form displays the number of variables, the active symbol and whether there are errors in the formula or not. Click on the "Debug Mode" tab to display the content of the variables. You will see the bar number and the corresponding variable value for each bar. To display the open, high, low, volume and openint variables, right click on the grid header and check these variables. More info can be found here: QuantShare Programming Language
|
![]() |