Articles » Use previous bar value

What is the most widely spread misunderstanding in the technical analysis?
Here is the answer to this question.

Building an example strategy

Logic: "The trend is my friend!" Trusting this postulate, follow the market using the 1H EURUSD chart for an intraday trading. The simplest way to measure the price tendency is to use the Momentum indicator. It shows the average speed of the price change. When the price rises, the Momentum rises too and when the price falls, the Momentum falls too. More rapid changes in the market lead to more extreme Momentum levels.
Let's see if we can predict the market using its speed as a guide.

  • Market - EURUSD 1H
  • Open a new position at the beginning of every hour.
  • Close the existing position at the end of the hour.
  • Do not add to the initial position

Momentum (Closing Price, Period 10) will be used as a direction criterion

  • Open Long - when the Momentum rises.
  • Open Short - when the Momentum falls.

How can this strategy be tested?

Make an Excel spreadsheet with the data and the formulas.
Write an Expert Advisor for the Meta trader.
In addition, we can test this logic on the market, trading on a demo account.
However, the easiest way is to use Forex Strategy Builder

Doing this test is a very easy task with the help of Forex Strategy Builder.

  1. - Load the history data: EURUSD 1H, Spread 4 pips, Swap 1 pip.
  2. - Set the strategy:
Opening point of the position
Bar Opening
Enter the market at the beginning of the bar
Opening logic condition
Momentum
The Momentum rises
Base price - Close
Period - 10
Use previous bar value - No
Closing point of the position
Bar Closing
Exit the market at the end of the bar

When we are ready, Forex Strategy Builder shows the result.

Momentum

The result looks perfect. Check the chart to make sure that we have not made a mistake.

Momentum

Everything is all right. When the Momentum rises we are long, when the Momentum falls we are short. The position opens at the beginning of the bar and closes at its end.
The account balance chart looks at the same way when the strategy is applied to the EURUSD 1D market. This is additional confirmation of our logic.

Momentum

The thesis is checked. After doing some future tests, we can start trading on the real market.

But is this back test real? Will we really earn several thousand dollars next month using this strategy?

Unfortunately I have to answer - NO, we will not!!!
I am really sorry to say that. The calculations are correct. We can check them using other methods. But the logic is wrong.

Top

The problem

In this example, at the beginning of each bar, the Open Strategy opens a long position if the Momentum value is higher than the previous bar Momentum value, and at the end of the bar the Close Strategy closes the position. Respectively, if the Momentum value is lower than the previous bar value the Open Strategy opens a new short position, which is closed at the end of the bar.

Let's look at the chart again.

Momentum

We all know the calculation formula of the Momentum indicator:

Momentum (PC, n) t = Closing Price (t) - Closing Price (t - n)

Where:

PC - the closing price of the bar
n - the Momentum period
t - the current bar number

Or, to put in a simplier way, the Momentum is equal to the difference between the closing price of the current bar and the closing price of the nth bar back.

After the calculation we plot the Momentum line below the price bar chart. Actually, the Momentum line consists of connected points - one point per bar. Becouse we use Momentum ( Close Prise ) we have to wait untill the closing of the bar in order to get the correct indicator value. The platform then fixes the value exactly below the bar.

In our exemple the Momentum value in point 2 refers to the closing of bar 2 and so on.

Do you see the problem? We open a long position in the beginning of the bar 3 becouse Momentum value 3 is higher than the value 2, but the value 3 will not be correct before the closing of the bar. What we are doing is opening a position at the beginning of the bar relying on an indicator value from the future (the moment of the bar closing).

Top

The real life

Once the problem has been identified, there are two ways to do a relible back test:

  • To use the Open Price as a base price of the indicator
  • To use the previous bar indicator value to determine the signals

In the first case, we have to modify the indicator to:
Momentum (Price Open, 10)
When the indicator is based on the opening price, we can use it with confidenceas as a criterian whether to open a position at the beginning of the bar.

Opening point of the position
Bar Opening
Enter the market at the beginning of the bar
Opening logic condition
Momentum
The Momentum rises
Base price - Open
Period - 10
Use previous bar value - No
Closing point of the position
Bar Closing
Exit the market at the end of the bar

Using Forex Strategy Builder, we can apply the other alternative without changing the initial strategy. It is enough to tick the "Use previous bar value" checkbox when setting the Momentum indicator.

Momentum

Opening point of the position
Bar Opening
Enter the market at the beginning of the bar
Opening logic condition
Momentum
The Momentum rises
Base price - Close
Period - 10
Use previous bar value - Yes
Closing point of the position
Bar Closing
Exit the market at the end of the bar

Momentum

When the checkbox "Use previous bar value" is ticked, FSB calculates the current signal (bar t) using the Momentum (PC, t-1) - Momentum (PC, t-2) criterion.

We can see on the chart that now the position of the selected bar is short.

In the dynamic information panel:
Momentum
Momentum -0.0050
Allow Open Long No
Allow Open Short Yes

In the previous chart the position of this bar was short.

We can use either:

Opening logic condition
Momentum
The Momentum rises
Base price - Open
Period - 10
Use previous bar value - No

Or

Opening logic condition
Momentum
The Momentum rises
Base price - Close
Period - 10
Use previous bar value - Yes

In both cases we get almost the same result, because the Opening Price of the current bar is equal to the Closing Price of the previous bar (If there is no gap between the prices. A gap appears at weekends.).

Using one of these variants, we see the real life result.

Momentum

Top

Conclusion

In our every day technical analysis we use indicators based on the closing price. In the back test all the bars are complete. But in real time trading the trading platform continuously plots the indicator's chart, calculating the indicator using the current price. The current bar is not complete yet. We can not take decision to trade using this indicator value, because the indicator is likely to change at the end of the bar. We have to use indicator values that are defined and unchangeable.

To avoid such vital errors, Forex Strategy Builder provides auto set Use previous bar value option.

We have to use "Use previous bar value" checked when we open a position at price different from Bar Opening or Day Opening, and the indicator is based on a price different from the Opening Price.

To emphasize it once again:

Using Indicator (Closing Price, ...) to decide whether to open a position at the beginning of the bar, we have to tick Use previous bar value.

The other option is to use Indicator (Opening Price, ...)

Горе