Click here to Login




More about QuantShare Programming Language

Updated on 2020-06-02





QS language is a very simple programming language used in QuantShare to plot lines, create indicators, composite, trading systems, watchlists, scan stocks...

Previously, we created a blog post that introduces QS language. We strongly suggest you read that post before continuing here.
QuantShare Programming Language Tutorial

Besides the popular and less popular indicators, there are a lot of functions that can be used in QS language to plot and detect your own pattern, formula, indicators...
Many of the most basic functions were introduced in the blog post referenced in the link above.


Introducing the logical operators (And/Or)

Let us begin by one example:
a = close > 10.5 AND volume > 1000;

In the above example, the "And" operator was used (you can also use && instead). The formula assigns a value of "1" to each bar of the "a" array/vector if the close is higher than 10.5 AND the volume is higher than 1000;

b = close > 10.5 OR volume > 1000;

The above formula assigns a value of "1" to each bar of the "a" array/vector if the close is higher than 10.5 OR the volume higher than 1000.
You can use || instead of OR.

If the conditions are not met then "a" would get a value of "0" on the corresponding bar.

You can combine AND and OR operators. Make sure to use parentheses to make the code clean.

Example:
c = (close > 10.5 AND volume > 1000) OR (close > 10.5 AND volume < 1000);

Here is how the values of the a, b and c variables will look like given a sample close and volume data.




Referencing another time-series

When analyzing a particular formula, whether it is for charting, backtesting or screening, that formula is always applied for each symbol individually.

When the formula finds the variable "close", the engine will use the close price of the currently analyzed security.

The "GetSeries" function allows you to reference an external security time-series.

closeSPY = getseries("spy", close);

This will get the close series of the "SPY" ETF and associate it with the "closeSPY" variable.

Now, let us analyze the following formula:

closeSPY = getseries("spy", close);
a = close / closeSPY;
filter = sma(a, 10);


If you are running this formula using the screener tool and you are analyzing say two symbols (IWM and QQQ) then screener will run that formula on these two symbols.

The first run will calculate the ratio of the IWM close series to the SPY close series and then return the 10-bar moving average of that ratio.
The second run will calculate the ratio of the QQQ close series to the SPY close series and then return the 10-bar moving average of that ratio.

Note how the SPY series is fixed here since we explicitly referenced the ticker symbol "SPY" in the "GetSeries" function.


Indicators Crossover

Often you need to detect when a time-series or an indicator crosses above or below another time-series, indicator or an horizontal line.

This can be easily achieved using the "cross" formula. Below are three examples:

// Returns 1 for each trading bar where the close price crosses above 20. The close price must be lower than 20 in the previous bar and higher than 20 in the current bar
a = cross(close, 20);

// Returns 1 for each trading bar where the close price crosses above its 20-bar simple moving average
a = cross(close, sma(20));

// Returns 1 for each trading bar where the close price crosses below its 20-bar simple moving average (The opposite of the previous line)
// This is equivalent to 20-bar simple moving average crossing above the close price
a = cross(sma(20), close);


Tips

In the QuantShare formula editor, there is a very important shortcut that allows you to display the list of available functions depending on the cursor location (start of the line, after "=" operator, inside a function parameter...). That shortcut is CONTROL+SPACE.

When typing a function and after you type the first parenthesis (Example: a = rsi( ), QuantShare will display a tooltip that shows the number of parameters that the function accepts and a description of each parameter. You can also click on that tooltip to display other variations (if exists). This is in case the function accepts different numbers of parameters.

As an example, the "RSI" function has two variations. One that accepts two parameters:
a = rsi(close, 14); // 14-bar RSI of the close time-series

And another one that accept just one parameter:
a = rsi(14); // Same as above. In this case, the close time-series will be used by default












no comments (Log in)

QuantShare Blog
QuantShare
Search Posts




QuantShare
Recent Posts

Create Graphs using the Grid Tool
Posted 1241 days ago

Profile Graphs
Posted 1346 days ago

QuantShare
Previous Posts

Lock, Link and Undock your Charts
Posted 2156 days ago

How to Use the Percentage Scale
Posted 2705 days ago


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.