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
- 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
Read the following blog posts for more information on the "ApplyRule" function:
How to turn any ordinary trading strategy into a very profitable one
How to choose which technical indicators to use in your trading system
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
More information can be found here:
How to create and backtest thousands of trading rules in less than 10 minutes
10 masks to create thousands of trading rules
1- Moving Average
The formula to create a 10-bar simple moving average is:
"close" variable (which refers to the security close price) can be replaced by any time-series or indicator.
mask > sma(mask, 10)
mask < sma(mask, 10)
2- Two Moving Averages
This mask uses two moving averages instead of one.
sma(mask, 20) > sma(mask, 10)
sma(mask, 20) < sma(mask, 10)
You can create several variations by optimizing the moving average parameters.
- Type the following mask: sma(mask, a) > sma(mask, b)
- Click on "Create"
- Select the mask rule
- Type the "min", "max" and "step" values for each variable ("a" and "b")
"a" varies from 10 to 20 with a step of 10
"b" varies from 30 to 40 with a step of 10
3- Rate of Return
The Rate of return is calculated using the "perf" function.
perf(mask, 10) > 50
perf(mask, 10) < -50
The above rule compares the 10-bar rate of return of an indicator with the 50 and -50 levels.
4- Increase, Decrease
To detect an increase in a time-series or indicator value, you must compare the current value with the previous one using the "ref" function.
The "ref" function references past values of a variable.
mask > ref(mask, 1)
mask < ref(mask, 1)
5- Percent Rank
The percent rank function calculates the percentage of observations or values, within a lookback period, that are below the current value of a given function.
This trading indicator can be downloaded here: Percentile - Percent Rank of a Trading Indicator.
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).
percentrank(mask, 30) >= 90
percentrank(mask, 30) <= 10
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.
percentrank(stddev(mask, 30), 30) >= 90
percentrank(stddev(mask, 30), 30) <= 10
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).
This mask simply compares the value of a variable with a threshold. It is the simplest mask rule you can create.
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 == hhv(mask, 20)
mask == llv(mask, 20)
This mask signals crossovers between two time-series. The "cross" function can be used to detect a crossover.
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.
LinearReg_Angle(mask, 20) > 50
LinearReg_Angle(mask, 20) < -50
Create even more rules for your trading system
Beside the "mask" variable that will be replaced each time by the variable specified in "Time Series" panel of the "Mass Rules" control, you can also use the "mask1" variable.
By combining "mask" and "mask1", you can use two different indicators or time-series in the same rule.
mask > mask1
Instead of creating three trading rules, this will generate six rules, which are:
sma(10) > sma(20)
sma(10) > sma(30)
sma(20) > sma(10)
sma(20) > sma(30)
sma(30) > sma(10)
sma(30) > sma(20)
By adding 100 time-series, you can create 9900 trading rules by simply using the above mask formula.