10 masks to create thousands of rules to use into your trading system

Updated on 2012-05-23

The "Mass Rules" feature of the rules analyzer is a tool that lets you create thousands of trading rules very quickly. You simply define masks and add time-series, such as indicators, fundamental ratios, composites, and the mass rules generates a lot of trading rules.

Once you have your list of rules, you can do the followings:

1/ Rules Analyzer
- Backtest these rules using the rules analyzer
- Choose the best ones to include in your trading system

2/ Simulator
- Use the "ApplyRule" function to create a huge optimizable trading system
- Use the simulator optimizer or the genetic algorithm or PBIL optimizer to create a profitable trading strategy

3/ Market Timing
- Use the "ApplyRule" function to create a market indicator (using the "comp" function)
- Backtest the trading system based on an index (S&P 500 for example)
- Analyze the market timing strategy

4/ Genetic Algorithm Optimizer
- Use the GA or PBIL optimizer to find the best combination of rules (AI -> Optimizer)

How to use "Mass Rules" feature

- In QuantShare main menu, select "Analysis" then "Rules Manager"
- Create a new list of rules by clicking on "Create"
- Type a name then click on "OK"
- Select the new list then select "Mass rules" from the top menu
- In the "Time Series" panel, add indicators using the "Add" button or click on "Add from TimeSeries Builder" to quickly add several indicators
- In "Masks" panel, type a mask formula then click on "Create"
- When done, click on "Create Rules" to add all generated rules in your list of rules

It returns a value between 0 and 100, where a value of 100 means that the current bar value is higher than all the previous values (Period defined in the second parameter of the "PercentRank" function).

Mask Formulas:percentrank(mask, 30) >= 90
percentrank(mask, 30) <= 10

6- Volatility

There are several ways to calculate the volatility of an asset (stock, currency pair, ETF, futures...). These same methods can be applied to calculate the volatility of an indicator.

Volatility measure the dispersion of a data points, it does not measure the direction of price or indicator changes.
A widely used method to measure the volatility of a time-series is the standard deviation.

The standard deviation of a variable is calculated using the "stddev" function.

Because the standard deviation values are likely to be very different from one indicator to another, I have used the "percentrank" function. See above for more information on this function (Percent Rank).

7- Threshold

This mask simply compares the value of a variable with a threshold. It is the simplest mask rule you can create.

Mask Formulas:mask > 70
mask < 30

This resulting rule will mainly work for indicators or time-series that oscillate between 0 and 100.

8- Highest and Lowest

"HHv" and "LLv" functions return the highest and lowest values of a security price or indicator over a given period.

The next function returns 1 if the relative strength index makes a new 20-bar high

a = rsi(14) == hhv(rsi(14), 20);

Mask Formulas:mask == hhv(mask, 20)
mask == llv(mask, 20)

9- Crossover

This mask signals crossovers between two time-series. The "cross" function can be used to detect a crossover.

Mask Formulas:cross(mask, sma(mask, 10))

The above rule returns a signal when an indicator crosses above its 10-bar moving average

10- Linear Regression

In the financial markets, the linear regression is an approach used to forecast future prices by estimating the trend given a previous set of data.
The "LinearReg_Angle" function returns, for each trading bar, the angle of the line that represents the trend. The higher the angle, the bullish is the trend and the lower the angle, the bearish is the trend.

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.