# Long Rule: Conditions

### Long Condition 1

Because we only want to trade when we can confirm that the Fast MA finally closes above the Slow MA, we need to ensure that a new candle just opens and see if in the candle that just closes the Fast MA is above the Slow MA. Having that in mind, we need a way to add a condition for our Long rule that will determine whether a new candle just opens.

In Trading SM a condition is a comparison between two values. If you click the New Condition button you can see in the upper board how the Conditions Creator looks like.

Two squares separated by a choice box appear inside the upper board. If you click the choice box you can see all the possible comparisons. Basically, you set a value in the left square that you want to compare with the value you set in the right square. In order to introduce the values in the corresponding squares, we need to first create those values.

In Trading SM one way to create values is by making questions. The answer to a question is a value. We can find all the available questions on the left side panels: Indicators, Timeseries and Misc.

As you can see, we can make a lot of questions in Trading SM. We will use the answers to these questions to make trade decisions. For the purpose of this condition we will use the Is New Bar question. The answer to this question can be true or false and it will be true every time a new bar opens.

The condition we are pursuing looks like this: true equal Is New Bar

In the right square of the condition we will need to set the answer to the question Is New Bar. And in the left square the true value. In the choice box we will select the equal comparison. Meaning that if the answer to Is New Bar is equal to true, then true is equal to true and so, the condition is met. Otherwise, if the answer to the question is false, then false is not equal to true and so, the condition is not met. The condition would be met only once per bar (at the open).

In order to set the true value in the left square we need to create a parameter that will hold this value. So, the first thing we are going to do is to create a parameter named True that will hold the value true. That can be done in the Parameters Creator:

Don’t forget to add the parameter by clicking the Add button as we do in the above video. As we create parameters, they are added to the list of parameters that can be seen at the Parameters pane on the right.

After that, we will come back to the Conditions Creator and drag and drop the parameter just created to the left square:

We select the equal comparison and on the right square we will drag and drop the Is New Bar question. The Is New Bar question is available at Misc panel:

Don’t forget to add the condition.

The buttons available at the top of Trading SM are creator buttons. Every time you click one of those buttons, the corresponding creator shows up in the upper board. Each creator can use values or questions from different side panels. In order to help you, Trading SM will print in blue the borders of the panels from where you can use values and questions at each creator.

We have already created the first condition. In the next chapter we keep creating the remaining conditions.

### Long Condition 2

We do not want to open a new Buy order when there is one already open. For that purpose we need a condition that will check whether there are more buy orders open in the terminal.

There is also a question available in Trading SM that will answer us how many orders of a specific type (like buy or sell) are open at any time in the terminal. So, the comparison of this condition would be something like this: 0 equal Total Orders Open (type Buy)

The first thing we need to do is create a parameter that will hold the value 0:

Once this parameter is created we can create our condition. The question Total Orders Open answers us know how many orders are open by type. Let’s create the condition:

### Long Condition 3

In the previous conditions, we have been dropping questions directly to any square of the Conditions Creator but we can also use a variable to hold the answer of some question and drop the variable instead. This approach helps us in avoiding to introduce all the settings every time we need to make the same question. We will create this condition using this approach.

This condition compares the Fast MA value in bar 2 with the Slow MA value in bar 2. From Trading SM, we can get values from all the indicators available in Metatrader. In this case we need the values of a Moving Average indicator. For this condition, we need the value of a 25 period Moving Average in bar 2 and the value of a 100 period Moving Average in bar 2. Because these values are also required in Short Condition 3, we can create variables and later, use the same variables in Short Condition 3. Let’s see how we can create a variable that will hold the value of a Moving Average.

In Trading SM, we have available several questions in the Indicators panel. In this case we use the Moving Average question.

Note that all the fields in the Moving Average question match the fields you see when you attach the Moving Average indicator in Metatrader. This applies for each indicator question. The only new field to any indicator is the Bar field because you need to specify from which bar number you want the value of the indicator.

Now that we have the corresponding variables, we can create the Long Condition 3.

### Long Condition 4

This condition requires some operation. We need to perform the following operation: Fast MA in 1 – Slow MA in 1. Later, we need to compare the result with a parameter (5 pips). So, the first thing we need to do is to create two variables: Fast MA 1 and Slow MA 1. Second, we create an operation to perform: Fast MA 1 – Slow MA 1. Third, we create the 5 pips parameter. Finally, we create the condition.

Let’s create Fast MA 1 and Slow MA 1.

Let’s create the operation.

Let’s create the distance parameter.

Let’s create the condition.