# forex software

Create and Test Forex Strategies

forex software

fsb:building_ma_strategy

# Building a MA Strategy Tutorial

In this step-by-step tutorial we will cover:

1. The meaning of the “Use previous bar value” parameter;
2. The strategy generator and how it can be used to improve a strategy.

## Moving Average Key Points

As you probably know, the Simple Moving Average (MA or SMA) indicator shows the average value of the price during a period. The main two parameters of MA are “Base Price” and “Period”. The “Base Price” parameter shows what is the exact price which will be used in the calculation. The “Period” shows how many bars will be calculated.

`MA(Close, n)(t) = (Close(t) + Close(t - 1) + … + Close(t – n)) / n`

Where:
Close(t) – closing price of bar “t”
n – period of MA

The Moving Average indicator is plotted as a line directly in the price chart. That is a bit confusing. Actually, MA has discrete values - one value per bar.

In order to calculate the MA for bar “t” we have to know the base price for that bar. If the base price is “Close”, we will know what that price is at the moment bar “t” closes (not earlier).

It's a big mistake to use MA(Close) value for the current bar in live Technical Analysis. Normally, trading platforms display MA for the last (current) bar. They calculate it using the current bar close price. But that bar is not closed yet. The current close price will probably change till the end of the period, which will change the MA value for that period. So, the logic of the strategy could be satisfied in the middle of the bar. However, fixing the MA value can make the logic unfulfilled.

There are two solutions of this problem:

1. To use the previous bar value of MA(Close) for the current bar Technical Analysis;
2. To use MA(Open). In this case we know the exact value of MA at the beginning of the bar.

Fortunately, Forex Strategy Builder protects you from making such mistakes.

We make use of the parameter “Use previous bar value” of the technical indicators which Forex Strategy Builder sets automatically to the correct value.

Let's see how it works in the following example.

## Moving Average Breakout Strategy

This is a simple MA breakout strategy. We will use the assertion that the Moving Average is an equilibrium of the market. Below it the market tends to fall, and respectively, above it the market tends to rise.

### Long Position Rules

1. The current bar opens below the MA(Close, 21) value;
2. The price breaks out above MA and continues to rise;
3. Open long position 15 pips above MA;
4. Exit – not specified.

### Short Position Rules

1. The current bar opens above the MA(Close, 21) value;
2. The price breaks out below MA and continues to fall;
3. Open short position 15 pips below MA;
4. Exit – not specified.

## How to Build and Test

We will set the entry rules in Forex Strategy Builder and use the automatic strategy “Generator” to set up the exit logic.

1. We set the entry point in the “Opening Point of the Position” slot. In our case, the entry point is 15 pips above (for the longs) and 15 pips below (for the short positions) a Simple Moving Average ( Close, 21 ). To do this we will use the “Steady Bands” indicator. It is made up of two bands around a central Moving Average. Each band is situated at a predetermined number of pips away from the central MA. Since we use “Close” base price, Forex Strategy Builder will set the “Use previous bar value” parameter automatically to “Yes”.

2. To catch the price breakthrough from below the MA to above it we will use the entry filter Moving Average - “The bar opens below the MA value”. These two indicators guarantee that the market will rise from below MA to 15 pips above it in order to enter long.

3. We will use the strategy “Generator” to improve the strategy. For that purpose open the Generator. The slots we have just set are in the left-hand side of the window. If we start the Generator now, it will delete our strategy and will try to generate a completely new one. As we want to protect our entry logic, we will lock the slots by clicking on them. A padlock image appears at the top-left corner of the slot panel. Now we can start the Generator. It will not change the locked slots. The Generator will try to set additional entry and exit rules in order to find a profitable strategy.

4. Now we start the Generator by pressing the “Generate” button. If we are lucky, we will have a profitable strategy in a minute:

5. If the pattern of the generated strategy's balance line looks well, we press “Accept” to confirm the strategy and to close the Generator.

6. Forex Strategy Builder generates a strategy review and a description automatically. To see it press the “Overview” button. It is in the middle of the tool bar, above the indicators slots. The strategy overview explains the entry / exit points and the other logic conditions. It also contains all the statistical information of the backtest.

We can do the same exercise using MA based on the bar opening price. Forex Strategy Builder will leave the “Use previous bar value” parameter unchecked in this case. 