Quantreex Documentation

Lookback function

##Definition

Lookback on logics are used to determine whether a condition has occurred any time during 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) or to check for a precondition that occurred some point in time (i.e. some time between now and the last n bars).

In this example we check for a cross over between two Simple Moving Averages at the current bar. At the same time we would like to check whether an RSI has crossed a certain level at some point during the last n bars. Using a lookback in the RSI logic we could determine whether this condition occurred within the last 20 bars (the shaded region).

Rule:

  • SMA 5 cross above SMA 20
  • RSI cross above level 30 value between now and the last 20 bars (lookback value).

Legend:

  • SMA 5 Orange Line
  • SMA 20 Green Line
  • RSI 20 Blue line

Image 0 Source: Dukascopy

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

Image 0

Create a lookback 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) at least once during the last 10 bars.

Image 0

To create the looback condition in the designer the following steps must be followed:

Image 0