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 Adviser 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.
Lets make this test with the help of Forex Strategy Builder.
(For the purpose of this tutorial uncheck the
menu "Strategy" -> "Auto use of 'Use previous bar value'" check box.)
- - Load the history data: EURUSD 1H, Spread 4 pips, Swap 1 pip.
- - Set the strategy:
| Base price | - Close |
| Period | - 10 |
| Use previous bar value | - No |
When we are ready, Forex Strategy Builder shows the result.
The result looks perfect. Check the chart to make sure that we have not made a mistake.
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.
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.
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.
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 simpler 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. Because we use Momentum ( Close Prise ) we have to wait until 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 example 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 because 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).
The real life
Once the problem has been identified, there are two ways to do a reliable 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 confidences
as a criterion whether to open a position at the beginning of the bar.
| Base price | - Open |
| Period | - 10 |
| Use previous bar value | - No |
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.
| Base price | - Close |
| Period | - 10 |
| Use previous bar value | - Yes |
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:
| Base price | - Open |
| Period | - 10 |
| Use previous bar value | - No |
Or
| 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.
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. (It is switched on by default.)
The other option is to use Indicator (Opening Price, ...)
forexsb.com
or leave a message into the forum.