- ago
Just installed build 10 today. Now I have noticed the following irregularities:

In a strategy, If I change the time interval from 1/1/2011-12/31/2100 to 1/1/2016-12/31/2100 then some sell signals are suddenly executed differently. The sell rule is pretty simple:

CODE:
if (sverbStochK[idx] == sverbStochK.GetHighest(idx, 115))





Capital and margin is high enough and in both time intervalls, the sverbStochK has exactly the same value for a new 115 days high.

Before I go through the code with the debugger I wanted to ask if there is any idea why, at shorter time interval, buy signals are executes properly but sell signals not?
0
710
Solved
6 Replies

Reply

Bookmark

Sort
- ago
#1
A WriteToDebugLog was already sufficient to detect the difference. It is a tiny little difference at the 14th decimal place!

1
Cone8
 ( 24.80% )
- ago
#2
Testing precise equality for floating point numbers can be tricky, although you'd generally expect that the comparison you made would work.

There are few ways you can tackle that equality issue, but maybe this one will be the easiest in this case...

CODE:
if (idx == (int)sverbStochK.GetHighestBar(idx, 115))


0
Best Answer
- ago
#3
Cone,

There was a function in Community Components to address this very problem (http://www2.wealth-lab.com/WL5Wiki/AlmostEquals.ashx). Might this be ported over to WL7?

Vince
0
- ago
#4
Yes, it has been ported since Build 1.
CODE:
//to compare two double values for approximate equality within e.g. one tick value of an instrument public static bool AlmostEquals(this double double1, double double2, double precision = 0.0001)
0
- ago
#5
Thanks for the tip. Seems to be undocumented but will try to use the AlmostEquals extension method in that case.

Nevertheless it's strange that in the shorter period, the float at the backmost position has a slightly different value than in a longer period...
0
Cone8
 ( 24.80% )
- ago
#6
Double precision is precise to only 15 digits.. and you're showing a difference in the 16th digit.

This kind of thing can be expected from time to time. I've seen differences in calculations at this precision just by calculating the same thing in different ways. It happens and is expected with floating point numbers.
1

Reply

Bookmark

Sort