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 CarlTrading, 03-31-2026, 09:41 PM
|
1 response
72 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
39 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
63 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
63 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
53 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment