Quantreex Documentation

Bars in a row function


Bars in a row on logics are used to determine whether a condition has always occurred within the last few bars. This typically used with a combination of logics that do not necessarily occur at the same time (i.e on the same bar) and/or to validate that a certain logic was reinforced throughout the last few bars.

In this example we check for a cross over between two Exponential Moving Averages (EMA) at the current bar. At the same time we would like to check the price has been trending up by checking that the EMA 100 has been increasing for the last 5 bars using the bars in a row function. By checking the EMA with its previous bar (i.e. using the index function) and setting a bars in a row value of 5 this condition is automatically checked for the last n (i.e. 5) bars.


  • SMA 5 cross above SMA 20
  • EMA 100 greater than the previous bar EMA 100, during the last 5 bars (using the bar in a row function)
  • SMA 20 greater than EMA 100


  • SMA 5 Blue Line
  • SMA 20 Green Line
  • EMA 100 in Orange

Image 0 Source: Dukascopy

The equivalent logic using the Strategy Designer can be defined as follows:

Image 0

Create a Bar in a row in the Strategy Designer

In the following example two logics are created one for verifying moving average cross overs and checking whether the moving average has been above its previous value (using an index of 1 - see index function for more details) for the last 10 bars.

Image 0

To create the bar in a row condition in the designer the following steps must be followed and the logic needs to be saved:

Image 0