comparison blocks

Creating consecutive blocks in a Strategy Quant X

In StrategyQuant X 131, we have added two new comparison blocks. In this article we will discuss them in more detail. Comparison blocks are snippets that we can use in the Algo wizard or  Builder and are used to be able to compare two values. ( Left and Right )

Basically, Greater Count / Lower Count compares how many bars the condition is met.

  • Greater Count checks the condition that X is greater than or equal to Y, for the specified number of bars.
  • Lower Count checks the condition that X is less than or equal to Y, for the specified number of bars.

Comparison blocks are also used in Builder, where the genetic engine searches for new combinations of blocks to create a profitable algorithmic strategy.

Let’s now show two examples of how to create and test these blocks:


RSI Consecutive Rules

In the first example, we show how to create a custom block – RSI ( 14 ) is greater than a value of 50 X consecutive bars in a row. In the first step, we select the comparison block Is greater for X bars.

We can choose several parameterizable settings for a given block


We can set the Bars  – a number of bars that must meet the condition and the Allow same values option. Allow same values is useful in a situation where there is a condition where the two values are equal. For example, when the RSI has two bars in a row with the same value.

After we have selected a particular comparison block, SQX offers us the actual setting of the block. We set the left indicator and the right indicator.

In our case, we will compare the RSI ( 14 ) and the value 50.

It is advisable to parameterize the given custom block as well. We choose the number of bars during which the given condition is valid, the RSI period, and the value above which the RSI must be for X bars.

It is a good practice to create an opposite rule, in our case we create a mirror condition that is lower for X bars, modifying slightly in the Block parameters only the variable RSI value, which we change to the interval 20-50.


Consecutive UP/Down Bars

Let us now show an example of creating consecutive Up/down bars. Define the UP bar when the closing price is greater than the opening price and vice versa.

Similar to the above examples, use is Greater Count with condition Close > Open.

For the opposite block, we use  Lower Count to create a block whose body contains the following condition Close < Open


Detecting False Breakouts

Another, slightly more complicated way is to use Greater/Lower Count to detect false breakouts. Let’s start with the definition of weekly high breakout.

A weekly high breakout can be simply defined as a condition where the last high is equal to the current weekly high.


At this point, let us consider when a false breakout occurs? It occurs when price generates a new high, but then price stagnates and does not move. This condition can last for several bars. To solve this situation, we can set at this point that such situations are covered only by the parameterization of the Shift parameter.

By adding the Bars Ago parameters, we are able to capture situations where the weekly High Bars Ago bars have been broken in the past.

To be able to detect that the price is below the current weekly high and also as many X Bars Ago to break the weekly breakout, we add the Lower Count comparison block.

A block prepared in this way allows us to filter these situations efficiently. There is a small problem with two identical parameters Bars Ago and Bars Ago Int. Normally they are the same variables, but they must be declared separately. This is so for the correct functionality of the other functions in SQX. Anyway, we have two ways to solve this problem.

  1. We let the SQX engine find a solution itself, but this takes more time during strategy generation
  2. We help SQX by setting parameter sets in the builder configuration


In the image below, we see a custom block HighWeekBreakout with defined parameter sets and an increased weighting of those settings that ensure the builder prioritizes the parameter sets we set.

For the opposite block, we use similar logic with Low, Weekly Low, and Greater Count.


The above procedures can be used in strategy design directly in Algo Wizard or in StrategyQuantX builder. By using custom blocks you can better target the desired trading strategy and reduce degrees of freedom. You need to be creative when creating blocks like this, ideally, you get similar ideas by looking at charts and looking for possible scenarios.



Inline Feedbacks
View all comments

Continue reading