#twitter-follow { border: 0;position: fixed; top: 240px; left:0;} #live-support { border: 0;position: fixed; top: 370px; left:0;} #knowledge-base { border: 0;position: fixed; top: 170px; left:0;}

### A vector-based language

Updated on 2009-08-31

A vector-based programming language is different from a standard language in that it deals with arrays or vectors instead of base elements. If for example you create a new variable and associate it with the number "2", you will in fact, create an array and associate the number "2" to each element of that array.
But how is the array size defined?
The array size is defined by the asset close price. This close price is a time-series that starts at a certain date and ends at another date. The total number of bars of this time-series represents the array size. In the last example, if our stock has 500 bars, then the variable we previously created will be associated with an array of 500 elements.

Mathematical operations on vectors are easy to understand. The only thing you need to know is that these operations are executed for each element of the arrays passed as parameters.
Let's have an example. Suppose a security close price is as follows:

And suppose we want to add this security close vector to a vector initialized with the value "2".

The result will be:

All the available indicators in the QuantShare software perform calculation on vectors. Moving average, Average price, commodity channel index, relative strength index (RSI), moving average convergence/divergence (MACD) ....., all of them, get vectors as parameters and return a vector as a function return object.

One of the most important and useful QuantShare function is (ref). This function let you refer to a past or a future bar of a particular vector. Internally it just shifts the array to the right or to left depending on whether you want to refer to past or future bars. If you want to set the current vector value to the vector value three bars ago, then the (ref) function will shift the vector to the right by 3 bars.
Example:
Close price:

Ref(close, 3): (the close price three bars ago)

Ref(close, -3): (the close price three bars in the future)

In the "Formula Editor" (Right click on a chart and select "Edit formula"), you can display at any moment the content of a particular vector. You just need to right click on the formula editor control and then select "Debug Mode". You will be presented with a grid, whose rows represent the bar index and whose columns display all the vectors initialized by the formula.

A vector can be one of the following two types: Numeric or Textual. String (Text) vectors can be created as easily as numeric vectors, you just need one instruction: (a = "this is a text message";). As with numeric vectors, the string vector will store the text message in every element of the array. The text message can be set to vary from a bar to another; example: (a = "close price:".close;). NB: The point is used as an addition operator for string vectors.
String vectors are mainly used to reference and manipulate news and text data stored inside custom databases.