Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Range bar issue with ninjascript
Collapse
X
-
That's whacked 89.54=89.54
but not in IF statement?
double d1;
double d2;
double d3;
double d4;
d1 = Close[1] + 4 *TickSize;
d2 = 4*TickSize;
d3 = Close[1];
d4 = d2-d3;
Print ("ToTime(Time[0])=" + ToTime(Time[0]) +" Close[0]=" + Close[0] + " Close[1]=" + Close[1] + " TickSize=" + TickSize + " (4*TickSize)=" + (4*TickSize) +
" Close[1]+4*TickSize=" + (Close[1]-4*TickSize) + " Close[1]-4*TickSize=" + (Close[1]-4*TickSize) + " d1=" + d1);
Print ("d2=" + d2 + " d3=" + d3 + " d4=" + d4 );
if (d4==Close[0])
{
Print ( "D4=Close[0]");
}
else
Print ( "D4!=Close[0]");
ToTime(Time[0])=110603 Close[0]=89.54 Close[1]=89.58 TickSize=0.01 (4*TickSize)=0.04 Close[1]+4*TickSize=89.54 Close[1]-4*TickSize=89.54 d1=89.62
d2=0.04 d3=89.58 d4=-89.54
D4!=Close[0]
Originally posted by gain247 View PostHi sledge, I've looked at print statements on these situations and they don't show any partial ticks, just same exact tick values as the corresponding bars on the screen. That's why I've been so puzzled as the bars on the screen AND print statements don't sometimes match with the strategy logic execution (or lack of) in certain bar sequences. For that purpose I did a very simple example strategy below to pinpoint some bar close price value issues, and it seems that sometimes (quite frequently) the real Close of the bar is not an exact tick value, but maybe tiny fraction higher/lower. On the screen the tick values are automatically by exact tick increment, but it seems in the world of programming tick is not an exact tick.
Comment
-
You cannot compare double values for equality and expect to get the precision you're expecting all the time. You either have to take the absolute value of their difference and compare that to be less than a threshold level (e.g., diff < 0.0000001f) or convert the doubles to the decimal type in C# and then do the equality comparison on the decimal variables.
NEVER compare two double values like this:
if (val1 == val2)...
The diff method is clumsy looking code but it's faster than working with decimal values as they are not native floating point types.Last edited by hygm; 07-29-2012, 08:13 AM.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by strategist007, Today, 07:51 PM
|
0 responses
2 views
0 likes
|
Last Post Today, 07:51 PM | ||
Started by StockTrader88, 03-06-2021, 08:58 AM
|
44 responses
3,967 views
3 likes
|
Last Post
by jhudas88
Today, 06:59 PM
|
||
Started by rbeckmann05, Today, 06:48 PM
|
0 responses
4 views
0 likes
|
Last Post
by rbeckmann05
Today, 06:48 PM
|
||
Started by rhyminkevin, Today, 04:58 PM
|
4 responses
55 views
0 likes
|
Last Post
by dp8282
Today, 06:13 PM
|
||
Started by iceman2018, Today, 05:07 PM
|
0 responses
6 views
0 likes
|
Last Post
by iceman2018
Today, 05:07 PM
|
Comment