Topic: Forex backtesting and value comparison

Dear users,

I received an interesting letter from Orlando Cornudella yesterday.

Buenos dias, first of all to thank you for the wonderful tool that they share with us.
Secondly say that my English is painful and I used an automatic translator.
Thirdly send a strategy developed FSB 2.6.01, the results are quite good, however checking periods of time have confirmed that there are "bar" where the logic does not work or that I think my.
For example:
07/03 on the day between 9:15 and 11:15 should enter into short, however, the strategy has not worked, or so I think to me, what is more secure you made some incorrect definition, how can it help?.
There are other times that supposedly should have entered the strategy, but I give that example. Thanks

I am Spanish

The strategy:

Forex Strategy Builder v2.6.0.1
Strategy name: Momo5min.
Exported on: 16.3.2008 ?. 10:47:29

Market: EURUSD 5 Minutes
Spread: 4 pips
Swap Long: 1 pip
Swap Short: -1 pips
Slippage: 0 pips

Intrabar scanning: Not accomplished
Interpolation method: Pessimistic scenario
Ambiguous bars: 0
Tested bars: 19959
Balance: 764 pips
Minimum account: 0 pips
Maximum drawdown: 209 pips
Time in position: 61 %

A same direction signal - Does nothing
An opposite direction signal - Does nothing
Permanent Stop Loss - -23

[Opening point of the position]
Bar Opening
     Enter the market at the beginning of the bar
     Base price  -  Open

[Opening logic condition]
MACD Histogram
     The MACD histogram crosses the Level line upward
     Smoothing method  -  Exponential
     Base price  -  Close
     Signal line method  -  Exponential
     Slow MA period  -  29
     Fast MA period  -  10
     Signal line period  -  8
     Level  -  0,0001
     Use previous bar value  -  Yes

[Opening logic condition]
Moving Average
     The bar opens above the MA value
     Smoothing method  -  Exponential
     Base price  -  Close
     Period  -  24
     Shift  -  0
     Use previous bar value  -  Yes

[Closing point of the position]
Take Profit
     Exit at the Take Profit level
     Take Profit  -  55

Thanks Orlando for the good question. I hope the answer will clear some of the FSB backtester logic.

I suppose, the misunderstanding comes from the "The MACD histogram crosses the Level line upward" logic implementation.
In that example the Level = 0.0001. (Dashed line on the chart.)

At first sight the logic - "? crosses the Level upward" should be implemented by the formula:

Long logic condition: Value (t-1) < Level and Value (t) > Level
Short logic condition: Value (t-1) > Level and Value (t) < Level

Looking the above chart, the signal should be at bar b: a < 0.0001 and b > 0.0001
Off course we have "Use previous bar value" that moves the signal one bar ahead to bar c.

But, Forex Strategy Builder does not use that logic.

The problem comes from the manner the computers represent the float numbers.
If you define Value = 0.0001, at the next moment the computer can show that Value = 0.0001000003 or Value = 0.000099999998.
So, the logic Value > 0.0001 simply does not work well.

The values should be compared like this:

Value > 0.0001 + delta
where delta is the acceptable error.

FSB uses delta = Point / 2
where Point = 0.0001 for EURUSD and 0.01 for USDJPY

That means:

Long logic condition: Value (t-1) < Level - delta and Value (t) > Level + delta
Short logic condition: Value (t-1) > Level + delta and Value (t) < Level - delta

But the programming can be insidious some time. (That is I like it)
Let see the following values for three consecutive bars:
    Value1 = 0.0000
    Value2 = 0.0001
    Value3 = 0.0002

Ops, the above logic does not work. We have crossing of the Level 0.0001 here, but there is no any signal.

In that situation neither:
Value1 < Level and Value2 > Level
Value1 < Level - delta and Value2 > Level + delta

The problem is that Value2 = Level

And even worse, we can meet:
    Value1 = 0.0000
    Value3 = 0.0001
    Value4 = 0.0001
    Value5 = 0.0001
    Value6 = 0.0002
For that reason Forex Strategy Builder uses a little bit complicated approach:

Case IndicatorLogic.The_indicator_crosses_the_level_line_upward:
  float fMicron = Point / 2;
  for (int iBar = iFirstBar; iBar < Bars; iBar++)
     int iBaseBar = iBar - iPrvs - 1;
     while (Math.Abs(afIndValue[iBaseBar] - fLevelLong) < fMicron && iBaseBar > iFirstBar)

      indCompLong.Value [iBar] = (afIndValue[iBaseBar]     < fLevelLong  - fMicron &&
                                  afIndValue[iBar - iPrvs] > fLevelLong  + fMicron) ? 1 : 0;

      indCompShort.Value[iBar] = (afIndValue[iBaseBar]     > fLevelShort + fMicron &&
                                  afIndValue[iBar - iPrvs] < fLevelShort - fMicron) ? 1 : 0;

(The source is published in the Library section.)

It ignores the bars which are in the range of the Level line (+- fMicron)

For that reason, looking at the chart, the bars that crosses the Level is the bar d (d > 0.00015) and FSB raises the signal at bar e, because of the "Use previous bar value" logic.

Re: Forex backtesting and value comparison

Thank you, I have taken note of your explanations