## Back Tester Rules

The rules page allows you to create an indicator formula for each of the four trade actions. The four trade actions are:

- Enter Long - Enter a long trade if the indicator issues a buy signal. A long position will only be entered if the trading status is out or short.
- Exit Long - Exit a long trade the indicator issues a sell signal.
- Enter Short - Enter a short trade if the indicator issues a sell signal. A short position will only be entered if the trading status is out or long.
- Exit Short - Exit a short trade the indicator issues a buy signal.

Here the above shot shows a simple moving average crossover formula for each trading rule.

Here is a breakdown of the enter long formula:

1. We use a REF function to grab an array of close bars.
2. We create a 20 period SMA with step 1 as the input.
3. We use a COMP function to generate a TRUE signal if step1(the close) is > step2 (the SMA). Note we check this step to plot. qtstalker needs to know which step will be used to generate signals.

The exit long formula breakdown is like this:

1. We use a REF function to grab an array of close bars.
2. We create a 40 period SMA with step 1 as the input.
3. We use a COMP function to generate a TRUE signal if step1(the close) is < step2 (the SMA). Note we check this step to plot. qtstalker needs to know which step will be used to generate signals.

**CRITICAL**
In order for any formula to work, you must have a COMP step somewhere in the formula to generate the boolean array that will generate the buy/sell signals. A TRUE value will issue the signal that applies to the particular rule. Note also that the only step that is checked in the plot column must be the COMP step. The checked step is the one that tells qtstalker which step contains the logic for the trading rule signals. If a non COMP step or multiple steps are checked, the results will be unreliable.